source: unitpy/test/GeneralTestsTest.py@ 1227

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

added a test with correct object, also works fine.

File size: 1.0 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 hash(self.value)
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
39
Note: See TracBrowser for help on using the repository browser.