-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.py
86 lines (63 loc) · 2.31 KB
/
tests.py
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
import unittest
from metamorism import *
class StrictBase(Metamorphic) :
def __init__(self) -> None:
self.__private = True
def greet(self) :
return "Hello, World!"
def paramTest(self, a: str, b) :
return False
def privateTest(self) :
pass
class StrictTest(unittest.TestCase) :
def test_positive(self) :
class WorkingMorph(StrictBase) :
def greet(self = None) :
return "Hello, Earth!"
def paramTest(self, a: str, b) :
return True
def privateTest(self) :
return self.__private
a = StrictBase()
self.assertEqual(a.greet(), "Hello, World!")
self.assertFalse(a.paramTest("a", "b"))
morph(a, WorkingMorph)
self.assertEqual(a.greet(), "Hello, Earth!")
self.assertTrue(a.paramTest("a", "b"))
self.assertTrue(a.privateTest())
def test_negative(self) :
def typo_test() :
class TypoMorph(StrictBase) :
def geeet(self) :
print("Too many e's")
self.assertRaises(MetamorphismError, typo_test)
def test_param_types(self) :
def param_swap() :
class SwapedParamsMorph(StrictBase) :
def paramTest(self, b, a) :
return True
self.assertRaises(MetamorphismError, param_swap)
class Loose(MetamorphismBase, metaclass=CustomMetamorphic, strict=False) :
pass
class LooseBase(Loose) :
pass
class LooseTest(unittest.TestCase) :
def test_loose(self) :
class SloppyMorph(LooseBase) :
def greet(self) :
return "Hello, World"
class LooseParamsBase(Metamorphic, metaclass=CustomMetamorphic, allow_mixed_typing=True) :
def greet(self) :
return "Hello, World!"
def paramTest(self, a: str, b) :
return False
class LooseParamsTest(unittest.TestCase) :
def test_param_types(self) :
class LooseParamsMorph(LooseParamsBase) :
def paramTest(self, a: str, b: str) :
return True
a = LooseParamsBase()
morph(a, LooseParamsMorph)
self.assertTrue(a.paramTest("", ""))
if __name__ == "__main__" :
unittest.main()