]> git.proxmox.com Git - mirror_edk2.git/blame - AppPkg/Applications/Python/Python-2.7.2/Lib/unittest/test/support.py
EmbeddedPkg: Extend NvVarStoreFormattedLib LIBRARY_CLASS
[mirror_edk2.git] / AppPkg / Applications / Python / Python-2.7.2 / Lib / unittest / test / support.py
CommitLineData
4710c53d 1import unittest\r
2\r
3\r
4class TestHashing(object):\r
5 """Used as a mixin for TestCase"""\r
6\r
7 # Check for a valid __hash__ implementation\r
8 def test_hash(self):\r
9 for obj_1, obj_2 in self.eq_pairs:\r
10 try:\r
11 if not hash(obj_1) == hash(obj_2):\r
12 self.fail("%r and %r do not hash equal" % (obj_1, obj_2))\r
13 except KeyboardInterrupt:\r
14 raise\r
15 except Exception, e:\r
16 self.fail("Problem hashing %r and %r: %s" % (obj_1, obj_2, e))\r
17\r
18 for obj_1, obj_2 in self.ne_pairs:\r
19 try:\r
20 if hash(obj_1) == hash(obj_2):\r
21 self.fail("%s and %s hash equal, but shouldn't" %\r
22 (obj_1, obj_2))\r
23 except KeyboardInterrupt:\r
24 raise\r
25 except Exception, e:\r
26 self.fail("Problem hashing %s and %s: %s" % (obj_1, obj_2, e))\r
27\r
28\r
29class TestEquality(object):\r
30 """Used as a mixin for TestCase"""\r
31\r
32 # Check for a valid __eq__ implementation\r
33 def test_eq(self):\r
34 for obj_1, obj_2 in self.eq_pairs:\r
35 self.assertEqual(obj_1, obj_2)\r
36 self.assertEqual(obj_2, obj_1)\r
37\r
38 # Check for a valid __ne__ implementation\r
39 def test_ne(self):\r
40 for obj_1, obj_2 in self.ne_pairs:\r
41 self.assertNotEqual(obj_1, obj_2)\r
42 self.assertNotEqual(obj_2, obj_1)\r
43\r
44\r
45class LoggingResult(unittest.TestResult):\r
46 def __init__(self, log):\r
47 self._events = log\r
48 super(LoggingResult, self).__init__()\r
49\r
50 def startTest(self, test):\r
51 self._events.append('startTest')\r
52 super(LoggingResult, self).startTest(test)\r
53\r
54 def startTestRun(self):\r
55 self._events.append('startTestRun')\r
56 super(LoggingResult, self).startTestRun()\r
57\r
58 def stopTest(self, test):\r
59 self._events.append('stopTest')\r
60 super(LoggingResult, self).stopTest(test)\r
61\r
62 def stopTestRun(self):\r
63 self._events.append('stopTestRun')\r
64 super(LoggingResult, self).stopTestRun()\r
65\r
66 def addFailure(self, *args):\r
67 self._events.append('addFailure')\r
68 super(LoggingResult, self).addFailure(*args)\r
69\r
70 def addSuccess(self, *args):\r
71 self._events.append('addSuccess')\r
72 super(LoggingResult, self).addSuccess(*args)\r
73\r
74 def addError(self, *args):\r
75 self._events.append('addError')\r
76 super(LoggingResult, self).addError(*args)\r
77\r
78 def addSkip(self, *args):\r
79 self._events.append('addSkip')\r
80 super(LoggingResult, self).addSkip(*args)\r
81\r
82 def addExpectedFailure(self, *args):\r
83 self._events.append('addExpectedFailure')\r
84 super(LoggingResult, self).addExpectedFailure(*args)\r
85\r
86 def addUnexpectedSuccess(self, *args):\r
87 self._events.append('addUnexpectedSuccess')\r
88 super(LoggingResult, self).addUnexpectedSuccess(*args)\r
89\r
90\r
91class ResultWithNoStartTestRunStopTestRun(object):\r
92 """An object honouring TestResult before startTestRun/stopTestRun."""\r
93\r
94 def __init__(self):\r
95 self.failures = []\r
96 self.errors = []\r
97 self.testsRun = 0\r
98 self.skipped = []\r
99 self.expectedFailures = []\r
100 self.unexpectedSuccesses = []\r
101 self.shouldStop = False\r
102\r
103 def startTest(self, test):\r
104 pass\r
105\r
106 def stopTest(self, test):\r
107 pass\r
108\r
109 def addError(self, test):\r
110 pass\r
111\r
112 def addFailure(self, test):\r
113 pass\r
114\r
115 def addSuccess(self, test):\r
116 pass\r
117\r
118 def wasSuccessful(self):\r
119 return True\r