Skip to content

Commit

Permalink
Merge pull request #619 from hrnciar/python3.12
Browse files Browse the repository at this point in the history
Adjust tests to the changes in Python 3.12
  • Loading branch information
edschofield authored Feb 21, 2024
2 parents 35ba085 + d7dc44e commit bcced95
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
16 changes: 12 additions & 4 deletions tests/test_future/test_backports.py
Original file line number Diff line number Diff line change
Expand Up @@ -599,17 +599,25 @@ def test_yaml_linkage(self):

def test_repr(self):
od = OrderedDict([('c', 1), ('b', 2), ('a', 3), ('d', 4), ('e', 5), ('f', 6)])
self.assertEqual(repr(od),
"OrderedDict([('c', 1), ('b', 2), ('a', 3), ('d', 4), ('e', 5), ('f', 6)])")
if sys.version_info[0] == 3 and sys.version_info[1] >= 12:
self.assertEqual(repr(od),
"OrderedDict({'c': 1, 'b': 2, 'a': 3, 'd': 4, 'e': 5, 'f': 6})")
else:
self.assertEqual(repr(od),
"OrderedDict([('c', 1), ('b', 2), ('a', 3), ('d', 4), ('e', 5), ('f', 6)])")
self.assertEqual(eval(repr(od)), od)
self.assertEqual(repr(OrderedDict()), "OrderedDict()")

def test_repr_recursive(self):
# See issue #9826
od = OrderedDict.fromkeys('abc')
od['x'] = od
self.assertEqual(repr(od),
"OrderedDict([('a', None), ('b', None), ('c', None), ('x', ...)])")
if sys.version_info[0] == 3 and sys.version_info[1] >= 12:
self.assertEqual(repr(od),
"OrderedDict({'a': None, 'b': None, 'c': None, 'x': ...})")
else:
self.assertEqual(repr(od),
"OrderedDict([('a', None), ('b', None), ('c', None), ('x', ...)])")

def test_setdefault(self):
pairs = [('c', 1), ('b', 2), ('a', 3), ('d', 4), ('e', 5), ('f', 6)]
Expand Down
4 changes: 2 additions & 2 deletions tests/test_future/test_builtins.py
Original file line number Diff line number Diff line change
Expand Up @@ -523,8 +523,8 @@ def test_compile(self):
self.assertRaises(TypeError, compile)
self.assertRaises(ValueError, compile, 'print(42)\n', '<string>', 'badmode')
self.assertRaises(ValueError, compile, 'print(42)\n', '<string>', 'single', 0xff)
# Raises TypeError in Python < v3.5, ValueError in v3.5:
self.assertRaises((TypeError, ValueError), compile, chr(0), 'f', 'exec')
# Raises TypeError in Python < v3.5, ValueError in v3.5, SyntaxError in >= 3.12:
self.assertRaises((TypeError, ValueError, SyntaxError), compile, chr(0), 'f', 'exec')
self.assertRaises(TypeError, compile, 'pass', '?', 'exec',
mode='eval', source='0', filename='tmp')
compile('print("\xe5")\n', '', 'exec')
Expand Down

0 comments on commit bcced95

Please sign in to comment.