source: unitpy/test/TestTest.py

Last change on this file was 989, checked in by wouter, 3 months ago

#336 recovery commit. Untested

File size: 1.2 KB
Line 
1import unittest
2import random
3from unitpy.GeneralTests import GeneralTests
4from typing import List
5from pickle import TRUE
6from unitpy.Test import Test,getTestNames, getExpected
7
8
9class Clazz1:
10 '''
11 Bugged, it always returns the same hashcode.
12 '''
13 def __init__(self, v:str):
14 self.value = v
15
16 def __repr__(self):
17 return str(self.value) + " " + str(random.randint(1,100))
18
19 def __hash__(self):
20 return hash(self.value)
21
22 def __eq__(self, other):
23 return isinstance(other, self.__class__) and \
24 self.value == other.value
25
26class Clazz2(Clazz1):
27 @Test()
28 def sometest(self):
29 return "ok"
30
31class Clazz3(Clazz1):
32 @Test(expected=ValueError)
33 def sometest(self):
34 return "ok"
35
36
37class TestTest(unittest.TestCase):
38 def test1(self):
39 self.assertEqual([], getTestNames(Clazz1))
40
41 def test2(self):
42 self.assertEqual(['sometest'], getTestNames(Clazz2))
43 self.assertEqual(None, getExpected(Clazz2.sometest))
44
45 def test3(self):
46 self.assertEqual(['sometest'], getTestNames(Clazz3))
47 self.assertEqual(ValueError, getExpected(Clazz3.sometest))
48
Note: See TracBrowser for help on using the repository browser.