|
5 | 5 | import sys |
6 | 6 | import unittest |
7 | 7 |
|
8 | | -from iptest import IronPythonTestCase, is_cli, is_netcoreapp, run_test, skipUnlessIronPython |
| 8 | +from iptest import IronPythonTestCase, is_cli, is_netcoreapp, run_test, skipUnlessIronPython, expectedFailureIf |
9 | 9 |
|
10 | 10 | class CP35300_Derived(EnvironmentError): |
11 | 11 | def __init__(self, *args, **kwargs): |
@@ -828,7 +828,7 @@ def __new__(cls, *args): return 42 |
828 | 828 | with self.assertRaises(TypeError): # TypeError: exceptions must derive from BaseException |
829 | 829 | raise MyException('abc') |
830 | 830 |
|
831 | | - @unittest.expectedFailure # https://github.com/IronLanguages/ironpython3/issues/876 |
| 831 | + @expectedFailureIf(is_cli) # https://github.com/IronLanguages/ironpython3/issues/876 |
832 | 832 | def test_oserror_init(self): |
833 | 833 | x = OSError() |
834 | 834 | self.assertEqual(x.errno, None) |
@@ -1025,6 +1025,39 @@ def test_windows_error(self): |
1025 | 1025 | # winerror code is mapped to Python error code |
1026 | 1026 | self.assertEqual(OSError('foo', 'bar', 'baz', 10).errno, 7) |
1027 | 1027 |
|
| 1028 | + def test_os_error_mapping(self): |
| 1029 | + import errno |
| 1030 | + import itertools |
| 1031 | + |
| 1032 | + error_map = { |
| 1033 | + errno.EPERM : PermissionError, |
| 1034 | + errno.ENOENT : FileNotFoundError, |
| 1035 | + errno.ESRCH : ProcessLookupError, |
| 1036 | + errno.EINTR : InterruptedError, |
| 1037 | + errno.ECHILD : ChildProcessError, |
| 1038 | + errno.EAGAIN : BlockingIOError, |
| 1039 | + errno.EACCES : PermissionError, |
| 1040 | + errno.EEXIST : FileExistsError, |
| 1041 | + errno.ENOTDIR : NotADirectoryError, |
| 1042 | + errno.EISDIR : IsADirectoryError, |
| 1043 | + errno.EPIPE : BrokenPipeError, |
| 1044 | + errno.EWOULDBLOCK : BlockingIOError, |
| 1045 | + errno.ECONNABORTED : ConnectionAbortedError, |
| 1046 | + errno.ECONNRESET : ConnectionResetError, |
| 1047 | + errno.ESHUTDOWN : BrokenPipeError, |
| 1048 | + errno.ETIMEDOUT : TimeoutError, |
| 1049 | + errno.ECONNREFUSED : ConnectionRefusedError, |
| 1050 | + errno.EALREADY : BlockingIOError, |
| 1051 | + errno.EINPROGRESS : BlockingIOError, |
| 1052 | + } |
| 1053 | + |
| 1054 | + for errno, exc in error_map.items(): |
| 1055 | + self.assertIsInstance(OSError(errno, ''), exc) |
| 1056 | + |
| 1057 | + for errno in itertools.chain(range(200), range(10000, 10200)): |
| 1058 | + if errno not in error_map: |
| 1059 | + self.assertIsInstance(OSError(errno, ''), OSError) |
| 1060 | + |
1028 | 1061 | def test_derived_keyword_args(self): |
1029 | 1062 | class ED(Exception): |
1030 | 1063 | def __init__(self, args=''): |
|
0 commit comments