@@ -69,31 +69,17 @@ def _capture_unraisable_hook(ur_args):
6969assert __version__ == "2.0.1.dev0" , ("This test_c.py file is for testing a version"
7070 " of cffi that differs from the one that we"
7171 " get from 'import _cffi_backend'" )
72- if sys .version_info < (3 ,):
73- type_or_class = "type"
74- mandatory_b_prefix = ''
75- mandatory_u_prefix = 'u'
76- bytechr = chr
77- bitem2bchr = lambda x : x
78- class U :
79- def __add__ (self , other ):
80- return eval ('u' + repr (other ).replace (r'\\u' , r'\u' )
81- .replace (r'\\U' , r'\U' ))
82- u = U ()
83- str2bytes = str
84- strict_compare = False
85- else :
86- type_or_class = "class"
87- long = int
88- unicode = str
89- unichr = chr
90- mandatory_b_prefix = 'b'
91- mandatory_u_prefix = ''
92- bytechr = lambda n : bytes ([n ])
93- bitem2bchr = bytechr
94- u = ""
95- str2bytes = lambda s : bytes (s , "ascii" )
96- strict_compare = True
72+ type_or_class = "class"
73+ long = int
74+ unicode = str
75+ unichr = chr
76+ mandatory_b_prefix = 'b'
77+ mandatory_u_prefix = ''
78+ bytechr = lambda n : bytes ([n ])
79+ bitem2bchr = bytechr
80+ u = ""
81+ str2bytes = lambda s : bytes (s , "ascii" )
82+ strict_compare = True
9783
9884def size_of_int ():
9985 BInt = new_primitive_type ("int" )
@@ -115,14 +101,9 @@ def find_and_load_library(name, flags=RTLD_NOW):
115101 path = None
116102 else :
117103 path = ctypes .util .find_library (name )
118- if path is None and sys .platform == 'darwin' and sys .version_info [:2 ] == (3 , 8 ):
119- pytest .xfail ("find_library usually broken on MacOS Python 3.8" )
120104 if path is None and name == 'c' :
121105 assert sys .platform == 'win32'
122- assert (sys .version_info >= (3 ,) or
123- '__pypy__' in sys .builtin_module_names )
124- pytest .skip ("dlopen(None) cannot work on Windows "
125- "with PyPy or Python 3" )
106+ pytest .skip ("dlopen(None) cannot work on Windows" )
126107 return load_library (path , flags )
127108
128109def test_load_library ():
@@ -1687,10 +1668,6 @@ def test_enum_in_struct():
16871668 "expected integer, got NoneType object" in msg ) # newer PyPys
16881669 with pytest .raises (TypeError ):
16891670 p .a1 = "def"
1690- if sys .version_info < (3 ,):
1691- BEnum2 = new_enum_type (unicode ("foo" ), (unicode ('abc' ),), (5 ,), BInt )
1692- assert string (cast (BEnum2 , 5 )) == 'abc'
1693- assert type (string (cast (BEnum2 , 5 ))) is str
16941671
16951672def test_enum_overflow ():
16961673 max_uint = 2 ** (size_of_int ()* 8 ) - 1
@@ -2024,8 +2001,6 @@ def test_string_byte():
20242001 BArray = new_array_type (new_pointer_type (BByte ), None )
20252002 a = newp (BArray , [65 , 66 , 67 ])
20262003 assert type (string (a )) is bytes and string (a ) == b'ABC'
2027- if 'PY_DOT_PY' not in globals () and sys .version_info < (3 ,):
2028- assert string (a , 8 ).startswith (b'ABC' ) # may contain additional garbage
20292004
20302005def test_string_wchar ():
20312006 for typename in ["wchar_t" , "char16_t" , "char32_t" ]:
@@ -2039,12 +2014,6 @@ def _test_string_wchar_variant(typename):
20392014 BArray = new_array_type (new_pointer_type (BWChar ), None )
20402015 a = newp (BArray , [u + 'A' , u + 'B' , u + 'C' ])
20412016 assert type (string (a )) is unicode and string (a ) == u + 'ABC'
2042- if 'PY_DOT_PY' not in globals () and sys .version_info < (3 ,):
2043- try :
2044- # may contain additional garbage
2045- assert string (a , 8 ).startswith (u + 'ABC' )
2046- except ValueError : # garbage contains values > 0x10FFFF
2047- assert sizeof (BWChar ) == 4
20482017
20492018def test_string_typeerror ():
20502019 BShort = new_primitive_type ("short" )
@@ -2485,11 +2454,7 @@ def test_buffer():
24852454 assert repr (buf ).startswith ('<_cffi_backend.buffer object at 0x' )
24862455 assert bytes (buf ) == b"hi there\x00 "
24872456 assert type (buf ) is buffer
2488- if sys .version_info < (3 ,):
2489- assert str (buf ) == "hi there\x00 "
2490- assert unicode (buf ) == u + "hi there\x00 "
2491- else :
2492- assert str (buf ) == repr (buf )
2457+ assert str (buf ) == repr (buf )
24932458 # --mb_length--
24942459 assert len (buf ) == len (b"hi there\x00 " )
24952460 # --mb_item--
@@ -3015,12 +2980,11 @@ def test_string_assignment_to_byte_array():
30152980 assert list (p ) == [ord ("X" ), ord ("Y" ), ord ("Z" ), 0 , 0 ]
30162981
30172982# XXX hack
3018- if sys .version_info >= (3 ,):
3019- try :
3020- import posix
3021- posix .fdopen = open
3022- except ImportError :
3023- pass # win32
2983+ try :
2984+ import posix
2985+ posix .fdopen = open
2986+ except ImportError :
2987+ pass # win32
30242988
30252989@pytest .mark .skipif (
30262990 is_ios ,
@@ -3107,7 +3071,7 @@ def test_FILE_object():
31073071 res = fputs (b"hello\n " , fw1p )
31083072 assert res >= 0
31093073 res = fileno (fw1p )
3110- assert ( res == fdw ) == ( sys . version_info < ( 3 ,))
3074+ assert res != fdw
31113075 fw1 .close ()
31123076 #
31133077 data = posix .read (fdr , 256 )
@@ -3838,16 +3802,14 @@ def test_from_buffer_more_cases():
38383802 def check1 (bufobj , expected ):
38393803 c = from_buffer (BCharA , bufobj )
38403804 assert typeof (c ) is BCharA
3841- if sys .version_info >= (3 ,):
3842- expected = [bytes (c , "ascii" ) for c in expected ]
3805+ expected = [bytes (c , "ascii" ) for c in expected ]
38433806 assert list (c ) == list (expected )
38443807 #
38453808 def check (methods , expected , expected_for_memoryview = None ):
3846- if sys .version_info >= (3 ,):
3847- if methods <= 7 :
3848- return
3849- if expected_for_memoryview is not None :
3850- expected = expected_for_memoryview
3809+ if methods <= 7 :
3810+ return
3811+ if expected_for_memoryview is not None :
3812+ expected = expected_for_memoryview
38513813 class X :
38523814 pass
38533815 _testbuff (X , methods )
0 commit comments