Skip to content

Commit ab6a3be

Browse files
committed
rename extra_tests
1 parent 487cd56 commit ab6a3be

File tree

9 files changed

+75
-75
lines changed

9 files changed

+75
-75
lines changed

extra_tests/snippets/builtin_exceptions.py

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,81 @@
22
import platform
33
import sys
44

5+
def exceptions_eq(e1, e2):
6+
return type(e1) is type(e2) and e1.args == e2.args
7+
8+
def round_trip_repr(e):
9+
return exceptions_eq(e, eval(repr(e)))
10+
11+
# KeyError
12+
empty_exc = KeyError()
13+
assert str(empty_exc) == ''
14+
assert round_trip_repr(empty_exc)
15+
assert len(empty_exc.args) == 0
16+
assert type(empty_exc.args) == tuple
17+
18+
exc = KeyError('message')
19+
assert str(exc) == "'message'"
20+
assert round_trip_repr(exc)
21+
22+
assert LookupError.__str__(exc) == "message"
23+
24+
exc = KeyError('message', 'another message')
25+
assert str(exc) == "('message', 'another message')"
26+
assert round_trip_repr(exc)
27+
assert exc.args[0] == 'message'
28+
assert exc.args[1] == 'another message'
29+
30+
class A:
31+
def __repr__(self):
32+
return 'A()'
33+
def __str__(self):
34+
return 'str'
35+
def __eq__(self, other):
36+
return type(other) is A
37+
38+
exc = KeyError(A())
39+
assert str(exc) == 'A()'
40+
assert round_trip_repr(exc)
41+
42+
# ImportError / ModuleNotFoundError
43+
exc = ImportError()
44+
assert exc.name is None
45+
assert exc.path is None
46+
assert exc.msg is None
47+
assert exc.args == ()
48+
49+
exc = ImportError('hello')
50+
assert exc.name is None
51+
assert exc.path is None
52+
assert exc.msg == 'hello'
53+
assert exc.args == ('hello',)
54+
55+
exc = ImportError('hello', name='name', path='path')
56+
assert exc.name == 'name'
57+
assert exc.path == 'path'
58+
assert exc.msg == 'hello'
59+
assert exc.args == ('hello',)
60+
61+
62+
class NewException(Exception):
63+
64+
def __init__(self, value):
65+
self.value = value
66+
67+
68+
try:
69+
raise NewException("test")
70+
except NewException as e:
71+
assert e.value == "test"
72+
73+
74+
exc = SyntaxError('msg', 1, 2, 3, 4, 5)
75+
assert exc.msg == 'msg'
76+
assert exc.filename is None
77+
assert exc.lineno is None
78+
assert exc.offset is None
79+
assert exc.text is None
580

681
# Regression to:
782
# https://github.com/RustPython/RustPython/issues/2779
File renamed without changes.

extra_tests/snippets/exceptions.py

Lines changed: 0 additions & 75 deletions
This file was deleted.

0 commit comments

Comments
 (0)