Skip to content

Commit ab215b7

Browse files
committed
gh-117829 : adding tests for zipapp module
1 parent da75715 commit ab215b7

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

Lib/test/test_zipapp.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import io
44
import pathlib
5+
import re
56
import stat
67
import sys
78
import tempfile
@@ -316,6 +317,67 @@ def test_content_of_copied_archive(self):
316317
with zipfile.ZipFile(new_target, 'r') as z:
317318
self.assertEqual(set(z.namelist()), {'__main__.py'})
318319

320+
def test_create_archive_with_include_pattern(self):
321+
source = self.tmpdir / 'source'
322+
source.mkdir()
323+
(source / '.DS_Store').touch()
324+
(source / 'zed.py').touch()
325+
(source / 'bin').mkdir()
326+
(source / 'bin' / 'qux').touch()
327+
(source / 'bin' / 'baz').touch()
328+
(source / '__main__.py').touch()
329+
target = io.BytesIO()
330+
zipapp.create_archive(
331+
source=str(source),
332+
target=target,
333+
include_pattern=re.compile(r".*\.py")
334+
)
335+
target.seek(0)
336+
with zipfile.ZipFile(target, 'r') as zf:
337+
self.assertEqual(zf.namelist(),
338+
["__main__.py", "zed.py"])
339+
340+
def test_create_archive_with_exclude_pattern(self):
341+
source = self.tmpdir / 'source'
342+
source.mkdir()
343+
(source / '.DS_Store').touch()
344+
(source / 'zed.py').touch()
345+
(source / 'bin').mkdir()
346+
(source / 'bin' / 'qux').touch()
347+
(source / 'bin' / 'baz').touch()
348+
(source / '__main__.py').touch()
349+
target = io.BytesIO()
350+
zipapp.create_archive(
351+
source=str(source),
352+
target=target,
353+
exclude_pattern=re.compile(r".*\.py")
354+
)
355+
target.seek(0)
356+
with zipfile.ZipFile(target, 'r') as zf:
357+
self.assertEqual(zf.namelist(),
358+
[".DS_Store", "bin/", "bin/baz", "bin/qux"])
359+
360+
def test_create_archive_with_include_and_exclude_pattern(self):
361+
source = self.tmpdir / 'source'
362+
source.mkdir()
363+
(source / '.DS_Store').touch()
364+
(source / 'zed.py').touch()
365+
(source / 'bin').mkdir()
366+
(source / 'bin' / 'qux').touch()
367+
(source / 'bin' / 'baz').touch()
368+
(source / '__main__.py').touch()
369+
target = io.BytesIO()
370+
zipapp.create_archive(
371+
source=str(source),
372+
target=target,
373+
include_pattern=re.compile(r".*\.py"),
374+
exclude_pattern=re.compile(r".*z.*")
375+
)
376+
target.seek(0)
377+
with zipfile.ZipFile(target, 'r') as zf:
378+
self.assertEqual(zf.namelist(),
379+
["__main__.py"])
380+
319381
# (Unix only) tests that archives with shebang lines are made executable
320382
@unittest.skipIf(sys.platform == 'win32',
321383
'Windows does not support an executable bit')

0 commit comments

Comments
 (0)