Skip to content

Commit

Permalink
prevent IndexError if all items are None
Browse files Browse the repository at this point in the history
  • Loading branch information
iamdual committed Aug 21, 2024
1 parent 4665e42 commit f0a50d4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/ua_generator/data/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def format(self, partitions=None, separator='.', trim_zero=False) -> str:
versions = versions[:partitions]
else:
# Stop at None
while versions[-1] is None:
while versions and versions[-1] is None:
versions.pop()

# None to zero
Expand Down
7 changes: 7 additions & 0 deletions tests/test_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ def test_version_7(self):
self.assertEqual(version.format(partitions=2), '1.0')
self.assertEqual(version.to_tuple(), (1, 0, 0, 0))

def test_version_none(self):
version = Version(major=None, minor=None, build=None, patch=None)
self.assertEqual(version.format(), '')
self.assertEqual(version.format(partitions=1), '0')
self.assertEqual(version.format(partitions=2), '0.0')
self.assertEqual(version.to_tuple(), (0, 0, 0, 0))

def test_version_separator(self):
version = Version(major=1, minor=2, build=3, patch=4)
self.assertEqual(version.format(separator='_'), '1_2_3_4')
Expand Down

0 comments on commit f0a50d4

Please sign in to comment.