def test_top_level_purl_conversion(pkg_type, purl_method, method_args, default_request, has_subpath): pkg = Package(type=pkg_type) if purl_method is None: msg = f"{pkg_type!r} is not a valid top level package" with pytest.raises(ContentManifestError, match=msg): pkg.to_top_level_purl(default_request) else: with mock.patch.object(pkg, purl_method) as mock_purl_method: mock_purl_method.return_value = "pkg:generic/foo" purl = pkg.to_top_level_purl( default_request, subpath="some/path" if has_subpath else None) assert mock_purl_method.called_once_with(*method_args) if has_subpath and pkg_type != "git-submodule": assert purl == "pkg:generic/foo#some/path" else: assert purl == "pkg:generic/foo"
def test_vcs_purl_conversion(repo_url, expected_purl): pkg = Package(name="foo") assert pkg.to_vcs_purl(repo_url, GIT_REF) == expected_purl