|
1 | 1 | import io |
2 | 2 | import unittest |
| 3 | +from dataclasses import dataclass, field |
3 | 4 |
|
4 | 5 | import tools.wheelmaker as wheelmaker |
5 | 6 |
|
@@ -44,61 +45,98 @@ def test_quote_all_quotes_filenames_with_commas(self) -> None: |
44 | 45 | ) |
45 | 46 |
|
46 | 47 |
|
| 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 | + |
47 | 57 | class ArcNameFromTest(unittest.TestCase): |
48 | 58 | 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 | + ), |
54 | 71 | # 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 | + ), |
56 | 77 | # 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", |
63 | 92 | ), |
64 | | - ("foo/bar/baz/file.py", "", ["foo/bar/baz", "foo"], "", "/file.py"), |
65 | | - ("foo/file2.py", "", ["foo/bar/baz", "foo"], "", "/file2.py"), |
66 | 93 | # Files under the distribution prefix (eg mylib-1.0.0-dist-info) |
67 | 94 | # 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", |
74 | 105 | ), |
75 | | - ("mylib/a/b/c/WHEEL", "mylib", ["mylib"], "", "mylib/a/b/c/WHEEL"), |
76 | 106 | # 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", |
85 | 123 | ), |
86 | 124 | ] |
87 | | - for name, prefix, strip, add, want in checks: |
| 125 | + for test_case in test_cases: |
88 | 126 | 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, |
94 | 132 | ): |
95 | 133 | 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, |
100 | 138 | ) |
101 | | - self.assertEqual(got, want) |
| 139 | + self.assertEqual(got, test_case.expected) |
102 | 140 |
|
103 | 141 |
|
104 | 142 | class GetNewRequirementLineTest(unittest.TestCase): |
|
0 commit comments