@@ -70,31 +70,17 @@ def _capture_unraisable_hook(ur_args):
7070assert __version__ == "2.2.0.dev0" , ("This test_c.py file is for testing a version"
7171 " of cffi that differs from the one that we"
7272 " get from 'import _cffi_backend'" )
73- if sys .version_info < (3 ,):
74- type_or_class = "type"
75- mandatory_b_prefix = ''
76- mandatory_u_prefix = 'u'
77- bytechr = chr
78- bitem2bchr = lambda x : x
79- class U :
80- def __add__ (self , other ):
81- return eval ('u' + repr (other ).replace (r'\\u' , r'\u' )
82- .replace (r'\\U' , r'\U' ))
83- u = U ()
84- str2bytes = str
85- strict_compare = False
86- else :
87- type_or_class = "class"
88- long = int
89- unicode = str
90- unichr = chr
91- mandatory_b_prefix = 'b'
92- mandatory_u_prefix = ''
93- bytechr = lambda n : bytes ([n ])
94- bitem2bchr = bytechr
95- u = ""
96- str2bytes = lambda s : bytes (s , "ascii" )
97- strict_compare = True
73+ type_or_class = "class"
74+ long = int
75+ unicode = str
76+ unichr = chr
77+ mandatory_b_prefix = 'b'
78+ mandatory_u_prefix = ''
79+ bytechr = lambda n : bytes ([n ])
80+ bitem2bchr = bytechr
81+ u = ""
82+ str2bytes = lambda s : bytes (s , "ascii" )
83+ strict_compare = True
9884
9985def size_of_int ():
10086 BInt = new_primitive_type ("int" )
@@ -1700,10 +1686,6 @@ def test_enum_in_struct():
17001686 "expected integer, got NoneType object" in msg ) # newer PyPys
17011687 with pytest .raises (TypeError ):
17021688 p .a1 = "def"
1703- if sys .version_info < (3 ,):
1704- BEnum2 = new_enum_type (unicode ("foo" ), (unicode ('abc' ),), (5 ,), BInt )
1705- assert string (cast (BEnum2 , 5 )) == 'abc'
1706- assert type (string (cast (BEnum2 , 5 ))) is str
17071689
17081690def test_enum_overflow ():
17091691 max_uint = 2 ** (size_of_int ()* 8 ) - 1
@@ -2498,11 +2480,7 @@ def test_buffer():
24982480 assert repr (buf ).startswith ('<_cffi_backend.buffer object at 0x' )
24992481 assert bytes (buf ) == b"hi there\x00 "
25002482 assert type (buf ) is buffer
2501- if sys .version_info < (3 ,):
2502- assert str (buf ) == "hi there\x00 "
2503- assert unicode (buf ) == u + "hi there\x00 "
2504- else :
2505- assert str (buf ) == repr (buf )
2483+ assert str (buf ) == repr (buf )
25062484 # --mb_length--
25072485 assert len (buf ) == len (b"hi there\x00 " )
25082486 # --mb_item--
@@ -3028,12 +3006,11 @@ def test_string_assignment_to_byte_array():
30283006 assert list (p ) == [ord ("X" ), ord ("Y" ), ord ("Z" ), 0 , 0 ]
30293007
30303008# XXX hack
3031- if sys .version_info >= (3 ,):
3032- try :
3033- import posix
3034- posix .fdopen = open
3035- except ImportError :
3036- pass # win32
3009+ try :
3010+ import posix
3011+ posix .fdopen = open
3012+ except ImportError :
3013+ pass # win32
30373014
30383015def test_FILE ():
30393016 if sys .platform == "win32" :
@@ -3846,16 +3823,14 @@ def test_from_buffer_more_cases():
38463823 def check1 (bufobj , expected ):
38473824 c = from_buffer (BCharA , bufobj )
38483825 assert typeof (c ) is BCharA
3849- if sys .version_info >= (3 ,):
3850- expected = [bytes (c , "ascii" ) for c in expected ]
3826+ expected = [bytes (c , "ascii" ) for c in expected ]
38513827 assert list (c ) == list (expected )
38523828 #
38533829 def check (methods , expected , expected_for_memoryview = None ):
3854- if sys .version_info >= (3 ,):
3855- if methods <= 7 :
3856- return
3857- if expected_for_memoryview is not None :
3858- expected = expected_for_memoryview
3830+ if methods <= 7 :
3831+ return
3832+ if expected_for_memoryview is not None :
3833+ expected = expected_for_memoryview
38593834 class X :
38603835 pass
38613836 _testbuff (X , methods )
0 commit comments