Skip to content

Commit 10167be

Browse files
alf239acabarbaye
andauthored
Avoid KeyError on variable reuse (#64)
Co-authored-by: Adrien CABARBAYE <adrien.cabarbaye@arm.com>
1 parent fc8dce7 commit 10167be

File tree

5 files changed

+57
-1
lines changed

5 files changed

+57
-1
lines changed

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
toml
22
semver~=2.13
3+
six

src/auto_version/replacement_handler.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,6 @@ def __call__(self, match):
3030
# of the line just after the last non-whitespace character
3131
# e.g. blah=\n --> blah=text\n
3232
start = end = len(original.rstrip())
33-
self.missing.remove(key)
33+
if key in self.missing:
34+
self.missing.remove(key)
3435
return "".join([original[:start], str(replacement), original[end:]])
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[AutoVersionConfig]
2+
CONFIG_NAME = 'example'
3+
PRERELEASE_TOKEN = 'dev'
4+
targets = ["example.py", "example2.py"]
5+
6+
[AutoVersionConfig.key_aliases]
7+
VERSION = "VERSION_KEY"
8+
VERSION_AGAIN = "VERSION_KEY"
9+
STRICT_VERSION = "VERSION_KEY_STRICT"
10+
LOCK = "VERSION_LOCK"
11+
RELEASE = "RELEASE_FIELD"
12+
13+
[AutoVersionConfig.trigger_patterns]
14+
# this will trigger on existence of any python file
15+
"*.py" = "minor"

src/auto_version/tests/example2.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
LOCK = False
2+
RELEASE = True
3+
VERSION = "19.99.0"
4+
VERSION_AGAIN = "19.99.0"
5+
STRICT_VERSION = "19.99.0"
6+
UNRELATED_STRING = "apple"

src/auto_version/tests/test_autoversion.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,39 @@ def test_custom_field_set(self):
129129
self.assertEqual(updates["UNRELATED_STRING"], "apple")
130130

131131

132+
class TestMultiFileBumps(unittest.TestCase):
133+
call = functools.partial(main, config_path="double_target.toml")
134+
135+
@classmethod
136+
def setUpClass(cls):
137+
dir = os.path.dirname(__file__)
138+
os.chdir(os.path.abspath(dir))
139+
140+
def tearDown(self):
141+
self.call(set_to="19.99.0")
142+
143+
def test_bump_patch(self):
144+
old, new, updates = self.call(bump="patch", release=True)
145+
self.assertEqual(
146+
updates,
147+
{
148+
"RELEASE": True,
149+
"VERSION": "19.99.1",
150+
"VERSION_AGAIN": "19.99.1",
151+
"STRICT_VERSION": "19.99.1",
152+
},
153+
)
154+
with open("example2.py", "r") as f:
155+
second_file = f.read()
156+
self.assertEqual(second_file, '''LOCK = False
157+
RELEASE = True
158+
VERSION = "19.99.1"
159+
VERSION_AGAIN = "19.99.1"
160+
STRICT_VERSION = "19.99.1"
161+
UNRELATED_STRING = "apple"
162+
''')
163+
164+
132165
class TestUtils(unittest.TestCase):
133166
def test_is_release(self):
134167
self.assertTrue(utils.is_release(semver.parse_version_info("1.2.3")))

0 commit comments

Comments
 (0)