diff options
author | Paul Moore <p.f.moore@gmail.com> | 2017-08-26 17:04:12 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-08-26 17:04:12 (GMT) |
commit | 0780bf7578dc4c9c3852dc5e869aba515a2c65b1 (patch) | |
tree | db073e0b76aabdb567564e917bc92239e5109f2b /Lib/test/test_zipapp.py | |
parent | a5b4ea15b61e3f3985f4f0748a18f8b888a63532 (diff) | |
download | cpython-0780bf7578dc4c9c3852dc5e869aba515a2c65b1.zip cpython-0780bf7578dc4c9c3852dc5e869aba515a2c65b1.tar.gz cpython-0780bf7578dc4c9c3852dc5e869aba515a2c65b1.tar.bz2 |
bpo-31072: Rename the new filter argument for zipapp.create_archive. (#3049)
bpo-31072: Rename the new filter argument for zipapp.create_archive (GH-3049)
* Rename the new argument to "filter"
* Improve tests for the new functionality
* Add a "What's New" entry.
Diffstat (limited to 'Lib/test/test_zipapp.py')
-rw-r--r-- | Lib/test/test_zipapp.py | 31 |
1 files changed, 26 insertions, 5 deletions
diff --git a/Lib/test/test_zipapp.py b/Lib/test/test_zipapp.py index 47eed5f..56cf37c 100644 --- a/Lib/test/test_zipapp.py +++ b/Lib/test/test_zipapp.py @@ -53,10 +53,11 @@ class ZipAppTest(unittest.TestCase): self.assertIn('foo/', z.namelist()) self.assertIn('bar/', z.namelist()) - def test_create_archive_with_include_file(self): - # Test packing a directory and using include_file to specify which files to include. - def skip_pyc_files(file): - return '.pyc' not in str(file) + def test_create_archive_with_filter(self): + # Test packing a directory and using filter to specify + # which files to include. + def skip_pyc_files(path): + return path.suffix != '.pyc' source = self.tmpdir / 'source' source.mkdir() (source / '__main__.py').touch() @@ -64,12 +65,32 @@ class ZipAppTest(unittest.TestCase): (source / 'test.pyc').touch() target = self.tmpdir / 'source.pyz' - zipapp.create_archive(source, target, include_file=skip_pyc_files) + zipapp.create_archive(source, target, filter=skip_pyc_files) with zipfile.ZipFile(target, 'r') as z: self.assertIn('__main__.py', z.namelist()) self.assertIn('test.py', z.namelist()) self.assertNotIn('test.pyc', z.namelist()) + def test_create_archive_filter_exclude_dir(self): + # Test packing a directory and using a filter to exclude a + # subdirectory (ensures that the path supplied to include + # is relative to the source location, as expected). + def skip_dummy_dir(path): + return path.parts[0] != 'dummy' + source = self.tmpdir / 'source' + source.mkdir() + (source / '__main__.py').touch() + (source / 'test.py').touch() + (source / 'dummy').mkdir() + (source / 'dummy' / 'test2.py').touch() + target = self.tmpdir / 'source.pyz' + + zipapp.create_archive(source, target, filter=skip_dummy_dir) + with zipfile.ZipFile(target, 'r') as z: + self.assertEqual(len(z.namelist()), 2) + self.assertIn('__main__.py', z.namelist()) + self.assertIn('test.py', z.namelist()) + def test_create_archive_default_target(self): # Test packing a directory to the default name. source = self.tmpdir / 'source' |