|
| 1 | +import io |
1 | 2 | import unittest |
2 | 3 |
|
3 | 4 | import tools.wheelmaker as wheelmaker |
4 | 5 |
|
5 | 6 |
|
| 7 | +class QuoteAllFilenamesTest(unittest.TestCase): |
| 8 | + """Tests for quote_all_filenames behavior in _WhlFile. |
| 9 | +
|
| 10 | + Some wheels (like torch) have all filenames quoted in their RECORD file. |
| 11 | + When repacking, we preserve this style to minimize diffs. |
| 12 | + """ |
| 13 | + |
| 14 | + def _make_whl_file(self, quote_all: bool) -> wheelmaker._WhlFile: |
| 15 | + """Create a _WhlFile instance for testing.""" |
| 16 | + buf = io.BytesIO() |
| 17 | + return wheelmaker._WhlFile( |
| 18 | + buf, |
| 19 | + mode="w", |
| 20 | + distribution_prefix="test-1.0.0", |
| 21 | + quote_all_filenames=quote_all, |
| 22 | + ) |
| 23 | + |
| 24 | + def test_quote_all_quotes_simple_filenames(self) -> None: |
| 25 | + """When quote_all_filenames=True, all filenames are quoted.""" |
| 26 | + whl = self._make_whl_file(quote_all=True) |
| 27 | + self.assertEqual(whl._quote_filename("foo/bar.py"), '"foo/bar.py"') |
| 28 | + |
| 29 | + def test_quote_all_false_leaves_simple_filenames_unquoted(self) -> None: |
| 30 | + """When quote_all_filenames=False, simple filenames stay unquoted.""" |
| 31 | + whl = self._make_whl_file(quote_all=False) |
| 32 | + self.assertEqual(whl._quote_filename("foo/bar.py"), "foo/bar.py") |
| 33 | + |
| 34 | + def test_quote_all_quotes_filenames_with_commas(self) -> None: |
| 35 | + """Filenames with commas are always quoted, regardless of quote_all_filenames.""" |
| 36 | + whl = self._make_whl_file(quote_all=True) |
| 37 | + self.assertEqual(whl._quote_filename("foo,bar/baz.py"), '"foo,bar/baz.py"') |
| 38 | + |
| 39 | + whl = self._make_whl_file(quote_all=False) |
| 40 | + self.assertEqual(whl._quote_filename("foo,bar/baz.py"), '"foo,bar/baz.py"') |
| 41 | + |
| 42 | + |
6 | 43 | class ArcNameFromTest(unittest.TestCase): |
7 | 44 | def test_arcname_from(self) -> None: |
8 | 45 | # (name, distribution_prefix, strip_path_prefixes, want) tuples |
|
0 commit comments