Skip to content

Commit

Permalink
fix(python): version updater updates patch versions >= 10 (#1708)
Browse files Browse the repository at this point in the history
* test: failing test for replacing multicharacter patch version

* fix(python): version updater updates patch versions >= 10
  • Loading branch information
chingor13 authored Oct 18, 2022
1 parent 0366cf1 commit 80b3d4f
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 1 deletion.
19 changes: 19 additions & 0 deletions __snapshots__/python-file-with-version.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,25 @@ __version__ = '0.6.0'
`

exports['version.py updateContent updates long patch versions in version.py 1'] = `
# Copyright 2020 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
__version__ = '0.5.11'
`

exports['version.py updateContent updates version in version.py 1'] = `
# Copyright 2020 Google LLC
#
Expand Down
2 changes: 1 addition & 1 deletion src/updaters/python/python-file-with-version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export class PythonFileWithVersion extends DefaultUpdater {
*/
updateContent(content: string): string {
return content.replace(
/(__version__ ?= ?["'])[0-9]+\.[0-9]+\.[0-9](?:-\w+)?(["'])/,
/(__version__ ?= ?["'])[0-9]+\.[0-9]+\.[0-9]+(?:-\w+)?(["'])/,
`$1${this.version}$2`
);
}
Expand Down
15 changes: 15 additions & 0 deletions test/updaters/fixtures/version-with-long-patch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright 2020 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

__version__ = '0.5.10'
11 changes: 11 additions & 0 deletions test/updaters/python-file-with-version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,17 @@ describe('version.py', () => {
const newContent = version.updateContent(oldContent);
snapshot(newContent);
});
it('updates long patch versions in version.py', async () => {
const oldContent = readFileSync(
resolve(fixturesPath, './version-with-long-patch.py'),
'utf8'
).replace(/\r\n/g, '\n');
const version = new PythonFileWithVersion({
version: Version.parse('0.5.11'),
});
const newContent = version.updateContent(oldContent);
snapshot(newContent);
});
});
});

Expand Down

0 comments on commit 80b3d4f

Please sign in to comment.