summaryrefslogtreecommitdiff
path: root/tests/run/test_fstring.pyx
diff options
context:
space:
mode:
Diffstat (limited to 'tests/run/test_fstring.pyx')
-rw-r--r--tests/run/test_fstring.pyx39
1 files changed, 10 insertions, 29 deletions
diff --git a/tests/run/test_fstring.pyx b/tests/run/test_fstring.pyx
index 309696c28..450f39f3e 100644
--- a/tests/run/test_fstring.pyx
+++ b/tests/run/test_fstring.pyx
@@ -10,7 +10,6 @@ import contextlib
import sys
IS_PY2 = sys.version_info[0] < 3
-IS_PY26 = sys.version_info[:2] < (2, 7)
from Cython.Build.Inline import cython_inline
from Cython.TestUtils import CythonTest
@@ -63,23 +62,8 @@ class TestCase(CythonTest):
first = stripped_first.decode('unicode_escape')
super(TestCase, self).assertEqual(first, second, msg)
- if IS_PY26:
- @contextlib.contextmanager
- def assertRaises(self, exc):
- try:
- yield
- except exc:
- pass
- else:
- assert False, "exception '%s' not raised" % exc
-
- def assertIn(self, value, collection):
- self.assertTrue(value in collection)
-
def test__format__lookup(self):
- if IS_PY26:
- return
- elif IS_PY2:
+ if IS_PY2:
raise unittest.SkipTest("Py3-only")
# Make sure __format__ is looked up on the type, not the instance.
@@ -288,12 +272,11 @@ f'{a * x()}'"""
width = 10
precision = 4
value = decimal.Decimal('12.34567')
- if not IS_PY26:
- self.assertEqual(f'result: {value:{width}.{precision}}', 'result: 12.35')
- self.assertEqual(f'result: {value:{width!r}.{precision}}', 'result: 12.35')
- self.assertEqual(f'result: {value:{width:0}.{precision:1}}', 'result: 12.35')
- self.assertEqual(f'result: {value:{1}{0:0}.{precision:1}}', 'result: 12.35')
- self.assertEqual(f'result: {value:{ 1}{ 0:0}.{ precision:1}}', 'result: 12.35')
+ self.assertEqual(f'result: {value:{width}.{precision}}', 'result: 12.35')
+ self.assertEqual(f'result: {value:{width!r}.{precision}}', 'result: 12.35')
+ self.assertEqual(f'result: {value:{width:0}.{precision:1}}', 'result: 12.35')
+ self.assertEqual(f'result: {value:{1}{0:0}.{precision:1}}', 'result: 12.35')
+ self.assertEqual(f'result: {value:{ 1}{ 0:0}.{ precision:1}}', 'result: 12.35')
self.assertEqual(f'{10:#{1}0x}', ' 0xa')
self.assertEqual(f'{10:{"#"}1{0}{"x"}}', ' 0xa')
self.assertEqual(f'{-10:-{"#"}1{0}x}', ' -0xa')
@@ -312,8 +295,7 @@ f'{a * x()}'"""
])
# CYTHON: The nesting restriction seems rather arbitrary. Ignoring it for now and instead test that it works.
- if not IS_PY26:
- self.assertEqual(f'result: {value:{width:{0}}.{precision:1}}', 'result: 12.35')
+ self.assertEqual(f'result: {value:{width:{0}}.{precision:1}}', 'result: 12.35')
#self.assertAllRaise(SyntaxError, "f-string: expressions nested too deeply",
# [# Can't nest format specifiers.
# "f'result: {value:{width:{0}}.{precision:1}}'",
@@ -678,10 +660,9 @@ f'{a * x()}'"""
def test_conversions(self):
self.assertEqual(f'{3.14:10.10}', ' 3.14')
- if not IS_PY26:
- self.assertEqual(f'{3.14!s:10.10}', '3.14 ')
- self.assertEqual(f'{3.14!r:10.10}', '3.14 ')
- self.assertEqual(f'{3.14!a:10.10}', '3.14 ')
+ self.assertEqual(f'{3.14!s:10.10}', '3.14 ')
+ self.assertEqual(f'{3.14!r:10.10}', '3.14 ')
+ self.assertEqual(f'{3.14!a:10.10}', '3.14 ')
self.assertEqual(f'{"a"}', 'a')
self.assertEqual(f'{"a"!r}', "'a'")