From 80b3d4fce7d494575b4f136e68bad1c508600ea0 Mon Sep 17 00:00:00 2001 From: Jeff Ching Date: Tue, 18 Oct 2022 09:56:34 -0700 Subject: [PATCH] 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 --- __snapshots__/python-file-with-version.js | 19 +++++++++++++++++++ .../python/python-file-with-version.ts | 2 +- .../fixtures/version-with-long-patch.py | 15 +++++++++++++++ test/updaters/python-file-with-version.ts | 11 +++++++++++ 4 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 test/updaters/fixtures/version-with-long-patch.py diff --git a/__snapshots__/python-file-with-version.js b/__snapshots__/python-file-with-version.js index 4744614b8..ead4c8a7e 100644 --- a/__snapshots__/python-file-with-version.js +++ b/__snapshots__/python-file-with-version.js @@ -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 # diff --git a/src/updaters/python/python-file-with-version.ts b/src/updaters/python/python-file-with-version.ts index d4e42f438..46555eb8d 100644 --- a/src/updaters/python/python-file-with-version.ts +++ b/src/updaters/python/python-file-with-version.ts @@ -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` ); } diff --git a/test/updaters/fixtures/version-with-long-patch.py b/test/updaters/fixtures/version-with-long-patch.py new file mode 100644 index 000000000..86dbdd6e6 --- /dev/null +++ b/test/updaters/fixtures/version-with-long-patch.py @@ -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' diff --git a/test/updaters/python-file-with-version.ts b/test/updaters/python-file-with-version.ts index 1ad847ad8..5f07e47f1 100644 --- a/test/updaters/python-file-with-version.ts +++ b/test/updaters/python-file-with-version.ts @@ -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); + }); }); });