Line | |
---|
1 | import random
|
---|
2 | from unitpy.GeneralTests import GeneralTests
|
---|
3 | from typing import List
|
---|
4 | from pickle import TRUE
|
---|
5 | from unitpy.Before import Before, getBefore
|
---|
6 | from unitpy.RunWith import RunWith, getRunWith
|
---|
7 | from unitpy.Runner import JUnit4ClassRunner, Parameterized, runTests
|
---|
8 | from unitpy.Test import Test
|
---|
9 | from unittest import TestCase
|
---|
10 |
|
---|
11 | class Clazz1:
|
---|
12 | '''
|
---|
13 | Bugged, it always returns the same hashcode.
|
---|
14 | '''
|
---|
15 | def __init__(self, v:str):
|
---|
16 | self.value = v
|
---|
17 |
|
---|
18 | def __repr__(self):
|
---|
19 | return str(self.value) + " " + str(random.randint(1,100))
|
---|
20 |
|
---|
21 |
|
---|
22 |
|
---|
23 | def __hash__(self):
|
---|
24 | return hash(self.value)
|
---|
25 |
|
---|
26 | def __eq__(self, other):
|
---|
27 | return isinstance(other, self.__class__) and \
|
---|
28 | self.value == other.value
|
---|
29 |
|
---|
30 | @RunWith(JUnit4ClassRunner)
|
---|
31 | class Clazz2(Clazz1):
|
---|
32 | @Before()
|
---|
33 | def initialize(self):
|
---|
34 | return "ok"
|
---|
35 |
|
---|
36 |
|
---|
37 |
|
---|
38 | @RunWith(Parameterized)
|
---|
39 | class Clazz3(Clazz1):
|
---|
40 | def initialize(self):
|
---|
41 | return "ok"
|
---|
42 |
|
---|
43 |
|
---|
44 | @RunWith(JUnit4ClassRunner)
|
---|
45 | class SomeRunnableTests:
|
---|
46 | @Test()
|
---|
47 | def tryassert(self):
|
---|
48 | TestCase().assertTrue(1==1)
|
---|
49 | print("assert is ok")
|
---|
50 | @Test(expected = ArithmeticError)
|
---|
51 | def divzero(self):
|
---|
52 | 1/0
|
---|
53 |
|
---|
54 |
|
---|
55 | class RunWithTest(TestCase):
|
---|
56 | def test1(self):
|
---|
57 | self.assertEqual(JUnit4ClassRunner, getRunWith(Clazz1))
|
---|
58 |
|
---|
59 | def test2(self):
|
---|
60 | self.assertEqual(JUnit4ClassRunner, getRunWith(Clazz2))
|
---|
61 |
|
---|
62 | def test3(self):
|
---|
63 | self.assertEqual(Parameterized, getRunWith(Clazz3))
|
---|
64 |
|
---|
65 | def testRun(self):
|
---|
66 | runTests(SomeRunnableTests)
|
---|
67 | print("testruns ok")
|
---|
68 |
|
---|
69 |
|
---|
70 |
|
---|
71 |
|
---|
72 | |
---|
Note:
See
TracBrowser
for help on using the repository browser.