|
1 | 1 | """http://dpip.testingperspective.com/?p=28""" |
2 | 2 |
|
3 | | -import time |
| 3 | +import time |
4 | 4 |
|
5 | 5 |
|
6 | 6 | class TC: |
7 | | - def __init__(self): |
8 | | - self._tm = tm |
9 | | - self._bProblem = 0 |
10 | | - |
11 | | - def setup(self): |
12 | | - print("Setting up the Test") |
13 | | - time.sleep(1) |
14 | | - self._tm.prepareReporting() |
15 | | - |
16 | | - def execute(self): |
17 | | - if not self._bProblem: |
18 | | - print("Executing the test") |
19 | | - time.sleep(1) |
20 | | - else: |
21 | | - print("Problem in setup. Test not executed.") |
22 | | - |
23 | | - def tearDown(self): |
24 | | - if not self._bProblem: |
25 | | - print("Tearing down") |
26 | | - time.sleep(1) |
27 | | - self._tm.publishReport() |
28 | | - else: |
29 | | - print("Test not executed. No tear down required.") |
| 7 | + def __init__(self): |
| 8 | + self._tm = tm |
| 9 | + self._bProblem = 0 |
| 10 | + |
| 11 | + def setup(self): |
| 12 | + print("Setting up the Test") |
| 13 | + time.sleep(1) |
| 14 | + self._tm.prepareReporting() |
| 15 | + |
| 16 | + def execute(self): |
| 17 | + if not self._bProblem: |
| 18 | + print("Executing the test") |
| 19 | + time.sleep(1) |
| 20 | + else: |
| 21 | + print("Problem in setup. Test not executed.") |
| 22 | + |
| 23 | + def tearDown(self): |
| 24 | + if not self._bProblem: |
| 25 | + print("Tearing down") |
| 26 | + time.sleep(1) |
| 27 | + self._tm.publishReport() |
| 28 | + else: |
| 29 | + print("Test not executed. No tear down required.") |
30 | 30 |
|
31 | 31 | def setTM(self, TM): |
32 | | - self._tm = tm |
| 32 | + self._tm = tm |
33 | 33 |
|
34 | | - def setProblem(self, value): |
35 | | - self._bProblem = value |
| 34 | + def setProblem(self, value): |
| 35 | + self._bProblem = value |
36 | 36 |
|
37 | 37 |
|
38 | 38 | class Reporter: |
39 | | - def __init__(self): |
40 | | - self._tm = None |
| 39 | + def __init__(self): |
| 40 | + self._tm = None |
41 | 41 |
|
42 | | - def prepare(self): |
43 | | - print("Reporter Class is preparing to report the results") |
44 | | - time.sleep(1) |
| 42 | + def prepare(self): |
| 43 | + print("Reporter Class is preparing to report the results") |
| 44 | + time.sleep(1) |
45 | 45 |
|
46 | | - def report(self): |
47 | | - print("Reporting the results of Test") |
48 | | - time.sleep(1) |
| 46 | + def report(self): |
| 47 | + print("Reporting the results of Test") |
| 48 | + time.sleep(1) |
49 | 49 |
|
50 | 50 | def setTM(self, TM): |
51 | | - self._tm = tm |
| 51 | + self._tm = tm |
52 | 52 |
|
53 | 53 |
|
54 | 54 | class DB: |
55 | | - def __init__(self): |
56 | | - self._tm = None |
57 | | - |
58 | | - def insert(self): |
59 | | - print("Inserting the execution begin status in the Database") |
60 | | - time.sleep(1) |
61 | | - #Following code is to simulate a communication from DB to TC |
62 | | - import random |
| 55 | + def __init__(self): |
| 56 | + self._tm = None |
| 57 | + |
| 58 | + def insert(self): |
| 59 | + print("Inserting the execution begin status in the Database") |
| 60 | + time.sleep(1) |
| 61 | + #Following code is to simulate a communication from DB to TC |
| 62 | + import random |
63 | 63 | if random.randrange(1, 4) == 3: |
64 | | - return -1 |
| 64 | + return -1 |
65 | 65 |
|
66 | | - def update(self): |
67 | | - print("Updating the test results in Database") |
68 | | - time.sleep(1) |
| 66 | + def update(self): |
| 67 | + print("Updating the test results in Database") |
| 68 | + time.sleep(1) |
69 | 69 |
|
70 | 70 | def setTM(self, TM): |
71 | | - self._tm = tm |
| 71 | + self._tm = tm |
72 | 72 |
|
73 | 73 |
|
74 | 74 | class TestManager: |
75 | | - def __init__(self): |
76 | | - self._reporter = None |
77 | | - self._db = None |
78 | | - self._tc = None |
| 75 | + def __init__(self): |
| 76 | + self._reporter = None |
| 77 | + self._db = None |
| 78 | + self._tc = None |
79 | 79 |
|
80 | | - def prepareReporting(self): |
81 | | - rvalue = self._db.insert() |
82 | | - if rvalue == -1: |
83 | | - self._tc.setProblem(1) |
84 | | - self._reporter.prepare() |
| 80 | + def prepareReporting(self): |
| 81 | + rvalue = self._db.insert() |
| 82 | + if rvalue == -1: |
| 83 | + self._tc.setProblem(1) |
| 84 | + self._reporter.prepare() |
85 | 85 |
|
86 | | - def setReporter(self, reporter): |
87 | | - self._reporter = reporter |
| 86 | + def setReporter(self, reporter): |
| 87 | + self._reporter = reporter |
88 | 88 |
|
89 | | - def setDB(self, db): |
90 | | - self._db = db |
| 89 | + def setDB(self, db): |
| 90 | + self._db = db |
91 | 91 |
|
92 | | - def publishReport(self): |
93 | | - self._db.update() |
94 | | - rvalue = self._reporter.report() |
| 92 | + def publishReport(self): |
| 93 | + self._db.update() |
| 94 | + rvalue = self._reporter.report() |
95 | 95 |
|
96 | 96 | def setTC(self, tc): |
97 | | - self._tc = tc |
98 | | - |
99 | | - |
100 | | -if __name__ == '__main__': |
101 | | - reporter = Reporter() |
102 | | - db = DB() |
103 | | - tm = TestManager() |
104 | | - tm.setReporter(reporter) |
105 | | - tm.setDB(db) |
106 | | - reporter.setTM(tm) |
107 | | - db.setTM(tm) |
108 | | - # For simplification we are looping on the same test. |
| 97 | + self._tc = tc |
| 98 | + |
| 99 | + |
| 100 | +if __name__ == '__main__': |
| 101 | + reporter = Reporter() |
| 102 | + db = DB() |
| 103 | + tm = TestManager() |
| 104 | + tm.setReporter(reporter) |
| 105 | + tm.setDB(db) |
| 106 | + reporter.setTM(tm) |
| 107 | + db.setTM(tm) |
| 108 | + # For simplification we are looping on the same test. |
109 | 109 | # Practically, it could be about various unique test classes and their |
110 | 110 | # objects |
111 | | - while (True): |
112 | | - tc = TC() |
113 | | - tc.setTM(tm) |
114 | | - tm.setTC(tc) |
115 | | - tc.setup() |
116 | | - tc.execute() |
| 111 | + while True: |
| 112 | + tc = TC() |
| 113 | + tc.setTM(tm) |
| 114 | + tm.setTC(tc) |
| 115 | + tc.setup() |
| 116 | + tc.execute() |
117 | 117 | tc.tearDown() |
0 commit comments