@@ -551,7 +551,12 @@ def replace(self, old, new):
551551 z .writestr (name , data )
552552 z .close ()
553553 zi = zipimport .zipimporter (TEMP_ZIP )
554- self .assertEqual (data , zi .get_data (FunnyStr (name )))
554+ try :
555+ data2 = zi .get_data (FunnyStr (name ))
556+ except AttributeError :
557+ pass
558+ else :
559+ self .assertEqual (data2 , data )
555560 finally :
556561 z .close ()
557562 os .remove (TEMP_ZIP )
@@ -677,24 +682,24 @@ def testBytesPath(self):
677682
678683 zipimport .zipimporter (filename )
679684 zipimport .zipimporter (os .fsencode (filename ))
680- with self .assertWarns ( DeprecationWarning ):
685+ with self .assertRaises ( TypeError ):
681686 zipimport .zipimporter (bytearray (os .fsencode (filename )))
682- with self .assertWarns ( DeprecationWarning ):
687+ with self .assertRaises ( TypeError ):
683688 zipimport .zipimporter (memoryview (os .fsencode (filename )))
684689
685690 @support .cpython_only
686691 def testUninitializedZipimporter (self ):
687692 # The interpreter shouldn't crash in case of calling methods of an
688693 # uninitialized zipimport.zipimporter object.
689694 zi = zipimport .zipimporter .__new__ (zipimport .zipimporter )
690- self .assertRaises (ValueError , zi .find_module , 'foo' )
691- self .assertRaises (ValueError , zi .find_loader , 'foo' )
692- self .assertRaises (ValueError , zi .load_module , 'foo' )
693- self .assertRaises (ValueError , zi .get_filename , 'foo' )
694- self .assertRaises (ValueError , zi .is_package , 'foo' )
695- self .assertRaises (ValueError , zi .get_data , 'foo' )
696- self .assertRaises (ValueError , zi .get_code , 'foo' )
697- self .assertRaises (ValueError , zi .get_source , 'foo' )
695+ self .assertRaises (( ValueError , AttributeError ) , zi .find_module , 'foo' )
696+ self .assertRaises (( ValueError , AttributeError ) , zi .find_loader , 'foo' )
697+ self .assertRaises (( ValueError , AttributeError ) , zi .load_module , 'foo' )
698+ self .assertRaises (( ValueError , AttributeError ) , zi .get_filename , 'foo' )
699+ self .assertRaises (( ValueError , AttributeError ) , zi .is_package , 'foo' )
700+ self .assertRaises (( ValueError , AttributeError ) , zi .get_data , 'foo' )
701+ self .assertRaises (( ValueError , AttributeError ) , zi .get_code , 'foo' )
702+ self .assertRaises (( ValueError , AttributeError ) , zi .get_source , 'foo' )
698703
699704
700705@support .requires_zlib
@@ -712,7 +717,7 @@ def bad_decompress(*args):
712717 zip_file .writestr ('bar.py' , b'print("hello world")' , ZIP_DEFLATED )
713718 zi = zipimport .zipimporter (TEMP_ZIP )
714719 with support .swap_attr (zlib , 'decompress' , bad_decompress ):
715- self .assertRaises (TypeError , zi .get_source , 'bar' )
720+ self .assertRaises (( TypeError , AttributeError ) , zi .get_source , 'bar' )
716721
717722
718723class BadFileZipImportTestCase (unittest .TestCase ):
0 commit comments