@@ -326,12 +326,14 @@ def test_create_archive_with_include_pattern(self):
326326 (source / 'bin' / 'qux' ).touch ()
327327 (source / 'bin' / 'baz' ).touch ()
328328 (source / '__main__.py' ).touch ()
329+
329330 target = io .BytesIO ()
330331 zipapp .create_archive (
331332 source = str (source ),
332333 target = target ,
333334 include_pattern = re .compile (r".*\.py" )
334335 )
336+
335337 target .seek (0 )
336338 with zipfile .ZipFile (target , 'r' ) as zf :
337339 self .assertEqual (zf .namelist (),
@@ -346,12 +348,14 @@ def test_create_archive_with_exclude_pattern(self):
346348 (source / 'bin' / 'qux' ).touch ()
347349 (source / 'bin' / 'baz' ).touch ()
348350 (source / '__main__.py' ).touch ()
351+
349352 target = io .BytesIO ()
350353 zipapp .create_archive (
351354 source = str (source ),
352355 target = target ,
353356 exclude_pattern = re .compile (r".*\.py" )
354357 )
358+
355359 target .seek (0 )
356360 with zipfile .ZipFile (target , 'r' ) as zf :
357361 self .assertEqual (zf .namelist (),
@@ -366,13 +370,15 @@ def test_create_archive_with_include_and_exclude_pattern(self):
366370 (source / 'bin' / 'qux' ).touch ()
367371 (source / 'bin' / 'baz' ).touch ()
368372 (source / '__main__.py' ).touch ()
373+
369374 target = io .BytesIO ()
370375 zipapp .create_archive (
371376 source = str (source ),
372377 target = target ,
373378 include_pattern = re .compile (r".*\.py" ),
374379 exclude_pattern = re .compile (r".*z.*" )
375380 )
381+
376382 target .seek (0 )
377383 with zipfile .ZipFile (target , 'r' ) as zf :
378384 self .assertEqual (zf .namelist (),
@@ -480,7 +486,61 @@ def test_info_error(self):
480486 self .assertTrue (cm .exception .code )
481487
482488 def test_cmdline_create_with_include_pattern (self ):
489+ source = self .tmpdir / 'source'
490+ source .mkdir ()
491+ (source / '.DS_Store' ).touch ()
492+ (source / 'zed.py' ).touch ()
493+ (source / 'bin' ).mkdir ()
494+ (source / 'bin' / 'qux' ).touch ()
495+ (source / 'bin' / 'baz' ).touch ()
496+ (source / '__main__.py' ).touch ()
497+
498+ args = [str (source ), '--include-pattern' , r'.*\.py' ]
499+ zipapp .main (args )
500+ target = source .with_suffix ('.pyz' )
501+ self .assertTrue (target .is_file ())
502+
503+ with zipfile .ZipFile (target , 'r' ) as zf :
504+ self .assertEqual (zf .namelist (),
505+ ["__main__.py" , "zed.py" ])
506+
507+ def test_cmdline_create_with_exclude_pattern (self ):
508+ source = self .tmpdir / 'source'
509+ source .mkdir ()
510+ (source / '.DS_Store' ).touch ()
511+ (source / 'zed.py' ).touch ()
512+ (source / 'bin' ).mkdir ()
513+ (source / 'bin' / 'qux' ).touch ()
514+ (source / 'bin' / 'baz' ).touch ()
515+ (source / '__main__.py' ).touch ()
516+
517+ args = [str (source ), '--exclude-pattern' , r'.*\.py' ]
518+ zipapp .main (args )
519+ target = source .with_suffix ('.pyz' )
520+ self .assertTrue (target .is_file ())
521+
522+ with zipfile .ZipFile (target , 'r' ) as zf :
523+ self .assertEqual (zf .namelist (),
524+ [".DS_Store" , "bin/" , "bin/baz" , "bin/qux" ])
525+
526+ def test_cmdline_create_with_include_and_exclude_pattern (self ):
527+ source = self .tmpdir / 'source'
528+ source .mkdir ()
529+ (source / '.DS_Store' ).touch ()
530+ (source / 'zed.py' ).touch ()
531+ (source / 'bin' ).mkdir ()
532+ (source / 'bin' / 'qux' ).touch ()
533+ (source / 'bin' / 'baz' ).touch ()
534+ (source / '__main__.py' ).touch ()
483535
536+ args = [str (source ), '--include-pattern' , r'.*\.py' , '--exclude-pattern' , r'.*z.*' ]
537+ zipapp .main (args )
538+ target = source .with_suffix ('.pyz' )
539+ self .assertTrue (target .is_file ())
540+
541+ with zipfile .ZipFile (target , 'r' ) as zf :
542+ self .assertEqual (zf .namelist (),
543+ ["__main__.py" ])
484544
485545
486546if __name__ == "__main__" :
0 commit comments