Skip to content

Commit 80b3d4f

Browse files
authored
fix(python): version updater updates patch versions >= 10 (#1708)
* test: failing test for replacing multicharacter patch version * fix(python): version updater updates patch versions >= 10
1 parent 0366cf1 commit 80b3d4f

4 files changed

Lines changed: 46 additions & 1 deletion

File tree

__snapshots__/python-file-with-version.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,25 @@ __version__ = '0.6.0'
88
99
`
1010

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

src/updaters/python/python-file-with-version.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export class PythonFileWithVersion extends DefaultUpdater {
2525
*/
2626
updateContent(content: string): string {
2727
return content.replace(
28-
/(__version__ ?= ?["'])[0-9]+\.[0-9]+\.[0-9](?:-\w+)?(["'])/,
28+
/(__version__ ?= ?["'])[0-9]+\.[0-9]+\.[0-9]+(?:-\w+)?(["'])/,
2929
`$1${this.version}$2`
3030
);
3131
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Copyright 2020 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
__version__ = '0.5.10'

test/updaters/python-file-with-version.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,17 @@ describe('version.py', () => {
3434
const newContent = version.updateContent(oldContent);
3535
snapshot(newContent);
3636
});
37+
it('updates long patch versions in version.py', async () => {
38+
const oldContent = readFileSync(
39+
resolve(fixturesPath, './version-with-long-patch.py'),
40+
'utf8'
41+
).replace(/\r\n/g, '\n');
42+
const version = new PythonFileWithVersion({
43+
version: Version.parse('0.5.11'),
44+
});
45+
const newContent = version.updateContent(oldContent);
46+
snapshot(newContent);
47+
});
3748
});
3849
});
3950

0 commit comments

Comments
 (0)