Skip to content

Commit

Permalink
Add more tests for schemes
Browse files Browse the repository at this point in the history
  • Loading branch information
y0urself committed Mar 14, 2023
1 parent 253bc4f commit a4f1edf
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
2 changes: 2 additions & 0 deletions pontos/version/schemes/_semantic.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
from ..version import Version
from ._scheme import VersioningScheme

# Note: This regex currently support any kind of
# word-number combination for pre releases
_PRE_RELEASE_REGEXP = re.compile(
r"^(?P<name>[a-zA-Z]+)(?P<version>0|[1-9][0-9]*)$"
)
Expand Down
16 changes: 16 additions & 0 deletions tests/version/schemes/test_pep440.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,22 @@ def test_parse_version(self):
for version in versions:
self.assertEqual(Version.from_string(version), Version(version))

def test_parse_version_from_semver(self):
versions = [
"0.0.1",
"1.2.3",
"1.2.3-post1.dev1",
"1.2.3-a1",
"1.2.3-b1",
"1.2.3-rc1",
"1.2.3-a1+dev1",
"1.4.1",
"2.4.1-dev1",
"2.4.1-dev3",
]
for version in versions:
self.assertEqual(Version.from_string(version), Version(version))

def test_parse_error(self):
versions = [
"abc",
Expand Down
13 changes: 12 additions & 1 deletion tests/version/schemes/test_semantic.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
)


class PEP440VersionTestCase(unittest.TestCase):
class SemanticVersionTestCase(unittest.TestCase):
def test_parse_version(self):
versions = [
"0.0.1",
Expand Down Expand Up @@ -63,6 +63,17 @@ def test_parse_error(self):
):
Version.from_string(version)

def test_parse_prerelease_error(self):
versions = [
"1.2.3-pos1t1",
]

for version in versions:
with self.assertRaisesRegex(
VersionError, f"^Invalid prerelease [a-zA-Z0-9]* in {version}"
):
Version.from_string(version)


class SemanticVersionCalculatorTestCase(unittest.TestCase):
def test_next_patch_version(self):
Expand Down

0 comments on commit a4f1edf

Please sign in to comment.