Skip to content

Commit 2f4bfee

Browse files
committed
Mark known-failing tests of past on Py3 as @expectedFailurePY3
1 parent 3816817 commit 2f4bfee

File tree

4 files changed

+81
-12
lines changed

4 files changed

+81
-12
lines changed

future/tests/base.py

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import unittest2 as unittest
1111
from textwrap import dedent
1212

13-
from future.utils import bind_method
13+
from future.utils import bind_method, PY26, PY3, PY2
1414

1515

1616
# For Python 2.6 compatibility: see http://stackoverflow.com/questions/4814970/
@@ -300,7 +300,46 @@ def _run_test_script(self, filename='mytestscript.py',
300300

301301

302302
# Decorator to skip some tests on Python 2.6 ...
303-
skip26 = unittest.skipIf(sys.version_info[:2] == (2, 6), "this test is known to fail on Py2.6")
303+
skip26 = unittest.skipIf(PY26, "this test is known to fail on Py2.6")
304+
305+
306+
def expectedFailurePY3(func):
307+
if not PY3:
308+
return func
309+
@functools.wraps(func)
310+
def wrapper(*args, **kwargs):
311+
try:
312+
func(*args, **kwargs)
313+
except Exception:
314+
raise _ExpectedFailure(sys.exc_info())
315+
raise _UnexpectedSuccess
316+
return wrapper
317+
318+
319+
def expectedFailurePY26(func):
320+
if not PY26:
321+
return func
322+
@functools.wraps(func)
323+
def wrapper(*args, **kwargs):
324+
try:
325+
func(*args, **kwargs)
326+
except Exception:
327+
raise _ExpectedFailure(sys.exc_info())
328+
raise _UnexpectedSuccess
329+
return wrapper
330+
331+
332+
def expectedFailurePY2(func):
333+
if not PY2:
334+
return func
335+
@functools.wraps(func)
336+
def wrapper(*args, **kwargs):
337+
try:
338+
func(*args, **kwargs)
339+
except Exception:
340+
raise _ExpectedFailure(sys.exc_info())
341+
raise _UnexpectedSuccess
342+
return wrapper
304343

305344

306345
# Renamed in Py3.3:

future/tests/test_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ def test_isbytes(self):
104104
self.assertFalse(isbytes(self.s))
105105
self.assertFalse(isbytes(self.s2))
106106

107-
@skip26
107+
@unittest.skipIf(PY3, 'test_raise_ currently fails on Py3')
108108
def test_raise_(self):
109109
"""
110110
The with_value() test currently fails on Py3

past/tests/test_builtins.py

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
# import UserDict
2121
from os import unlink
2222
from operator import neg
23-
from future.tests.base import unittest
23+
from future.tests.base import unittest, expectedFailurePY3
2424

2525
# count the number of test runs.
2626
# used to skip running test_execfile() multiple times
@@ -169,6 +169,7 @@ def test_neg(self):
169169
self.assertTrue(isinstance(x, int))
170170
self.assertEqual(-x, sys.maxsize+1)
171171

172+
@expectedFailurePY3
172173
def test_apply(self):
173174
def f0(*args):
174175
self.assertEqual(args, ())
@@ -195,6 +196,11 @@ def f3(a1, a2, a3):
195196
self.assertRaises(TypeError, apply, id, 42)
196197
self.assertRaises(TypeError, apply, id, (42,), 42)
197198

199+
def test_basestring(self):
200+
assert isinstance('hello', basestring)
201+
assert isinstance(b'hello', basestring)
202+
203+
@expectedFailurePY3
198204
def test_callable(self):
199205
self.assertTrue(callable(len))
200206
self.assertFalse(callable("a"))
@@ -236,6 +242,7 @@ class N3(N2): pass
236242
n3 = N3()
237243
self.assertTrue(callable(n3))
238244

245+
@expectedFailurePY3
239246
def test_chr(self):
240247
self.assertEqual(chr(32), ' ')
241248
self.assertEqual(chr(65), 'A')
@@ -244,6 +251,7 @@ def test_chr(self):
244251
self.assertRaises(ValueError, chr, 256)
245252
self.assertRaises(TypeError, chr)
246253

254+
@expectedFailurePY3
247255
def test_cmp(self):
248256
self.assertEqual(cmp(-1, 1), -1)
249257
self.assertEqual(cmp(1, -1), 1)
@@ -261,6 +269,7 @@ def test_cmp(self):
261269
a.pop(); b.pop(); c.pop()
262270
self.assertRaises(TypeError, cmp)
263271

272+
@expectedFailurePY3
264273
def test_coerce(self):
265274
self.assertTrue(not fcmp(coerce(1, 1.1), (1.0, 1.1)))
266275
self.assertEqual(coerce(1, 1), (1, 1))
@@ -272,6 +281,7 @@ def __coerce__(self, other):
272281
self.assertRaises(ValueError, coerce, 42, BadNumber())
273282
self.assertRaises(OverflowError, coerce, 0.5, int("12345" * 1000))
274283

284+
@expectedFailurePY3
275285
def test_compile(self):
276286
compile('print(1)\n', '', 'exec')
277287
bom = '\xef\xbb\xbf'
@@ -385,6 +395,7 @@ def test_divmod(self):
385395

386396
self.assertRaises(TypeError, divmod)
387397

398+
@expectedFailurePY3
388399
def test_eval(self):
389400
self.assertEqual(eval('1+1'), 2)
390401
self.assertEqual(eval(' 1+1\n'), 2)
@@ -411,6 +422,7 @@ def test_eval(self):
411422
self.assertRaises(TypeError, eval)
412423
self.assertRaises(TypeError, eval, ())
413424

425+
@expectedFailurePY3
414426
def test_general_eval(self):
415427
# Tests that general mappings can be used for the locals argument
416428

@@ -535,6 +547,7 @@ def __setitem__(self, key, value):
535547
self.assertRaises(IOError, execfile, os.curdir)
536548
self.assertRaises(IOError, execfile, "I_dont_exist")
537549

550+
@expectedFailurePY3
538551
def test_filter(self):
539552
self.assertEqual(filter(lambda c: 'a' <= c <= 'z', 'Hello World'), 'elloorld')
540553
self.assertEqual(filter(None, [1, 'hello', [], [3], '', None, 9, 0]), [1, 'hello', [3], 9])
@@ -610,6 +623,7 @@ def __getitem__(self, index):
610623
unicode("345")
611624
)
612625

626+
@expectedFailurePY3
613627
def test_filter_subclasses(self):
614628
# test that filter() never returns tuple, str or unicode subclasses
615629
# and that the result always goes through __getitem__
@@ -646,6 +660,7 @@ def __getitem__(self, index):
646660
self.assertEqual(outp, exp)
647661
self.assertTrue(not isinstance(outp, cls))
648662

663+
@expectedFailurePY3
649664
def test_getattr(self):
650665
import sys
651666
self.assertTrue(getattr(sys, 'stdout') is sys.stdout)
@@ -655,6 +670,7 @@ def test_getattr(self):
655670
if True: # Was: have_unicode:
656671
self.assertRaises(UnicodeError, getattr, sys, unichr(sys.maxunicode))
657672

673+
@expectedFailurePY3
658674
def test_hasattr(self):
659675
import sys
660676
self.assertTrue(hasattr(sys, 'stdout'))
@@ -719,6 +735,7 @@ def test_id(self):
719735

720736
# test_int(): see test_int.py for int() tests.
721737

738+
@expectedFailurePY3
722739
def test_intern(self):
723740
self.assertRaises(TypeError, intern)
724741
# This fails if the test is run twice with a constant string,
@@ -745,6 +762,7 @@ def __hash__(self):
745762
setattr(s, s, s)
746763
self.assertEqual(getattr(s, s), s)
747764

765+
@expectedFailurePY3
748766
def test_iter(self):
749767
self.assertRaises(TypeError, iter)
750768
self.assertRaises(TypeError, iter, 42, 42)
@@ -792,6 +810,7 @@ class E:
792810
self.assertRaises(TypeError, issubclass, E, 'foo')
793811
self.assertRaises(TypeError, issubclass)
794812

813+
@expectedFailurePY3
795814
def test_len(self):
796815
self.assertEqual(len('123'), 3)
797816
self.assertEqual(len(()), 0)
@@ -918,6 +937,7 @@ def test_max(self):
918937
self.assertEqual(max(data, key=f),
919938
sorted(reversed(data), key=f)[-1])
920939

940+
@expectedFailurePY3
921941
def test_min(self):
922942
self.assertEqual(min('123123'), '1')
923943
self.assertEqual(min(1, 2, 3), 1)
@@ -964,6 +984,7 @@ def __cmp__(self, other):
964984
self.assertEqual(min(data, key=f),
965985
sorted(data, key=f)[0])
966986

987+
@expectedFailurePY3
967988
def test_next(self):
968989
it = iter(range(2))
969990
self.assertEqual(next(it), 0)
@@ -991,6 +1012,7 @@ def gen():
9911012
self.assertRaises(StopIteration, next, it)
9921013
self.assertEqual(next(it, 42), 42)
9931014

1015+
@expectedFailurePY3
9941016
def test_oct(self):
9951017
self.assertEqual(oct(100), '0144')
9961018
# self.assertEqual(oct(100L), '0144L')
@@ -1027,6 +1049,7 @@ def test_open(self):
10271049
fp.close()
10281050
unlink(TESTFN)
10291051

1052+
@expectedFailurePY3
10301053
def test_ord(self):
10311054
self.assertEqual(ord(' '), 32)
10321055
self.assertEqual(ord('A'), 65)
@@ -1037,6 +1060,7 @@ def test_ord(self):
10371060
if True: # Was: if have_unicode:
10381061
self.assertRaises(TypeError, ord, unicode("12"))
10391062

1063+
@expectedFailurePY3
10401064
def test_pow(self):
10411065
self.assertEqual(pow(0,0), 1)
10421066
self.assertEqual(pow(0,1), 0)
@@ -1102,6 +1126,7 @@ def test_pow(self):
11021126

11031127
self.assertRaises(TypeError, pow)
11041128

1129+
@expectedFailurePY3
11051130
def test_range(self):
11061131
self.assertEqual(range(3), [0, 1, 2])
11071132
self.assertEqual(range(1, 5), [1, 2, 3, 4])
@@ -1208,8 +1233,7 @@ def __int__(self):
12081233
self.assertRaises(TypeError, range, 0.0, 0.0, 1)
12091234
self.assertRaises(TypeError, range, 0.0, 0.0, 1.0)
12101235

1211-
1212-
1236+
@expectedFailurePY3
12131237
def test_input_and_raw_input(self):
12141238
self.write_testfile()
12151239
fp = open(TESTFN, 'r')
@@ -1324,6 +1348,7 @@ def test_repr(self):
13241348
a[0] = a
13251349
self.assertEqual(repr(a), '{0: {...}}')
13261350

1351+
@expectedFailurePY3
13271352
def test_round(self):
13281353
self.assertEqual(round(0.0), 0.0)
13291354
self.assertEqual(type(round(0.0)), float) # Will be int in 3.0.
@@ -1454,6 +1479,7 @@ def test_type(self):
14541479
self.assertEqual(type(''), type('123'))
14551480
self.assertNotEqual(type(''), type(()))
14561481

1482+
@expectedFailurePY3
14571483
def test_unichr(self):
14581484
if True: # Was: if have_unicode:
14591485
self.assertEqual(unichr(32), unicode(' '))
@@ -1538,6 +1564,7 @@ def __getitem__(self, i):
15381564
return i
15391565
self.assertRaises(ValueError, zip, BadSeq(), BadSeq())
15401566

1567+
@expectedFailurePY3
15411568
def test_format(self):
15421569
# Test the basic machinery of the format() builtin. Don't test
15431570
# the specifics of the various formatters
@@ -1677,13 +1704,15 @@ def test_bin(self):
16771704
self.assertEqual(bin(-(2**65)), '-0b1' + '0' * 65)
16781705
self.assertEqual(bin(-(2**65-1)), '-0b' + '1' * 65)
16791706

1707+
@expectedFailurePY3
16801708
def test_bytearray_translate(self):
16811709
x = bytearray(b"abc")
16821710
self.assertRaises(ValueError, x.translate, "1", 1)
16831711
self.assertRaises(TypeError, x.translate, "1"*256, 1)
16841712

16851713
class TestSorted(unittest.TestCase):
16861714

1715+
@expectedFailurePY3
16871716
def test_basic(self):
16881717
data = range(100)
16891718
copy = data[:]

past/tests/test_translation.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
from past.builtins import basestring, str as oldstr, unicode
1818

1919
from past.translation import install_hooks, remove_hooks, common_substring
20-
from future.tests.base import unittest, CodeHandler, skip26
20+
from future.tests.base import (unittest, CodeHandler, skip26,
21+
expectedFailurePY3, expectedFailurePY26)
2122

2223

2324
class TestTranslate(unittest.TestCase):
@@ -82,16 +83,16 @@ def test_exec_statement(self):
8283
module = self.write_and_import(code, 'execer')
8384
self.assertEqual(module.x, 7)
8485

85-
@skip26
86+
@expectedFailurePY3
8687
def test_div(self):
8788
code = """
8889
x = 3 / 2
8990
"""
9091
module = self.write_and_import(code, 'div')
9192
self.assertEqual(module.x, 1)
9293

93-
@skip26
94-
@unittest.skipIf(utils.PY3, 'test_stdlib currently fails on Py3')
94+
@expectedFailurePY26
95+
@expectedFailurePY3
9596
def test_stdlib(self):
9697
"""
9798
Have the old stdlib names been mapped onto the new ones?
@@ -152,8 +153,8 @@ def double(x):
152153
self.assertEqual(module.d, [0, 4, 8, 12, 16])
153154
self.assertTrue(module.e)
154155

155-
@skip26
156-
# @unittest.expectedFailure
156+
@expectedFailurePY26
157+
@expectedFailurePY3
157158
def test_import_builtin_types(self):
158159
code = """
159160
s1 = 'abcd'

0 commit comments

Comments
 (0)