import unittest import random from unitpy.GeneralTests import GeneralTests from typing import List from pickle import TRUE from unitpy.Test import Test,getTestNames, getExpected class Clazz1: ''' Bugged, it always returns the same hashcode. ''' def __init__(self, v:str): self.value = v def __repr__(self): return str(self.value) + " " + str(random.randint(1,100)) def __hash__(self): return hash(self.value) def __eq__(self, other): return isinstance(other, self.__class__) and \ self.value == other.value class Clazz2(Clazz1): @Test() def sometest(self): return "ok" class Clazz3(Clazz1): @Test(expected=ValueError) def sometest(self): return "ok" class TestTest(unittest.TestCase): def test1(self): self.assertEqual([], getTestNames(Clazz1)) def test2(self): self.assertEqual(['sometest'], getTestNames(Clazz2)) self.assertEqual(None, getExpected(Clazz2.sometest)) def test3(self): self.assertEqual(['sometest'], getTestNames(Clazz3)) self.assertEqual(ValueError, getExpected(Clazz3.sometest))