Skip to content

Commit e6fea22

Browse files
QuLogicedschofield
authored andcommitted
Fix object.__format__ test on Python 3.4.
The test checks if this is deprecated, but in 3.4, the behaviour was made an error.
1 parent 76e64a6 commit e6fea22

File tree

2 files changed

+30
-12
lines changed

2 files changed

+30
-12
lines changed

future/tests/test_builtins.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1726,9 +1726,18 @@ def __format__(self, format_spec):
17261726
# Issue #7994: object.__format__ with a non-empty format string is
17271727
# deprecated
17281728
def test_deprecated_format_string(obj, fmt_str, should_raise_warning):
1729-
with warnings.catch_warnings(record=True) as w:
1730-
warnings.simplefilter("always", DeprecationWarning)
1731-
format(obj, fmt_str)
1729+
if sys.version_info[0] == 3 and sys.version_info[1] >= 4:
1730+
if should_raise_warning:
1731+
self.assertRaises(TypeError, format, obj, fmt_str)
1732+
else:
1733+
try:
1734+
format(obj, fmt_str)
1735+
except TypeError:
1736+
self.fail('object.__format__ raised TypeError unexpectedly')
1737+
else:
1738+
with warnings.catch_warnings(record=True) as w:
1739+
warnings.simplefilter("always", DeprecationWarning)
1740+
format(obj, fmt_str)
17321741
# Was:
17331742
# if should_raise_warning:
17341743
# self.assertEqual(len(w), 1)

past/tests/test_builtins.py

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1662,16 +1662,25 @@ def __format__(self, format_spec):
16621662
# Issue #7994: object.__format__ with a non-empty format string is
16631663
# pending deprecated
16641664
def test_deprecated_format_string(obj, fmt_str, should_raise_warning):
1665-
with warnings.catch_warnings(record=True) as w:
1666-
warnings.simplefilter("always", PendingDeprecationWarning)
1667-
format(obj, fmt_str)
1668-
if should_raise_warning:
1669-
self.assertEqual(len(w), 1)
1670-
self.assertIsInstance(w[0].message, PendingDeprecationWarning)
1671-
self.assertIn('object.__format__ with a non-empty format '
1672-
'string', str(w[0].message))
1665+
if sys.version_info[0] == 3 and sys.version_info[1] >= 4:
1666+
if should_raise_warning:
1667+
self.assertRaises(TypeError, format, obj, fmt_str)
1668+
else:
1669+
try:
1670+
format(obj, fmt_str)
1671+
except TypeError:
1672+
self.fail('object.__format__ raised TypeError unexpectedly')
16731673
else:
1674-
self.assertEqual(len(w), 0)
1674+
with warnings.catch_warnings(record=True) as w:
1675+
warnings.simplefilter("always", PendingDeprecationWarning)
1676+
format(obj, fmt_str)
1677+
if should_raise_warning:
1678+
self.assertEqual(len(w), 1)
1679+
self.assertIsInstance(w[0].message, PendingDeprecationWarning)
1680+
self.assertIn('object.__format__ with a non-empty format '
1681+
'string', str(w[0].message))
1682+
else:
1683+
self.assertEqual(len(w), 0)
16751684

16761685
fmt_strs = ['', 's', u'', u's']
16771686

0 commit comments

Comments
 (0)