Skip to content

Commit 259e0cb

Browse files
committed
fix regex bug
1 parent b941b28 commit 259e0cb

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

synapseclient/models/schema_organization.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1161,7 +1161,9 @@ def _check_semantic_version(self, version: str) -> None:
11611161
Raises:
11621162
ValueError: If the string is not a correct semantic version
11631163
"""
1164-
if not re.match("^(\d+)\.(\d+)\.([1-9]\d*)$", version):
1164+
if version == "0.0.0":
1165+
raise ValueError("Schema version must start at '0.0.1' or higher")
1166+
if not re.match("^(\d+)\.(\d+)\.(\d+)$", version):
11651167
raise ValueError(
11661168
(
11671169
"Schema version must be a semantic version with no letters "

tests/unit/synapseclient/models/synchronous/unit_test_schema_organization.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,25 @@ def test_fill_from_dict(self) -> None:
125125
assert js.created_by == "2"
126126
assert js.uri == "org.name-name"
127127

128+
@pytest.mark.parametrize("version", ["1.0.0", "0.0.1", "0.1.0"])
129+
def test_check_semantic_version(self, version: str) -> None:
130+
"Tests that only correct versions are allowed"
131+
js = JSONSchema()
132+
js._check_semantic_version(version)
133+
134+
def test_check_semantic_version_with_exceptions(self) -> None:
135+
"Tests that only correct versions are allowed"
136+
js = JSONSchema()
137+
with pytest.raises(
138+
ValueError, match="Schema version must start at '0.0.1' or higher"
139+
):
140+
js._check_semantic_version("0.0.0")
141+
with pytest.raises(
142+
ValueError,
143+
match="Schema version must be a semantic version with no letters and a major, minor and patch version",
144+
):
145+
js._check_semantic_version("0.0.1.rc")
146+
128147

129148
class TestCreateSchemaRequest:
130149
@pytest.mark.parametrize(

0 commit comments

Comments
 (0)