Skip to content

Commit e85d615

Browse files
committed
Add unit tests
Signed-off-by: Kai Hodžić <hodzic.e.k@outlook.com>
1 parent 6df7fab commit e85d615

1 file changed

Lines changed: 57 additions & 0 deletions

File tree

tests/test_package_data.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
#
4+
# Copyright (c) nexB Inc. and others. All rights reserved.
5+
# ScanCode is a trademark of nexB Inc.
6+
# SPDX-License-Identifier: Apache-2.0
7+
# See http://www.apache.org/licenses/LICENSE-2.0 for the license text.
8+
# See https://github.com/aboutcode-org/python-inspector for support or download.
9+
# See https://aboutcode.org for more information about nexB OSS projects.
10+
#
11+
12+
from python_inspector.package_data import get_pypi_codeview_url
13+
from python_inspector.package_data import get_sdist_from_urls
14+
15+
16+
def test_get_pypi_codeview_url():
17+
assert (
18+
get_pypi_codeview_url({"Source": "https://github.com/psf/requests"})
19+
== "https://github.com/psf/requests"
20+
)
21+
assert (
22+
get_pypi_codeview_url({"Code": "https://github.com/psf/requests"})
23+
== "https://github.com/psf/requests"
24+
)
25+
assert (
26+
get_pypi_codeview_url({"Source Code": "https://github.com/psf/requests"})
27+
== "https://github.com/psf/requests"
28+
)
29+
assert get_pypi_codeview_url({}) is None
30+
31+
32+
def test_get_sdist_from_urls():
33+
urls = [
34+
{"packagetype": "bdist_wheel", "url": "https://example.com/pkg-1.0.whl"},
35+
{
36+
"packagetype": "sdist",
37+
"url": "https://example.com/pkg-1.0.tar.gz",
38+
"digests": {"sha256": "abc123", "md5": "def456"},
39+
"size": 12345,
40+
"filename": "pkg-1.0.tar.gz",
41+
},
42+
]
43+
result = get_sdist_from_urls(urls)
44+
assert result["url"] == "https://example.com/pkg-1.0.tar.gz"
45+
assert result["sha256"] == "abc123"
46+
assert result["filename"] == "pkg-1.0.tar.gz"
47+
48+
49+
def test_get_sdist_from_urls_returns_none_when_missing():
50+
assert get_sdist_from_urls([]) is None
51+
assert get_sdist_from_urls(None) is None
52+
assert get_sdist_from_urls([{"packagetype": "bdist_wheel"}]) is None
53+
54+
55+
def test_get_sdist_from_urls_md5_digest_fallback():
56+
urls = [{"packagetype": "sdist", "url": "x", "md5_digest": "old", "digests": {}}]
57+
assert get_sdist_from_urls(urls)["md5"] == "old"

0 commit comments

Comments
 (0)