source: unitpy/test/GeneralTestsTest2.py@ 289

Last change on this file since 289 was 289, checked in by wouter, 3 years ago

#98 fix errors mypy

File size: 1.2 KB
Line 
1import unittest
2import random
3from unitpy.GeneralTests import GeneralTests
4from typing import List
5# import unittest
6class ObjectUnderTest2:
7 '''
8 Bugged, it always returns the same hashcode.
9 '''
10 def __init__(self, v:str):
11 self.value = v
12
13 def __repr__(self):
14 return str(self.value) + " " + str(random.randint(1,100))
15
16 def __hash__(self):
17 return 31
18
19 def __eq__(self, other):
20 return isinstance(other, self.__class__) and \
21 self.value == other.value
22
23
24
25class GeneralTestTest2(unittest.TestCase, GeneralTests[ObjectUnderTest2]):
26 def getGeneralTestData(self) -> List[List[ObjectUnderTest2]] :
27 list = []
28 list.append([ ObjectUnderTest2("hi"),ObjectUnderTest2("hi")])
29 list.append([ ObjectUnderTest2("ha")])
30 list.append([ ObjectUnderTest2("")])
31 list.append([ ObjectUnderTest2(None)]) #type:ignore
32
33 return list;
34
35 def getGeneralTestStrings(self) ->List[str] :
36 return ["hi .*", "ha .*", ".*", "None.*"]
37
38 #override
39 def testNotEqualsAllData(self):
40 sup=super()
41 self.assertRaises(AssertionError, lambda:sup.testNotEqualsAllData())
42 #,"are different but actually have same hashcode");
43
44
Note: See TracBrowser for help on using the repository browser.