forked from aboutcode-org/python-inspector
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_utils_pypi.py
More file actions
176 lines (156 loc) · 5.25 KB
/
test_utils_pypi.py
File metadata and controls
176 lines (156 loc) · 5.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright (c) nexB Inc. and others. All rights reserved.
# ScanCode is a trademark of nexB Inc.
# SPDX-License-Identifier: Apache-2.0
# See http://www.apache.org/licenses/LICENSE-2.0 for the license text.
# See https://github.com/nexB/python-inspector for support or download.
# See https://aboutcode.org for more information about nexB OSS projects.
#
from typing import NamedTuple
import pytest
from python_inspector import utils_pypi
from python_inspector.utils_pypi import Distribution
from python_inspector.utils_pypi import PypiPackage
from python_inspector.utils_pypi import Sdist
from python_inspector.utils_pypi import Wheel
class DistTest(NamedTuple):
filename: str
expected_class: type
expected_name: str
expected_version: str
def check(self, using=Distribution):
dist = using.from_filename(self.filename)
assert dist.name == self.expected_name
assert dist.version == self.expected_version
wheel_tests = [
DistTest(
filename="package.repo/SomeProject-1.2.3-py33-none-any.whl",
expected_class=Wheel,
expected_name="SomeProject",
expected_version="1.2.3",
),
DistTest(
filename="SomeProject-1.2.3+cpu-py33-none-any.whl",
expected_class=Wheel,
expected_name="SomeProject",
expected_version="1.2.3+cpu",
),
DistTest(
filename="/scancode_toolkit_mini-32.0.6-cp311-none-any.whl",
expected_class=Wheel,
expected_name="scancode-toolkit-mini",
expected_version="32.0.6",
),
DistTest(
filename="example/torch-2.0.0+cpu.cxx11.abi-cp310-cp310-linux_x86_64.whl",
expected_class=Wheel,
expected_name="torch",
expected_version="2.0.0+cpu.cxx11.abi",
),
DistTest(
filename="torch-1.10.2+cpu-cp39-cp39-win_amd64.whl",
expected_class=Wheel,
expected_name="torch",
expected_version="1.10.2+cpu",
),
DistTest(
filename="torch-2.0.0+cpu.cxx11.abi-cp310-cp310-linux_x86_64.whl",
expected_class=Wheel,
expected_name="torch",
expected_version="2.0.0+cpu.cxx11.abi",
),
DistTest(
filename="/torch-1.10.2+cpu-cp39-cp39-win_amd64.whl",
expected_class=Wheel,
expected_name="torch",
expected_version="1.10.2+cpu",
),
DistTest(
filename="example/torch-2.0.0%2Bcpu.cxx11.abi-cp310-cp310-linux_x86_64.whl",
expected_class=Wheel,
expected_name="torch",
expected_version="2.0.0+cpu.cxx11.abi",
),
DistTest(
filename="torch-1.10.2%2Bcpu-cp39-cp39-win_amd64.whl",
expected_class=Wheel,
expected_name="torch",
expected_version="1.10.2+cpu",
),
DistTest(
filename="torch-2.0.0%2Bcpu.cxx11.abi-cp310-cp310-linux_x86_64.whl",
expected_class=Wheel,
expected_name="torch",
expected_version="2.0.0+cpu.cxx11.abi",
),
DistTest(
filename="/torch-1.10.2%2Bcpu-cp39-cp39-win_amd64.whl",
expected_class=Wheel,
expected_name="torch",
expected_version="1.10.2+cpu",
),
]
sdist_tests = [
DistTest(
filename="scancode-toolkit-mini-32.0.6.tar.gz",
expected_class=Sdist,
expected_name="scancode-toolkit-mini",
expected_version="32.0.6",
),
DistTest(
filename="/scancode-toolkit-mini-32.0.6.tar.gz",
expected_class=Sdist,
expected_name="scancode-toolkit-mini",
expected_version="32.0.6",
),
DistTest(
filename="foo/bar/scancode-toolkit-mini-32.0.6.tar.gz",
expected_class=Sdist,
expected_name="scancode-toolkit-mini",
expected_version="32.0.6",
),
DistTest(
filename="scancode-toolkit-mini-32.0.6.zip",
expected_class=Sdist,
expected_name="scancode-toolkit-mini",
expected_version="32.0.6",
),
DistTest(
filename="/scancode-toolkit-mini-32.0.6.zip",
expected_class=Sdist,
expected_name="scancode-toolkit-mini",
expected_version="32.0.6",
),
DistTest(
filename="foo/bar/scancode-toolkit-mini-32.0.6.zip",
expected_class=Sdist,
expected_name="scancode-toolkit-mini",
expected_version="32.0.6",
),
]
linux_platforms = [
"linux_x86_64",
"manylinux1_x86_64",
"manylinux2010_x86_64",
"manylinux2014_x86_64",
"manylinux_2_27_x86_64",
"manylinux_2_28_x86_64",
]
@pytest.mark.parametrize("dist_test", sdist_tests + wheel_tests)
def test_Distribution_from_filename(dist_test):
dist_test.check()
@pytest.mark.parametrize("dist_test", sdist_tests)
def test_Sdist_from_filename(dist_test):
dist_test.check(using=Sdist)
@pytest.mark.parametrize("dist_test", wheel_tests)
def test_Wheel_from_filename(dist_test):
dist_test.check(using=Wheel)
@pytest.mark.parametrize("linux_platform", linux_platforms)
def test_PypiPackage_get_supported_wheels(linux_platform):
whl = Wheel.from_filename(f"onnxruntime-1.19.2-cp311-cp311-{linux_platform}.whl")
pkg = PypiPackage.package_from_dists(dists=[whl])
env = utils_pypi.Environment.from_pyver_and_os(python_version="311", operating_system="linux")
supported_wheels = list(pkg.get_supported_wheels(environment=env))
assert supported_wheels == [whl]