forked from OpenBazaar/OpenBazaar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_guid.py
67 lines (50 loc) · 2.45 KB
/
test_guid.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
import unittest
from node import guid
class TestGUIDMixin(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.guid = "42"
cls.alt_guid = "43"
cls.uguid = unicode(cls.guid)
cls.alt_uguid = unicode(cls.alt_guid)
def test_init(self):
guid_mixin_1 = guid.GUIDMixin(self.guid)
self.assertEqual(guid_mixin_1.guid, self.guid)
guid_mixin_2 = guid.GUIDMixin(self.uguid)
self.assertEqual(guid_mixin_2.guid, self.uguid)
def _test_eq_true_scenario(self, guid1, guid2):
guid_mixin_1 = guid.GUIDMixin(guid1)
guid_mixin_2 = guid.GUIDMixin(guid1)
guid_mixin_3 = guid.GUIDMixin(guid2)
self.assertIsNot(guid_mixin_1, guid_mixin_2, "Separate instantiations produce same objects.")
self.assertEqual(guid_mixin_1, guid_mixin_2, "GUIDMixin unequal to same GUIDMixin.")
self.assertEqual(guid_mixin_1, guid1, "GUIDMixin unequal to own GUID.")
self.assertEqual(
guid_mixin_1, guid_mixin_3, "GUIDMixin unequal to string-equivalent GUIDMixin."
)
def _test_eq_false_scenario(self, guid1, guid2):
guid_mixin_1 = guid.GUIDMixin(guid1)
guid_mixin_2 = guid.GUIDMixin(guid2)
self.assertNotEqual(guid_mixin_1, guid_mixin_2, "GUIDMixin equal to different GUIDMixin.")
self.assertNotEqual(guid_mixin_1, guid2, "GUIDMixin equal to different GUID.")
def test_eq_(self):
self._test_eq_true_scenario(self.guid, self.uguid)
self._test_eq_true_scenario(self.uguid, self.guid)
self._test_eq_false_scenario(self.guid, self.alt_guid)
self._test_eq_false_scenario(self.guid, self.alt_uguid)
self._test_eq_false_scenario(self.uguid, self.alt_guid)
self._test_eq_false_scenario(self.uguid, self.alt_uguid)
def test_hash(self):
guid_mixin_1 = guid.GUIDMixin(self.guid)
self.assertEqual(hash(guid_mixin_1), hash(self.guid))
self.assertEqual(hash(guid_mixin_1), hash(self.uguid))
guid_mixin_2 = guid.GUIDMixin(self.uguid)
self.assertEqual(hash(guid_mixin_2), hash(self.guid))
self.assertEqual(hash(guid_mixin_2), hash(self.uguid))
def test_repr(self):
guid_mixin_1 = guid.GUIDMixin(self.guid)
self.assertEqual(guid_mixin_1.__repr__(), str(guid_mixin_1))
guid_mixin_2 = guid.GUIDMixin(self.uguid)
self.assertEqual(guid_mixin_2.__repr__(), str(guid_mixin_2))
if __name__ == "__main__":
unittest.main()