@@ -95,7 +95,7 @@ def zipfile_ondisk(self, alpharep):
9595 def test_iterdir_and_types (self , alpharep ):
9696 root = zipfile .Path (alpharep )
9797 assert root .is_dir ()
98- a , n , b , g , j = root .iterdir ()
98+ a , n , b , g , j = root .iterdir () # noqa: RUF059
9999 assert a .is_file ()
100100 assert b .is_dir ()
101101 assert g .is_dir ()
@@ -115,8 +115,8 @@ def test_is_file_missing(self, alpharep):
115115 @pass_alpharep
116116 def test_iterdir_on_file (self , alpharep ):
117117 root = zipfile .Path (alpharep )
118- a , n , b , g , j = root .iterdir ()
119- with self .assertRaises (ValueError ):
118+ a , n , b , g , j = root .iterdir () # noqa: RUF059
119+ with self .assertRaises (NotADirectoryError ):
120120 a .iterdir ()
121121
122122 @pass_alpharep
@@ -130,7 +130,7 @@ def test_subdir_is_dir(self, alpharep):
130130 @pass_alpharep
131131 def test_open (self , alpharep ):
132132 root = zipfile .Path (alpharep )
133- a , n , b , g , j = root .iterdir ()
133+ a , n , b , g , j = root .iterdir () # noqa: RUF059
134134 with a .open (encoding = "utf-8" ) as strm :
135135 data = strm .read ()
136136 self .assertEqual (data , "content of a" )
@@ -173,24 +173,30 @@ def test_open_encoding_errors(self):
173173 data = u16 .read_text ("utf-8" , encoding = "utf-8" )
174174
175175 # both keyword arguments work.
176- with u16 .open ("r" , encoding = "utf-8" , errors = "strict" ) as f :
177- # error during decoding with wrong codec.
178- with self .assertRaises (UnicodeDecodeError ):
179- f .read ()
176+ # error during decoding with wrong codec.
177+ with (
178+ u16 .open ("r" , encoding = "utf-8" , errors = "strict" ) as f ,
179+ self .assertRaises (UnicodeDecodeError ),
180+ ):
181+ f .read ()
180182
181183 @unittest .skipIf (
182184 not getattr (sys .flags , 'warn_default_encoding' , 0 ),
183185 "Requires warn_default_encoding" ,
184186 )
187+ @unittest .skipIf (
188+ sys .implementation .name == 'pypy' and sys .pypy_version_info < (7 , 3 , 18 ),
189+ "Older PyPy versions set the wrong stacklevel in text_encoding()" ,
190+ )
185191 @pass_alpharep
186192 def test_encoding_warnings (self , alpharep ):
187193 """EncodingWarning must blame the read_text and open calls."""
188194 assert sys .flags .warn_default_encoding
189195 root = zipfile .Path (alpharep )
190- with self .assertWarns (EncodingWarning ) as wc : # noqa: F821 (astral-sh/ruff#13296)
196+ with self .assertWarns (EncodingWarning ) as wc :
191197 root .joinpath ("a.txt" ).read_text ()
192198 assert __file__ == wc .filename
193- with self .assertWarns (EncodingWarning ) as wc : # noqa: F821 (astral-sh/ruff#13296)
199+ with self .assertWarns (EncodingWarning ) as wc :
194200 root .joinpath ("a.txt" ).open ("r" ).close ()
195201 assert __file__ == wc .filename
196202
@@ -235,7 +241,7 @@ def test_open_missing_directory(self, alpharep):
235241 @pass_alpharep
236242 def test_read (self , alpharep ):
237243 root = zipfile .Path (alpharep )
238- a , n , b , g , j = root .iterdir ()
244+ a , n , b , g , j = root .iterdir () # noqa: RUF059
239245 assert a .read_text (encoding = "utf-8" ) == "content of a"
240246 # Also check positional encoding arg (gh-101144).
241247 assert a .read_text ("utf-8" ) == "content of a"
@@ -302,7 +308,7 @@ def test_mutability(self, alpharep):
302308 reflect that change.
303309 """
304310 root = zipfile .Path (alpharep )
305- a , n , b , g , j = root .iterdir ()
311+ a , n , b , g , j = root .iterdir () # noqa: RUF059
306312 alpharep .writestr ('foo.txt' , 'foo' )
307313 alpharep .writestr ('bar/baz.txt' , 'baz' )
308314 assert any (child .name == 'foo.txt' for child in root .iterdir ())
@@ -540,6 +546,27 @@ def test_glob_chars(self, alpharep):
540546 zipfile .Path (alpharep , "j/l.baz" ),
541547 ]
542548
549+ @parameterize (
550+ ['alpharep' , 'pattern' , 'expected' ],
551+ [
552+ (alpharep , pattern , expected )
553+ for alpharep in alpharep_generators
554+ for pattern , expected in [
555+ ('[!a].txt' , {'n.txt' }),
556+ ('[!an].txt' , set ()),
557+ ('[!b]' , {'g/' , 'j/' }),
558+ ('j/[!k].b*' , {'j/l.baz' , 'j/m.bar' }),
559+ ('j/[^k].b*' , {'j/k.bin' }),
560+ ('j/[!k-l].b*' , {'j/m.bar' }),
561+ ('j/[k-l].b*' , {'j/k.bin' , 'j/l.baz' }),
562+ ('b[!x]c.txt' , set ()),
563+ ]
564+ ],
565+ )
566+ def test_glob_character_class_syntax (self , alpharep , pattern , expected ):
567+ root = zipfile .Path (alpharep )
568+ assert {path .at for path in root .glob (pattern )} == expected
569+
543570 def test_glob_empty (self ):
544571 zip_file = self .enterContext (zipfile .ZipFile (io .BytesIO (), 'w' ))
545572 root = zipfile .Path (zip_file )
@@ -592,7 +619,7 @@ def test_pickle(self, alpharep, path_type, subpath):
592619 saved_1 = pickle .dumps (root )
593620 root .root .close ()
594621 restored_1 = pickle .loads (saved_1 )
595- first , * rest = restored_1 .iterdir ()
622+ first , * _rest = restored_1 .iterdir ()
596623 assert first .read_text (encoding = 'utf-8' ).startswith ('content of ' )
597624 restored_1 .root .close ()
598625
0 commit comments