@@ -551,7 +551,12 @@ def replace(self, old, new):
551
551
z .writestr (name , data )
552
552
z .close ()
553
553
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 )
555
560
finally :
556
561
z .close ()
557
562
os .remove (TEMP_ZIP )
@@ -677,24 +682,24 @@ def testBytesPath(self):
677
682
678
683
zipimport .zipimporter (filename )
679
684
zipimport .zipimporter (os .fsencode (filename ))
680
- with self .assertWarns ( DeprecationWarning ):
685
+ with self .assertRaises ( TypeError ):
681
686
zipimport .zipimporter (bytearray (os .fsencode (filename )))
682
- with self .assertWarns ( DeprecationWarning ):
687
+ with self .assertRaises ( TypeError ):
683
688
zipimport .zipimporter (memoryview (os .fsencode (filename )))
684
689
685
690
@support .cpython_only
686
691
def testUninitializedZipimporter (self ):
687
692
# The interpreter shouldn't crash in case of calling methods of an
688
693
# uninitialized zipimport.zipimporter object.
689
694
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' )
698
703
699
704
700
705
@support .requires_zlib
@@ -712,7 +717,7 @@ def bad_decompress(*args):
712
717
zip_file .writestr ('bar.py' , b'print("hello world")' , ZIP_DEFLATED )
713
718
zi = zipimport .zipimporter (TEMP_ZIP )
714
719
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' )
716
721
717
722
718
723
class BadFileZipImportTestCase (unittest .TestCase ):
0 commit comments