import random from unitpy.GeneralTests import GeneralTests from typing import List from pickle import TRUE from unitpy.Before import Before, getBefore from unitpy.RunWith import RunWith, getRunWith from unitpy.Runner import JUnit4ClassRunner, Parameterized, runTests from unitpy.Test import Test from unittest import TestCase 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 @RunWith(JUnit4ClassRunner) class Clazz2(Clazz1): @Before() def initialize(self): return "ok" @RunWith(Parameterized) class Clazz3(Clazz1): def initialize(self): return "ok" @RunWith(JUnit4ClassRunner) class SomeRunnableTests: @Test() def tryassert(self): TestCase().assertTrue(1==1) print("assert is ok") @Test(expected = ArithmeticError) def divzero(self): 1/0 class RunWithTest(TestCase): def test1(self): self.assertEqual(JUnit4ClassRunner, getRunWith(Clazz1)) def test2(self): self.assertEqual(JUnit4ClassRunner, getRunWith(Clazz2)) def test3(self): self.assertEqual(Parameterized, getRunWith(Clazz3)) def testRun(self): runTests(SomeRunnableTests) print("testruns ok")