@@ -41,16 +41,21 @@ def build_alpharep_fixture():
4141 │ ├── d
4242 │ │ └── e.txt
4343 │ └── f.txt
44- └── g
45- └── h
46- └── i.txt
44+ ├── g
45+ │ └── h
46+ │ └── i.txt
47+ └── j
48+ ├── k.bin
49+ ├── l.baz
50+ └── m.bar
4751
4852 This fixture has the following key characteristics:
4953
5054 - a file at the root (a)
5155 - a file two levels deep (b/d/e)
5256 - multiple files in a directory (b/c, b/f)
5357 - a directory containing only a directory (g/h)
58+ - a directory with files of different extensions (j/klm)
5459
5560 "alpha" because it uses alphabet
5661 "rep" because it's a representative example
@@ -62,6 +67,9 @@ def build_alpharep_fixture():
6267 zf .writestr ("b/d/e.txt" , b"content of e" )
6368 zf .writestr ("b/f.txt" , b"content of f" )
6469 zf .writestr ("g/h/i.txt" , b"content of i" )
70+ zf .writestr ("j/k.bin" , b"content of k" )
71+ zf .writestr ("j/l.baz" , b"content of l" )
72+ zf .writestr ("j/m.bar" , b"content of m" )
6573 zf .filename = "alpharep.zip"
6674 return zf
6775
@@ -92,7 +100,7 @@ def zipfile_ondisk(self, alpharep):
92100 def test_iterdir_and_types (self , alpharep ):
93101 root = zipfile .Path (alpharep )
94102 assert root .is_dir ()
95- a , b , g = root .iterdir ()
103+ a , b , g , j = root .iterdir ()
96104 assert a .is_file ()
97105 assert b .is_dir ()
98106 assert g .is_dir ()
@@ -112,7 +120,7 @@ def test_is_file_missing(self, alpharep):
112120 @pass_alpharep
113121 def test_iterdir_on_file (self , alpharep ):
114122 root = zipfile .Path (alpharep )
115- a , b , g = root .iterdir ()
123+ a , b , g , j = root .iterdir ()
116124 with self .assertRaises (ValueError ):
117125 a .iterdir ()
118126
@@ -127,7 +135,7 @@ def test_subdir_is_dir(self, alpharep):
127135 @pass_alpharep
128136 def test_open (self , alpharep ):
129137 root = zipfile .Path (alpharep )
130- a , b , g = root .iterdir ()
138+ a , b , g , j = root .iterdir ()
131139 with a .open (encoding = "utf-8" ) as strm :
132140 data = strm .read ()
133141 self .assertEqual (data , "content of a" )
@@ -229,7 +237,7 @@ def test_open_missing_directory(self):
229237 @pass_alpharep
230238 def test_read (self , alpharep ):
231239 root = zipfile .Path (alpharep )
232- a , b , g = root .iterdir ()
240+ a , b , g , j = root .iterdir ()
233241 assert a .read_text (encoding = "utf-8" ) == "content of a"
234242 # Also check positional encoding arg (gh-101144).
235243 assert a .read_text ("utf-8" ) == "content of a"
@@ -295,7 +303,7 @@ def test_mutability(self, alpharep):
295303 reflect that change.
296304 """
297305 root = zipfile .Path (alpharep )
298- a , b , g = root .iterdir ()
306+ a , b , g , j = root .iterdir ()
299307 alpharep .writestr ('foo.txt' , 'foo' )
300308 alpharep .writestr ('bar/baz.txt' , 'baz' )
301309 assert any (child .name == 'foo.txt' for child in root .iterdir ())
@@ -394,6 +402,13 @@ def test_suffixes(self, alpharep):
394402 e = root / '.hgrc'
395403 assert e .suffixes == []
396404
405+ @pass_alpharep
406+ def test_suffix_no_filename (self , alpharep ):
407+ alpharep .filename = None
408+ root = zipfile .Path (alpharep )
409+ assert root .joinpath ('example' ).suffix == ""
410+ assert root .joinpath ('example' ).suffixes == []
411+
397412 @pass_alpharep
398413 def test_stem (self , alpharep ):
399414 """
@@ -411,6 +426,8 @@ def test_stem(self, alpharep):
411426 d = root / "d"
412427 assert d .stem == "d"
413428
429+ assert (root / ".gitignore" ).stem == ".gitignore"
430+
414431 @pass_alpharep
415432 def test_root_parent (self , alpharep ):
416433 root = zipfile .Path (alpharep )
@@ -442,12 +459,49 @@ def test_match_and_glob(self, alpharep):
442459 assert not root .match ("*.txt" )
443460
444461 assert list (root .glob ("b/c.*" )) == [zipfile .Path (alpharep , "b/c.txt" )]
462+ assert list (root .glob ("b/*.txt" )) == [
463+ zipfile .Path (alpharep , "b/c.txt" ),
464+ zipfile .Path (alpharep , "b/f.txt" ),
465+ ]
445466
467+ @pass_alpharep
468+ def test_glob_recursive (self , alpharep ):
469+ root = zipfile .Path (alpharep )
446470 files = root .glob ("**/*.txt" )
447471 assert all (each .match ("*.txt" ) for each in files )
448472
449473 assert list (root .glob ("**/*.txt" )) == list (root .rglob ("*.txt" ))
450474
475+ @pass_alpharep
476+ def test_glob_subdirs (self , alpharep ):
477+ root = zipfile .Path (alpharep )
478+
479+ assert list (root .glob ("*/i.txt" )) == []
480+ assert list (root .rglob ("*/i.txt" )) == [zipfile .Path (alpharep , "g/h/i.txt" )]
481+
482+ @pass_alpharep
483+ def test_glob_does_not_overmatch_dot (self , alpharep ):
484+ root = zipfile .Path (alpharep )
485+
486+ assert list (root .glob ("*.xt" )) == []
487+
488+ @pass_alpharep
489+ def test_glob_single_char (self , alpharep ):
490+ root = zipfile .Path (alpharep )
491+
492+ assert list (root .glob ("a?txt" )) == [zipfile .Path (alpharep , "a.txt" )]
493+ assert list (root .glob ("a[.]txt" )) == [zipfile .Path (alpharep , "a.txt" )]
494+ assert list (root .glob ("a[?]txt" )) == []
495+
496+ @pass_alpharep
497+ def test_glob_chars (self , alpharep ):
498+ root = zipfile .Path (alpharep )
499+
500+ assert list (root .glob ("j/?.b[ai][nz]" )) == [
501+ zipfile .Path (alpharep , "j/k.bin" ),
502+ zipfile .Path (alpharep , "j/l.baz" ),
503+ ]
504+
451505 def test_glob_empty (self ):
452506 root = zipfile .Path (zipfile .ZipFile (io .BytesIO (), 'w' ))
453507 with self .assertRaises (ValueError ):
0 commit comments