@@ -113,6 +113,19 @@ def test_target_overwrites_source_file(self):
113113 with self .assertRaises (zipapp .ZipAppError ):
114114 zipapp .create_archive (source , target )
115115
116+ def test_target_overwrites_filtered_source_file (self ):
117+ # If there's a filter that excludes the target,
118+ # the overwrite check shouldn't trigger.
119+ source = self .tmpdir
120+ (source / '__main__.py' ).touch ()
121+ target = source / 'target.pyz'
122+ target .touch ()
123+ pyz_filter = lambda p : not p .match ('*.pyz' )
124+ zipapp .create_archive (source , target , filter = pyz_filter )
125+ with zipfile .ZipFile (target , 'r' ) as z :
126+ self .assertEqual (len (z .namelist ()), 1 )
127+ self .assertIn ('__main__.py' , z .namelist ())
128+
116129 def test_create_archive_filter_exclude_dir (self ):
117130 # Test packing a directory and using a filter to exclude a
118131 # subdirectory (ensures that the path supplied to include
@@ -246,7 +259,7 @@ def test_pack_to_fileobj(self):
246259 (source / '__main__.py' ).touch ()
247260 target = io .BytesIO ()
248261 zipapp .create_archive (str (source ), target , interpreter = 'python' )
249- self .assertTrue (target .getvalue (). startswith ( b'#!python\n ' ) )
262+ self .assertStartsWith (target .getvalue (), b'#!python\n ' )
250263
251264 def test_read_shebang (self ):
252265 # Test that we can read the shebang line correctly.
@@ -287,7 +300,7 @@ def test_write_shebang_to_fileobj(self):
287300 zipapp .create_archive (str (source ), str (target ), interpreter = 'python' )
288301 new_target = io .BytesIO ()
289302 zipapp .create_archive (str (target ), new_target , interpreter = 'python2.7' )
290- self .assertTrue (new_target .getvalue (). startswith ( b'#!python2.7\n ' ) )
303+ self .assertStartsWith (new_target .getvalue (), b'#!python2.7\n ' )
291304
292305 def test_read_from_pathlike_obj (self ):
293306 # Test that we can copy an archive using a path-like object
@@ -313,7 +326,7 @@ def test_read_from_fileobj(self):
313326 new_target = io .BytesIO ()
314327 temp_archive .seek (0 )
315328 zipapp .create_archive (temp_archive , new_target , interpreter = 'python2.7' )
316- self .assertTrue (new_target .getvalue (). startswith ( b'#!python2.7\n ' ) )
329+ self .assertStartsWith (new_target .getvalue (), b'#!python2.7\n ' )
317330
318331 def test_remove_shebang (self ):
319332 # Test that we can remove the shebang from a file.
0 commit comments