1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
|
# This may be loaded as a module, in the current __main__ module,
# or in another __main__ module.
#######################################
# functions and generators
from test._code_definitions import *
#######################################
# classes
class Spam:
# minimal
pass
class SpamOkay:
def okay(self):
return True
class SpamFull:
a: object
b: object
c: object
@staticmethod
def staticmeth(cls):
return True
@classmethod
def classmeth(cls):
return True
def __new__(cls, *args, **kwargs):
return super().__new__(cls)
def __init__(self, a, b, c):
self.a = a
self.b = b
self.c = c
# __repr__
# __str__
# ...
def __eq__(self, other):
if not isinstance(other, SpamFull):
return NotImplemented
return (self.a == other.a and
self.b == other.b and
self.c == other.c)
@property
def prop(self):
return True
class SubSpamFull(SpamFull):
...
class SubTuple(tuple):
...
def class_eggs_inner():
class EggsNested:
...
return EggsNested
EggsNested = class_eggs_inner()
TOP_CLASSES = {
Spam: (),
SpamOkay: (),
SpamFull: (1, 2, 3),
SubSpamFull: (1, 2, 3),
SubTuple: ([1, 2, 3],),
}
CLASSES_WITHOUT_EQUALITY = [
Spam,
SpamOkay,
]
BUILTIN_SUBCLASSES = [
SubTuple,
]
NESTED_CLASSES = {
EggsNested: (),
}
CLASSES = {
**TOP_CLASSES,
**NESTED_CLASSES,
}
#######################################
# exceptions
class MimimalError(Exception):
pass
class RichError(Exception):
def __init__(self, msg, value=None):
super().__init__(msg, value)
self.msg = msg
self.value = value
def __eq__(self, other):
if not isinstance(other, RichError):
return NotImplemented
if self.msg != other.msg:
return False
if self.value != other.value:
return False
return True
|