Skip to content

Commit 84c916a

Browse files
committed
test: validate use of build segments
1 parent aec775f commit 84c916a

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

tests/test_version_config.py

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
# SPDX-FileCopyrightText: 2022-present Angus Hollands <[email protected]>
22
#
33
# SPDX-License-Identifier: MIT
4-
import pytest
54
import json
65

6+
import pytest
7+
78
from hatch_nodejs_version.version_source import NodeJSVersionSource
89

910
GOOD_NODE_PYTHON_VERSIONS = [
@@ -17,19 +18,26 @@
1718
("1.4.5-beta0", "1.4.5beta0"),
1819
("1.4.5-pre9", "1.4.5pre9"),
1920
("1.4.5-preview0", "1.4.5preview0"),
21+
("1.4.5-preview0+build1.0.0", "1.4.5preview0+build1.0.0"),
22+
("1.4.5-preview0+build-1.0.0", "1.4.5preview0+build-1.0.0"),
23+
("1.4.5-preview0+build-1_0.0", "1.4.5preview0+build-1_0.0"),
2024
]
2125

2226
BAD_NODE_VERSIONS = [
2327
"1.4",
2428
"1.4.5a0",
2529
"1.4.5-c0.post1",
2630
"1.4.5-rc0.post1.dev2",
31+
"1.4.5-rc0.post1+-bad",
32+
"1.4.5-rc0.post1+bad_",
2733
]
2834
BAD_PYTHON_VERSIONS = [
2935
"1.4",
3036
"1.4.5ab",
3137
"1.4.5-c0.smoke2",
3238
"1.4.5rc.post1@dev2",
39+
"1.4.5rc0.post1+-bad",
40+
"1.4.5rc0.post1+bad_",
3341
]
3442

3543

@@ -54,7 +62,7 @@ def test_parse_python_incorrect(self, python_version):
5462
"node_version",
5563
BAD_NODE_VERSIONS,
5664
)
57-
def test_parse_python_incorrect(self, node_version):
65+
def test_parse_node_incorrect(self, node_version):
5866
with pytest.raises(ValueError, match=".* did not match regex"):
5967
NodeJSVersionSource.node_version_to_python(node_version)
6068

@@ -79,7 +87,7 @@ def test_version_from_package(
7987
name = "my-app"
8088
dynamic = ["version"]
8189
[tool.hatch.version]
82-
source = "nodejs"
90+
source = "nodejs"
8391
"""
8492
)
8593
package_json = "package.json" if alt_package_json is None else alt_package_json
@@ -94,7 +102,7 @@ def test_version_from_package(
94102
config = {} if alt_package_json is None else {"path": alt_package_json}
95103
version_source = NodeJSVersionSource(project, config=config)
96104
data = version_source.get_version_data()
97-
assert data['version'] == python_version
105+
assert data["version"] == python_version
98106

99107
@pytest.mark.parametrize(
100108
"node_version, python_version",
@@ -117,15 +125,15 @@ def test_version_to_package(
117125
name = "my-app"
118126
dynamic = ["version"]
119127
[tool.hatch.version]
120-
source = "nodejs"
128+
source = "nodejs"
121129
"""
122130
)
123131
(project / package_json).write_text(
124-
f"""
125-
{{
132+
"""
133+
{
126134
"name": "my-app",
127135
"version": "0.0.0"
128-
}}
136+
}
129137
"""
130138
)
131139
config = {} if alt_package_json is None else {"path": alt_package_json}
@@ -134,5 +142,4 @@ def test_version_to_package(
134142
version_source.set_version(python_version, version_data)
135143

136144
written_package = json.loads((project / package_json).read_text())
137-
assert written_package['version'] == node_version
138-
145+
assert written_package["version"] == node_version

0 commit comments

Comments
 (0)