Skip to content

Commit 6e4c2fe

Browse files
authored
Merge pull request RustPython#4597 from youknowone/expected-failure-if
Add unittset.expectedFailureIf for RustPython
2 parents a7c9856 + 367a948 commit 6e4c2fe

33 files changed

+106
-356
lines changed

Lib/test/test_charmapcodec.py

+3-10
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ def codec_search_function(encoding):
2626
codecname = 'testcodec'
2727

2828
class CharmapCodecTest(unittest.TestCase):
29+
@unittest.expectedFailureIfWindows("TODO: RUSTPYTHON")
2930
def test_constructorx(self):
3031
self.assertEqual(str(b'abc', codecname), 'abc')
3132
self.assertEqual(str(b'xdef', codecname), 'abcdef')
@@ -42,24 +43,16 @@ def test_encodex(self):
4243
self.assertEqual('dxf'.encode(codecname), b'dabcf')
4344
self.assertEqual('dxfx'.encode(codecname), b'dabcfabc')
4445

46+
@unittest.expectedFailureIfWindows("TODO: RUSTPYTHON")
4547
def test_constructory(self):
4648
self.assertEqual(str(b'ydef', codecname), 'def')
4749
self.assertEqual(str(b'defy', codecname), 'def')
4850
self.assertEqual(str(b'dyf', codecname), 'df')
4951
self.assertEqual(str(b'dyfy', codecname), 'df')
5052

53+
@unittest.expectedFailureIfWindows("TODO: RUSTPYTHON")
5154
def test_maptoundefined(self):
5255
self.assertRaises(UnicodeError, str, b'abc\001', codecname)
5356

54-
# TODO: RUSTPYTHON
55-
import sys
56-
if sys.platform == "win32":
57-
# TODO: RUSTPYTHON
58-
test_constructorx = unittest.expectedFailure(test_constructorx)
59-
# TODO: RUSTPYTHON
60-
test_constructory = unittest.expectedFailure(test_constructory)
61-
# TODO: RUSTPYTHON
62-
test_maptoundefined = unittest.expectedFailure(test_maptoundefined)
63-
6457
if __name__ == "__main__":
6558
unittest.main()

Lib/test/test_codecs.py

+14-57
Original file line numberDiff line numberDiff line change
@@ -1793,6 +1793,7 @@ def test_decode(self):
17931793
self.assertEqual(codecs.decode(b'[\xff]', 'ascii', errors='ignore'),
17941794
'[]')
17951795

1796+
@unittest.expectedFailureIfWindows("TODO: RUSTPYTHON")
17961797
def test_encode(self):
17971798
self.assertEqual(codecs.encode('\xe4\xf6\xfc', 'latin-1'),
17981799
b'\xe4\xf6\xfc')
@@ -1807,14 +1808,11 @@ def test_encode(self):
18071808
self.assertEqual(codecs.encode('[\xff]', 'ascii', errors='ignore'),
18081809
b'[]')
18091810

1810-
# TODO: RUSTPYTHON
1811-
if sys.platform == "win32":
1812-
test_encode = unittest.expectedFailure(test_encode)
1813-
18141811
def test_register(self):
18151812
self.assertRaises(TypeError, codecs.register)
18161813
self.assertRaises(TypeError, codecs.register, 42)
18171814

1815+
@unittest.expectedFailureIfWindows("TODO: RUSTPYTHON; AttributeError: module '_winapi' has no attribute 'GetACP'")
18181816
def test_unregister(self):
18191817
name = "nonexistent_codec_name"
18201818
search_function = mock.Mock()
@@ -1827,51 +1825,32 @@ def test_unregister(self):
18271825
self.assertRaises(LookupError, codecs.lookup, name)
18281826
search_function.assert_not_called()
18291827

1830-
# TODO: RUSTPYTHON, AttributeError: module '_winapi' has no attribute 'GetACP'
1831-
if sys.platform == "win32":
1832-
test_unregister = unittest.expectedFailure(test_unregister)
1833-
1828+
@unittest.expectedFailureIfWindows("TODO: RUSTPYTHON")
18341829
def test_lookup(self):
18351830
self.assertRaises(TypeError, codecs.lookup)
18361831
self.assertRaises(LookupError, codecs.lookup, "__spam__")
18371832
self.assertRaises(LookupError, codecs.lookup, " ")
18381833

1839-
# TODO: RUSTPYTHON
1840-
if sys.platform == "win32":
1841-
test_lookup = unittest.expectedFailure(test_lookup)
1842-
1834+
@unittest.expectedFailureIfWindows("TODO: RUSTPYTHON")
18431835
def test_getencoder(self):
18441836
self.assertRaises(TypeError, codecs.getencoder)
18451837
self.assertRaises(LookupError, codecs.getencoder, "__spam__")
18461838

1847-
# TODO: RUSTPYTHON
1848-
if sys.platform == "win32":
1849-
test_getencoder = unittest.expectedFailure(test_getencoder)
1850-
1839+
@unittest.expectedFailureIfWindows("TODO: RUSTPYTHON")
18511840
def test_getdecoder(self):
18521841
self.assertRaises(TypeError, codecs.getdecoder)
18531842
self.assertRaises(LookupError, codecs.getdecoder, "__spam__")
18541843

1855-
# TODO: RUSTPYTHON
1856-
if sys.platform == "win32":
1857-
test_getdecoder = unittest.expectedFailure(test_getdecoder)
1858-
1844+
@unittest.expectedFailureIfWindows("TODO: RUSTPYTHON")
18591845
def test_getreader(self):
18601846
self.assertRaises(TypeError, codecs.getreader)
18611847
self.assertRaises(LookupError, codecs.getreader, "__spam__")
18621848

1863-
# TODO: RUSTPYTHON
1864-
if sys.platform == "win32":
1865-
test_getreader = unittest.expectedFailure(test_getreader)
1866-
1849+
@unittest.expectedFailureIfWindows("TODO: RUSTPYTHON")
18671850
def test_getwriter(self):
18681851
self.assertRaises(TypeError, codecs.getwriter)
18691852
self.assertRaises(LookupError, codecs.getwriter, "__spam__")
18701853

1871-
# TODO: RUSTPYTHON
1872-
if sys.platform == "win32":
1873-
test_getwriter = unittest.expectedFailure(test_getwriter)
1874-
18751854
def test_lookup_issue1813(self):
18761855
# Issue #1813: under Turkish locales, lookup of some codecs failed
18771856
# because 'I' is lowercased as "ı" (dotless i)
@@ -1926,6 +1905,7 @@ def test_undefined(self):
19261905
self.assertRaises(UnicodeError,
19271906
codecs.decode, b'abc', 'undefined', errors)
19281907

1908+
@unittest.expectedFailureIfWindows("TODO: RUSTPYTHON")
19291909
def test_file_closes_if_lookup_error_raised(self):
19301910
mock_open = mock.mock_open()
19311911
with mock.patch('builtins.open', mock_open) as file:
@@ -1934,11 +1914,6 @@ def test_file_closes_if_lookup_error_raised(self):
19341914

19351915
file().close.assert_called()
19361916

1937-
# TODO: RUSTPYTHON
1938-
if sys.platform == "win32":
1939-
test_file_closes_if_lookup_error_raised = unittest.expectedFailure(test_file_closes_if_lookup_error_raised)
1940-
1941-
19421917
class StreamReaderTest(unittest.TestCase):
19431918

19441919
def setUp(self):
@@ -3190,51 +3165,37 @@ def raise_obj(*args, **kwds):
31903165
with self.assertRaisesRegex(RuntimeError, msg):
31913166
codecs.decode(b"bytes input", self.codec_name)
31923167

3168+
@unittest.expectedFailureIfWindows("TODO: RUSTPYTHON")
31933169
def test_init_override_is_not_wrapped(self):
31943170
class CustomInit(RuntimeError):
31953171
def __init__(self):
31963172
pass
31973173
self.check_not_wrapped(CustomInit, "")
31983174

3199-
# TODO: RUSTPYTHON
3200-
if sys.platform == "win32":
3201-
test_init_override_is_not_wrapped = unittest.expectedFailure(test_init_override_is_not_wrapped)
3202-
3175+
@unittest.expectedFailureIfWindows("TODO: RUSTPYTHON")
32033176
def test_new_override_is_not_wrapped(self):
32043177
class CustomNew(RuntimeError):
32053178
def __new__(cls):
32063179
return super().__new__(cls)
32073180
self.check_not_wrapped(CustomNew, "")
32083181

3209-
# TODO: RUSTPYTHON
3210-
if sys.platform == "win32":
3211-
test_new_override_is_not_wrapped = unittest.expectedFailure(test_new_override_is_not_wrapped)
3212-
3182+
@unittest.expectedFailureIfWindows("TODO: RUSTPYTHON")
32133183
def test_instance_attribute_is_not_wrapped(self):
32143184
msg = "This should NOT be wrapped"
32153185
exc = RuntimeError(msg)
32163186
exc.attr = 1
32173187
self.check_not_wrapped(exc, "^{}$".format(msg))
32183188

3219-
# TODO: RUSTPYTHON
3220-
if sys.platform == "win32":
3221-
test_instance_attribute_is_not_wrapped = unittest.expectedFailure(test_instance_attribute_is_not_wrapped)
3222-
3189+
@unittest.expectedFailureIfWindows("TODO: RUSTPYTHON")
32233190
def test_non_str_arg_is_not_wrapped(self):
32243191
self.check_not_wrapped(RuntimeError(1), "1")
32253192

3226-
# TODO: RUSTPYTHON
3227-
if sys.platform == "win32":
3228-
test_non_str_arg_is_not_wrapped = unittest.expectedFailure(test_non_str_arg_is_not_wrapped)
3229-
3193+
@unittest.expectedFailureIfWindows("TODO: RUSTPYTHON")
32303194
def test_multiple_args_is_not_wrapped(self):
32313195
msg_re = r"^\('a', 'b', 'c'\)$"
32323196
self.check_not_wrapped(RuntimeError('a', 'b', 'c'), msg_re)
32333197

3234-
# TODO: RUSTPYTHON
3235-
if sys.platform == "win32":
3236-
test_multiple_args_is_not_wrapped = unittest.expectedFailure(test_multiple_args_is_not_wrapped)
3237-
3198+
@unittest.expectedFailureIfWindows("TODO: RUSTPYTHON")
32383199
# http://bugs.python.org/issue19609
32393200
def test_codec_lookup_failure_not_wrapped(self):
32403201
msg = "^unknown encoding: {}$".format(self.codec_name)
@@ -3248,10 +3209,6 @@ def test_codec_lookup_failure_not_wrapped(self):
32483209
with self.assertRaisesRegex(LookupError, msg):
32493210
codecs.decode(b"bytes input", self.codec_name)
32503211

3251-
# TODO: RUSTPYTHON
3252-
if sys.platform == "win32":
3253-
test_codec_lookup_failure_not_wrapped = unittest.expectedFailure(test_codec_lookup_failure_not_wrapped)
3254-
32553212
# TODO: RUSTPYTHON
32563213
@unittest.expectedFailure
32573214
def test_unflagged_non_text_codec_handling(self):

Lib/test/test_difflib.py

+1-5
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ def test_mdiff_catch_stop_iteration(self):
186186
the end"""
187187

188188
class TestSFpatches(unittest.TestCase):
189-
189+
@unittest.expectedFailureIfWindows("TODO: RUSTPYTHON")
190190
def test_html_diff(self):
191191
# Check SF patch 914575 for generating HTML differences
192192
f1a = ((patch914575_from1 + '123\n'*10)*3)
@@ -244,10 +244,6 @@ def test_html_diff(self):
244244
with open(findfile('test_difflib_expect.html')) as fp:
245245
self.assertEqual(actual, fp.read())
246246

247-
# TODO: RUSTPYTHON
248-
if sys.platform == "win32":
249-
test_html_diff = unittest.expectedFailure(test_html_diff)
250-
251247
def test_recursion_limit(self):
252248
# Check if the problem described in patch #1413711 exists.
253249
limit = sys.getrecursionlimit()

Lib/test/test_exception_hierarchy.py

+1-5
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ def _make_map(s):
8080
return _map
8181
_map = _make_map(_pep_map)
8282

83+
@unittest.expectedFailureIfWindows("TODO: RUSTPYTHON")
8384
def test_errno_mapping(self):
8485
# The OSError constructor maps errnos to subclasses
8586
# A sample test for the basic functionality
@@ -94,11 +95,6 @@ def test_errno_mapping(self):
9495
e = OSError(errcode, "Some message")
9596
self.assertIs(type(e), OSError)
9697

97-
# TODO: RUSTPYTHON
98-
import sys
99-
if sys.platform == 'win32':
100-
test_errno_mapping = unittest.expectedFailure(test_errno_mapping)
101-
10298
def test_try_except(self):
10399
filename = "some_hopefully_non_existing_file"
104100

Lib/test/test_faulthandler.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,7 @@ def test_enable_single_thread(self):
368368
'Segmentation fault',
369369
all_threads=False)
370370

371+
@unittest.expectedFailureIfWindows("TODO: RUSTPYTHON; AttributeError: module 'msvcrt' has no attribute 'GetErrorMode'")
371372
@skip_segfault_on_android
372373
def test_disable(self):
373374
code = """
@@ -383,9 +384,6 @@ def test_disable(self):
383384
"%r is present in %r" % (not_expected, stderr))
384385
self.assertNotEqual(exitcode, 0)
385386

386-
if sys.platform == "win32": # TODO: RUSTPYTHON, AttributeError: module 'msvcrt' has no attribute 'GetErrorMode'
387-
test_disable = unittest.expectedFailure(test_disable)
388-
389387
# TODO: RUSTPYTHON
390388
@unittest.expectedFailure
391389
@skip_segfault_on_android

Lib/test/test_fileio.py

+1-5
Original file line numberDiff line numberDiff line change
@@ -221,9 +221,6 @@ def testMethods(self):
221221
self.assertRaises(ValueError, self.f.writelines, b'')
222222

223223
def testOpendir(self):
224-
# TODO: RUSTPYTHON
225-
if sys.platform == "win32":
226-
testOpendir = unittest.expectedFailure(testOpendir)
227224
# Issue 3703: opening a directory should fill the errno
228225
# Windows always returns "[Errno 13]: Permission denied
229226
# Unix uses fstat and returns "[Errno 21]: Is a directory"
@@ -381,8 +378,7 @@ def testMethods(self):
381378
def testOpenDirFD(self):
382379
super().testOpenDirFD()
383380

384-
# TODO: RUSTPYTHON
385-
@unittest.expectedFailure
381+
@unittest.expectedFailureIf(sys.platform != "win32", "TODO: RUSTPYTHON")
386382
def testOpendir(self):
387383
super().testOpendir()
388384

Lib/test/test_fnmatch.py

+1-5
Original file line numberDiff line numberDiff line change
@@ -71,16 +71,12 @@ def test_fnmatchcase(self):
7171
check('usr/bin', 'usr\\bin', False, fnmatchcase)
7272
check('usr\\bin', 'usr\\bin', True, fnmatchcase)
7373

74+
@unittest.expectedFailureIfWindows("TODO: RUSTPYTHON")
7475
def test_bytes(self):
7576
self.check_match(b'test', b'te*')
7677
self.check_match(b'test\xff', b'te*\xff')
7778
self.check_match(b'foo\nbar', b'foo*')
7879

79-
# TODO: RUSTPYTHON
80-
import sys
81-
if sys.platform == 'win32':
82-
test_bytes = unittest.expectedFailure(test_bytes)
83-
8480
def test_case(self):
8581
ignorecase = os.path.normcase('ABC') == os.path.normcase('abc')
8682
check = self.check_match

Lib/test/test_genericpath.py

+2-8
Original file line numberDiff line numberDiff line change
@@ -242,14 +242,11 @@ def _test_samefile_on_link_func(self, func):
242242
create_file(test_fn2)
243243
self.assertFalse(self.pathmodule.samefile(test_fn1, test_fn2))
244244

245+
@unittest.expectedFailureIfWindows("TODO: RUSTPYTHON; properly implement stat st_dev/st_ino")
245246
@os_helper.skip_unless_symlink
246247
def test_samefile_on_symlink(self):
247248
self._test_samefile_on_link_func(os.symlink)
248249

249-
if sys.platform == 'win32':
250-
# TODO: RUSTPYTHON, properly implement stat st_dev/st_ino
251-
test_samefile_on_symlink = unittest.expectedFailure(test_samefile_on_symlink)
252-
253250
def test_samefile_on_link(self):
254251
try:
255252
self._test_samefile_on_link_func(os.link)
@@ -288,14 +285,11 @@ def _test_samestat_on_link_func(self, func):
288285
self.assertFalse(self.pathmodule.samestat(os.stat(test_fn1),
289286
os.stat(test_fn2)))
290287

288+
@unittest.expectedFailureIfWindows("TODO: RUSTPYTHON; properly implement stat st_dev/st_ino")
291289
@os_helper.skip_unless_symlink
292290
def test_samestat_on_symlink(self):
293291
self._test_samestat_on_link_func(os.symlink)
294292

295-
if sys.platform == 'win32':
296-
# TODO: RUSTPYTHON, properly implement stat st_dev/st_ino
297-
test_samestat_on_symlink = unittest.expectedFailure(test_samestat_on_symlink)
298-
299293
def test_samestat_on_link(self):
300294
try:
301295
self._test_samestat_on_link_func(os.link)

Lib/test/test_gzip.py

+1-5
Original file line numberDiff line numberDiff line change
@@ -708,6 +708,7 @@ def test_bad_params(self):
708708
with self.assertRaises(ValueError):
709709
gzip.open(self.filename, "rb", newline="\n")
710710

711+
@unittest.expectedFailureIfWindows("TODO: RUSTPYTHON")
711712
def test_encoding(self):
712713
# Test non-default encoding.
713714
uncompressed = data1.decode("ascii") * 50
@@ -720,11 +721,6 @@ def test_encoding(self):
720721
with gzip.open(self.filename, "rt", encoding="utf-16") as f:
721722
self.assertEqual(f.read(), uncompressed)
722723

723-
# TODO: RUSTPYTHON
724-
if sys.platform == "win32":
725-
test_encoding = unittest.expectedFailure(test_encoding)
726-
727-
728724
def test_encoding_error_handler(self):
729725
# Test with non-default encoding error handler.
730726
with gzip.open(self.filename, "wb") as f:

Lib/test/test_imp.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ def test_find_module_encoding(self):
8181
with self.assertRaises(SyntaxError):
8282
imp.find_module('badsyntax_pep3120', path)
8383

84+
@unittest.expectedFailureIfWindows("TODO: RUSTPYTHON")
8485
def test_issue1267(self):
8586
for mod, encoding, _ in self.test_strings:
8687
fp, filename, info = imp.find_module('module_' + mod,
@@ -100,10 +101,6 @@ def test_issue1267(self):
100101
self.assertEqual(fp.readline(),
101102
'"""Tokenization help for Python programs.\n')
102103

103-
# TODO: RUSTPYTHON
104-
if sys.platform == 'win32':
105-
test_issue1267 = unittest.expectedFailure(test_issue1267)
106-
107104
def test_issue3594(self):
108105
temp_mod_name = 'test_imp_helper'
109106
sys.path.insert(0, '.')

Lib/test/test_importlib/source/test_finder.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ def test_no_read_directory(self):
168168
found = self._find(finder, 'doesnotexist')
169169
self.assertEqual(found, self.NOT_FOUND)
170170

171+
@unittest.expectedFailureIfWindows("TODO: RUSTPYTHON")
171172
def test_ignore_file(self):
172173
# If a directory got changed to a file from underneath us, then don't
173174
# worry about looking for submodules.
@@ -176,10 +177,6 @@ def test_ignore_file(self):
176177
found = self._find(finder, 'doesnotexist')
177178
self.assertEqual(found, self.NOT_FOUND)
178179

179-
# TODO: RUSTPYTHON
180-
if sys.platform == 'win32':
181-
test_ignore_file = unittest.expectedFailure(test_ignore_file)
182-
183180

184181
class FinderTestsPEP451(FinderTests):
185182

0 commit comments

Comments
 (0)