Skip to content

Commit 419a239

Browse files
committed
test: test URL labels
1 parent 1a31e7e commit 419a239

File tree

1 file changed

+36
-15
lines changed

1 file changed

+36
-15
lines changed

tests/test_metadata_config.py

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
from hatch_nodejs_version.metadata_source import NodeJSMetadataHook
77

8-
98
TRIVIAL_PYPROJECT_CONTENTS = """
109
[build-backend]
1110
requires = ["hatchling", "hatch-vcs"]
@@ -16,7 +15,7 @@
1615
[tool.hatch.metadata.hooks.nodejs]
1716
"""
1817

19-
DEMO_PACKAGE_CONTENTS = """
18+
TRIVIAL_PACKAGE_CONTENTS = """
2019
{
2120
"name": "my-app",
2221
"version": "1.0.0",
@@ -50,12 +49,12 @@
5049
}
5150
"""
5251

53-
EXPECTED_METADATA = {
52+
TRIVIAL_EXPECTED_METADATA = {
5453
"license": "MIT",
5554
"urls": {
56-
"bug tracker": "https://www.send-help.com",
57-
"repository": "https://github.com/some/code.git",
58-
"homepage": "https://where-the-heart-is.com",
55+
"Bug Tracker": "https://www.send-help.com",
56+
"Repository": "https://github.com/some/code.git",
57+
"Homepage": "https://where-the-heart-is.com",
5958
},
6059
"authors": [
6160
{
@@ -79,14 +78,14 @@ def test_all_metadata(self, project, alt_package_json):
7978
# Create a simple project
8079
package_json = "package.json" if alt_package_json is None else alt_package_json
8180
(project / "pyproject.toml").write_text(TRIVIAL_PYPROJECT_CONTENTS)
82-
(project / package_json).write_text(DEMO_PACKAGE_CONTENTS)
81+
(project / package_json).write_text(TRIVIAL_PACKAGE_CONTENTS)
8382

8483
config = {} if alt_package_json is None else {"path": alt_package_json}
8584
metadata = {}
8685
metadata_source = NodeJSMetadataHook(project, config=config)
8786
metadata_source.update(metadata)
8887

89-
assert metadata == EXPECTED_METADATA
88+
assert metadata == TRIVIAL_EXPECTED_METADATA
9089

9190
@pytest.mark.parametrize(
9291
"pyproject_field",
@@ -103,7 +102,7 @@ def test_all_metadata(self, project, alt_package_json):
103102
def test_subset_metadata(self, project, pyproject_field):
104103
# Create a simple project
105104
(project / "pyproject.toml").write_text(TRIVIAL_PYPROJECT_CONTENTS)
106-
(project / "package.json").write_text(DEMO_PACKAGE_CONTENTS)
105+
(project / "package.json").write_text(TRIVIAL_PACKAGE_CONTENTS)
107106

108107
config = {"fields": [pyproject_field]}
109108

@@ -113,26 +112,26 @@ def test_subset_metadata(self, project, pyproject_field):
113112

114113
assert pyproject_field in metadata
115114
assert len(metadata) == len(config["fields"])
116-
assert metadata[pyproject_field] == EXPECTED_METADATA[pyproject_field]
115+
assert metadata[pyproject_field] == TRIVIAL_EXPECTED_METADATA[pyproject_field]
117116

118117
def test_contributors_as_maintainers(self, project):
119118
# Create a simple project
120119
(project / "pyproject.toml").write_text(TRIVIAL_PYPROJECT_CONTENTS)
121-
(project / "package.json").write_text(DEMO_PACKAGE_CONTENTS)
120+
(project / "package.json").write_text(TRIVIAL_PACKAGE_CONTENTS)
122121

123122
metadata = {}
124123
metadata_source = NodeJSMetadataHook(
125124
project, config={"contributors-as-maintainers": True}
126125
)
127126
metadata_source.update(metadata)
128127

129-
assert metadata["authors"] == EXPECTED_METADATA["authors"]
130-
assert metadata["maintainers"] == EXPECTED_METADATA["maintainers"]
128+
assert metadata["authors"] == TRIVIAL_EXPECTED_METADATA["authors"]
129+
assert metadata["maintainers"] == TRIVIAL_EXPECTED_METADATA["maintainers"]
131130

132131
def test_contributors_as_authors(self, project):
133132
# Create a simple project
134133
(project / "pyproject.toml").write_text(TRIVIAL_PYPROJECT_CONTENTS)
135-
(project / "package.json").write_text(DEMO_PACKAGE_CONTENTS)
134+
(project / "package.json").write_text(TRIVIAL_PACKAGE_CONTENTS)
136135

137136
metadata = {}
138137
metadata_source = NodeJSMetadataHook(
@@ -142,5 +141,27 @@ def test_contributors_as_authors(self, project):
142141

143142
assert (
144143
metadata["authors"]
145-
== EXPECTED_METADATA["authors"] + EXPECTED_METADATA["maintainers"]
144+
== TRIVIAL_EXPECTED_METADATA["authors"]
145+
+ TRIVIAL_EXPECTED_METADATA["maintainers"]
146+
)
147+
148+
def test_labels(self, project):
149+
# Create a simple project
150+
(project / "pyproject.toml").write_text(TRIVIAL_PYPROJECT_CONTENTS)
151+
(project / "package.json").write_text(TRIVIAL_PACKAGE_CONTENTS)
152+
153+
metadata = {}
154+
metadata_source = NodeJSMetadataHook(
155+
project,
156+
config={
157+
"repository-label": "the-repository",
158+
"bugs-label": "the-bug-tracker",
159+
"homepage-label": "the-homepage",
160+
},
146161
)
162+
metadata_source.update(metadata)
163+
164+
urls = metadata["urls"]
165+
assert urls["the-repository"] == "https://github.com/some/code.git"
166+
assert urls["the-bug-tracker"] == "https://www.send-help.com"
167+
assert urls["the-homepage"] == "https://where-the-heart-is.com"

0 commit comments

Comments
 (0)