Skip to content

Commit 7d60a82

Browse files
author
Antonio Kim
committed
Address comments
1 parent 927458b commit 7d60a82

File tree

2 files changed

+81
-40
lines changed

2 files changed

+81
-40
lines changed

python/private/py_wheel.bzl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,9 @@ For example:
181181
+ `"foo/" will prepend to `"bar/baz/file.py"` as `"foo/bar/baz/file.py"`
182182
+ `"foo_" will prepend to `"bar/baz/file.py"` as `"foo_bar/baz/file.py"`
183183
+ `stripping ["bar/"] and adding "foo/" will change `"bar/baz/file.py"` to `"foo/baz/file.py"`
184+
:::{versionadded} VERSION_NEXT_FEATURE
185+
The {attr}`add_path_prefix` attribute was added.
186+
:::
184187
""",
185188
),
186189
"author": attr.string(

tests/tools/wheelmaker_test.py

Lines changed: 78 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import io
22
import unittest
3+
from dataclasses import dataclass, field
34

45
import tools.wheelmaker as wheelmaker
56

@@ -44,61 +45,98 @@ def test_quote_all_quotes_filenames_with_commas(self) -> None:
4445
)
4546

4647

48+
@dataclass
49+
class ArcNameTestCase:
50+
name: str
51+
expected: str
52+
distribution_prefix: str = ""
53+
strip_path_prefixes: list[str] = field(default_factory=list)
54+
add_path_prefix: str = ""
55+
56+
4757
class ArcNameFromTest(unittest.TestCase):
4858
def test_arcname_from(self) -> None:
49-
# (name, distribution_prefix, strip_path_prefixes, add_path_prefix, want) tuples
50-
checks = [
51-
("a/b/c/file.py", "", [], "", "a/b/c/file.py"),
52-
("a/b/c/file.py", "", ["a"], "", "/b/c/file.py"),
53-
("a/b/c/file.py", "", ["a/b/"], "", "c/file.py"),
59+
test_cases = [
60+
ArcNameTestCase(name="a/b/c/file.py", expected="a/b/c/file.py"),
61+
ArcNameTestCase(
62+
name="a/b/c/file.py",
63+
strip_path_prefixes=["a"],
64+
expected="/b/c/file.py",
65+
),
66+
ArcNameTestCase(
67+
name="a/b/c/file.py",
68+
strip_path_prefixes=["a/b/"],
69+
expected="c/file.py",
70+
),
5471
# only first found is used and it's not cumulative.
55-
("a/b/c/file.py", "", ["a/", "b/"], "", "b/c/file.py"),
72+
ArcNameTestCase(
73+
name="a/b/c/file.py",
74+
strip_path_prefixes=["a/", "b/"],
75+
expected="b/c/file.py",
76+
),
5677
# Examples from docs
57-
(
58-
"foo/bar/baz/file.py",
59-
"",
60-
["foo", "foo/bar/baz"],
61-
"",
62-
"/bar/baz/file.py",
78+
ArcNameTestCase(
79+
name="foo/bar/baz/file.py",
80+
strip_path_prefixes=["foo", "foo/bar/baz"],
81+
expected="/bar/baz/file.py",
82+
),
83+
ArcNameTestCase(
84+
name="foo/bar/baz/file.py",
85+
strip_path_prefixes=["foo/bar/baz", "foo"],
86+
expected="/file.py",
87+
),
88+
ArcNameTestCase(
89+
name="foo/file2.py",
90+
strip_path_prefixes=["foo/bar/baz", "foo"],
91+
expected="/file2.py",
6392
),
64-
("foo/bar/baz/file.py", "", ["foo/bar/baz", "foo"], "", "/file.py"),
65-
("foo/file2.py", "", ["foo/bar/baz", "foo"], "", "/file2.py"),
6693
# Files under the distribution prefix (eg mylib-1.0.0-dist-info)
6794
# are unmodified
68-
(
69-
"mylib-0.0.1-dist-info/WHEEL",
70-
"mylib",
71-
[],
72-
"",
73-
"mylib-0.0.1-dist-info/WHEEL",
95+
ArcNameTestCase(
96+
name="mylib-0.0.1-dist-info/WHEEL",
97+
distribution_prefix="mylib",
98+
expected="mylib-0.0.1-dist-info/WHEEL",
99+
),
100+
ArcNameTestCase(
101+
name="mylib/a/b/c/WHEEL",
102+
distribution_prefix="mylib",
103+
strip_path_prefixes=["mylib"],
104+
expected="mylib/a/b/c/WHEEL",
74105
),
75-
("mylib/a/b/c/WHEEL", "mylib", ["mylib"], "", "mylib/a/b/c/WHEEL"),
76106
# Check that prefixes are added
77-
("a/b/c/file.py", "", [], "namespace/", "namespace/a/b/c/file.py"),
78-
("a/b/c/file.py", "", ["a"], "namespace", "namespace/b/c/file.py"),
79-
(
80-
"a/b/c/file.py",
81-
"",
82-
["a/b/"],
83-
"namespace_",
84-
"namespace_c/file.py",
107+
ArcNameTestCase(
108+
name="a/b/c/file.py",
109+
add_path_prefix="namespace/",
110+
expected="namespace/a/b/c/file.py",
111+
),
112+
ArcNameTestCase(
113+
name="a/b/c/file.py",
114+
strip_path_prefixes=["a"],
115+
add_path_prefix="namespace",
116+
expected="namespace/b/c/file.py",
117+
),
118+
ArcNameTestCase(
119+
name="a/b/c/file.py",
120+
strip_path_prefixes=["a/b/"],
121+
add_path_prefix="namespace_",
122+
expected="namespace_c/file.py",
85123
),
86124
]
87-
for name, prefix, strip, add, want in checks:
125+
for test_case in test_cases:
88126
with self.subTest(
89-
name=name,
90-
distribution_prefix=prefix,
91-
strip_path_prefixes=strip,
92-
add_path_prefix=add,
93-
want=want,
127+
name=test_case.name,
128+
distribution_prefix=test_case.distribution_prefix,
129+
strip_path_prefixes=test_case.strip_path_prefixes,
130+
add_path_prefix=test_case.add_path_prefix,
131+
want=test_case.expected,
94132
):
95133
got = wheelmaker.arcname_from(
96-
name=name,
97-
distribution_prefix=prefix,
98-
strip_path_prefixes=strip,
99-
add_path_prefix=add,
134+
name=test_case.name,
135+
distribution_prefix=test_case.distribution_prefix,
136+
strip_path_prefixes=test_case.strip_path_prefixes,
137+
add_path_prefix=test_case.add_path_prefix,
100138
)
101-
self.assertEqual(got, want)
139+
self.assertEqual(got, test_case.expected)
102140

103141

104142
class GetNewRequirementLineTest(unittest.TestCase):

0 commit comments

Comments
 (0)