Skip to content

Commit 8a3558f

Browse files
committed
Add new tests for unquoted/quoted names aboutcode-org#143
These new test were missing originally and they excercise all the corner cases of encoding. Reference: aboutcode-org#143 Signed-off-by: Philippe Ombredanne <[email protected]>
1 parent 1298af8 commit 8a3558f

File tree

1 file changed

+154
-0
lines changed

1 file changed

+154
-0
lines changed

tests/test_utils_pypi.py

+154
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
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/nexB/python-inspector for support or download.
9+
# See https://aboutcode.org for more information about nexB OSS projects.
10+
#
11+
12+
from typing import NamedTuple
13+
14+
import pytest
15+
16+
from python_inspector.utils_pypi import Distribution
17+
from python_inspector.utils_pypi import Sdist
18+
from python_inspector.utils_pypi import Wheel
19+
20+
21+
class DistTest(NamedTuple):
22+
filename: str
23+
expected_class: type
24+
expected_name: str
25+
expected_version: str
26+
27+
def check(self, using=Distribution):
28+
dist = using.from_filename(self.filename)
29+
assert dist.name == self.expected_name
30+
assert dist.version == self.expected_version
31+
32+
33+
wheel_tests = [
34+
DistTest(
35+
filename="package.repo/SomeProject-1.2.3-py33-none-any.whl",
36+
expected_class=Wheel,
37+
expected_name="SomeProject",
38+
expected_version="1.2.3",
39+
),
40+
DistTest(
41+
filename="SomeProject-1.2.3+cpu-py33-none-any.whl",
42+
expected_class=Wheel,
43+
expected_name="SomeProject",
44+
expected_version="1.2.3+cpu",
45+
),
46+
DistTest(
47+
filename="/scancode_toolkit_mini-32.0.6-cp311-none-any.whl",
48+
expected_class=Wheel,
49+
expected_name="scancode-toolkit-mini",
50+
expected_version="32.0.6",
51+
),
52+
DistTest(
53+
filename="example/torch-2.0.0+cpu.cxx11.abi-cp310-cp310-linux_x86_64.whl",
54+
expected_class=Wheel,
55+
expected_name="torch",
56+
expected_version="2.0.0+cpu.cxx11.abi",
57+
),
58+
DistTest(
59+
filename="torch-1.10.2+cpu-cp39-cp39-win_amd64.whl",
60+
expected_class=Wheel,
61+
expected_name="torch",
62+
expected_version="1.10.2+cpu",
63+
),
64+
DistTest(
65+
filename="torch-2.0.0+cpu.cxx11.abi-cp310-cp310-linux_x86_64.whl",
66+
expected_class=Wheel,
67+
expected_name="torch",
68+
expected_version="2.0.0+cpu.cxx11.abi",
69+
),
70+
DistTest(
71+
filename="/torch-1.10.2+cpu-cp39-cp39-win_amd64.whl",
72+
expected_class=Wheel,
73+
expected_name="torch",
74+
expected_version="1.10.2+cpu",
75+
),
76+
DistTest(
77+
filename="example/torch-2.0.0%2Bcpu.cxx11.abi-cp310-cp310-linux_x86_64.whl",
78+
expected_class=Wheel,
79+
expected_name="torch",
80+
expected_version="2.0.0+cpu.cxx11.abi",
81+
),
82+
DistTest(
83+
filename="torch-1.10.2%2Bcpu-cp39-cp39-win_amd64.whl",
84+
expected_class=Wheel,
85+
expected_name="torch",
86+
expected_version="1.10.2+cpu",
87+
),
88+
DistTest(
89+
filename="torch-2.0.0%2Bcpu.cxx11.abi-cp310-cp310-linux_x86_64.whl",
90+
expected_class=Wheel,
91+
expected_name="torch",
92+
expected_version="2.0.0+cpu.cxx11.abi",
93+
),
94+
DistTest(
95+
filename="/torch-1.10.2%2Bcpu-cp39-cp39-win_amd64.whl",
96+
expected_class=Wheel,
97+
expected_name="torch",
98+
expected_version="1.10.2+cpu",
99+
),
100+
]
101+
102+
sdist_tests = [
103+
DistTest(
104+
filename="scancode-toolkit-mini-32.0.6.tar.gz",
105+
expected_class=Sdist,
106+
expected_name="scancode-toolkit-mini",
107+
expected_version="32.0.6",
108+
),
109+
DistTest(
110+
filename="/scancode-toolkit-mini-32.0.6.tar.gz",
111+
expected_class=Sdist,
112+
expected_name="scancode-toolkit-mini",
113+
expected_version="32.0.6",
114+
),
115+
DistTest(
116+
filename="foo/bar/scancode-toolkit-mini-32.0.6.tar.gz",
117+
expected_class=Sdist,
118+
expected_name="scancode-toolkit-mini",
119+
expected_version="32.0.6",
120+
),
121+
DistTest(
122+
filename="scancode-toolkit-mini-32.0.6.zip",
123+
expected_class=Sdist,
124+
expected_name="scancode-toolkit-mini",
125+
expected_version="32.0.6",
126+
),
127+
DistTest(
128+
filename="/scancode-toolkit-mini-32.0.6.zip",
129+
expected_class=Sdist,
130+
expected_name="scancode-toolkit-mini",
131+
expected_version="32.0.6",
132+
),
133+
DistTest(
134+
filename="foo/bar/scancode-toolkit-mini-32.0.6.zip",
135+
expected_class=Sdist,
136+
expected_name="scancode-toolkit-mini",
137+
expected_version="32.0.6",
138+
),
139+
]
140+
141+
142+
@pytest.mark.parametrize("dist_test", sdist_tests + wheel_tests)
143+
def test_Distribution_from_filename(dist_test):
144+
dist_test.check()
145+
146+
147+
@pytest.mark.parametrize("dist_test", sdist_tests)
148+
def test_Sdist_from_filename(dist_test):
149+
dist_test.check(using=Sdist)
150+
151+
152+
@pytest.mark.parametrize("dist_test", wheel_tests)
153+
def test_Wheel_from_filename(dist_test):
154+
dist_test.check(using=Wheel)

0 commit comments

Comments
 (0)