Skip to content

Commit

Permalink
Swap the parameter order for from_project_details_html()
Browse files Browse the repository at this point in the history
This allows for a potential future where the name of the project can be inferred.
  • Loading branch information
brettcannon committed Nov 20, 2022
1 parent 8e86d7e commit 5d9dcaa
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
3 changes: 1 addition & 2 deletions mousebender/simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,7 @@ def handle_starttag(
self.archive_links.append(args)


def from_project_details_html(name: str, html: str) -> ProjectDetails_1_0:
"""Parse the HTML of a project details page."""
def from_project_details_html(html: str, name: str) -> ProjectDetails_1_0:
parser = _ArchiveLinkHTMLParser()
parser.feed(html)
files: List[ProjectFileDetails_1_0] = []
Expand Down
22 changes: 11 additions & 11 deletions tests/test_simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def test_full_parse(self, module_name, count, expected_file_details):
importlib_resources.files(simple_data) / f"archive_links.{module_name}.html"
)
html = html_file.read_text(encoding="utf-8")
project_details = simple.from_project_details_html(module_name, html)
project_details = simple.from_project_details_html(html, module_name)
assert len(project_details) == 3
assert project_details["name"] == module_name
assert project_details["meta"] == {"api-version": "1.0"}
Expand All @@ -152,7 +152,7 @@ def test_full_parse(self, module_name, count, expected_file_details):
],
)
def test_filename(self, html, expected_filename):
project_details = simple.from_project_details_html("honey", html)
project_details = simple.from_project_details_html(html, "honey")
assert len(project_details["files"]) == 1
assert project_details["files"][0]["filename"] == expected_filename

Expand All @@ -170,13 +170,13 @@ def test_filename(self, html, expected_filename):
],
)
def test_url(self, html, expected_url):
project_details = simple.from_project_details_html("cash", html)
project_details = simple.from_project_details_html(html, "cash")
assert len(project_details["files"]) == 1
assert project_details["files"][0]["url"] == expected_url

def test_no_href(self):
html = "<a>numpy-1.12.1-cp35-none-win_amd64.whl</a><br/>"
project_details = simple.from_project_details_html("test_no_href", html)
project_details = simple.from_project_details_html(html, "test_no_href")
assert not len(project_details["files"])

@pytest.mark.parametrize(
Expand All @@ -193,7 +193,7 @@ def test_no_href(self):
],
)
def test_requires_python(self, html, expected):
project_details = simple.from_project_details_html("Dave", html)
project_details = simple.from_project_details_html(html, "Dave")
assert len(project_details["files"]) == 1
if expected is None:
assert "requires-python" not in project_details["files"][0]
Expand All @@ -216,7 +216,7 @@ def test_requires_python(self, html, expected):
],
)
def test_hashes(self, html, expected_hashes):
project_details = simple.from_project_details_html("Brett", html)
project_details = simple.from_project_details_html(html, "Brett")
assert len(project_details["files"]) == 1
assert project_details["files"][0]["hashes"] == expected_hashes

Expand All @@ -238,7 +238,7 @@ def test_hashes(self, html, expected_hashes):
],
)
def test_gpg_sig(self, html, expected_gpg_sig):
details = simple.from_project_details_html("test_gpg_sig", html)
details = simple.from_project_details_html(html, "test_gpg_sig")
assert len(details["files"]) == 1
assert details["files"][0].get("gpg-sig") == expected_gpg_sig

Expand Down Expand Up @@ -272,15 +272,15 @@ def test_gpg_sig(self, html, expected_gpg_sig):
],
)
def test_yanked(self, html, expected):
details = simple.from_project_details_html("test_yanked", html)
details = simple.from_project_details_html(html, "test_yanked")
assert len(details["files"]) == 1
assert details["files"][0].get("yanked") == expected


class TestPEP658Metadata:
def test_default(self):
html = '<a href="spam-1.2.3-py3.none.any.whl">spam-1.2.3-py3.none.any.whl</a>'
details = simple.from_project_details_html("test_default", html)
details = simple.from_project_details_html(html, "test_default")
assert len(details["files"]) == 1
# Need to make sure it isn't an empty dict.
assert "dist-info-metadata" not in details["files"][0]
Expand All @@ -290,7 +290,7 @@ def test_default(self):
)
def test_attribute_only(self, attribute):
html = f'<a href="spam-1.2.3-py3.none.any.whl" {attribute} >spam-1.2.3-py3.none.any.whl</a>'
details = simple.from_project_details_html("test_default", html)
details = simple.from_project_details_html(html, "test_default")
assert len(details["files"]) == 1
assert details["files"][0]["dist-info-metadata"] is True

Expand All @@ -303,6 +303,6 @@ def test_attribute_only(self, attribute):
)
def test_hash(self, attribute):
html = f'<a href="spam-1.2.3-py3.none.any.whl" {attribute}>spam-1.2.3-py3.none.any.whl</a>'
details = simple.from_project_details_html("test_default", html)
details = simple.from_project_details_html(html, "test_default")
assert len(details["files"]) == 1
assert details["files"][0]["dist-info-metadata"] == {"sha256": "abcdef"}

0 comments on commit 5d9dcaa

Please sign in to comment.