|
11 | 11 | else:
|
12 | 12 | import unittest
|
13 | 13 |
|
| 14 | + |
14 | 15 | class ProxyTest(unittest.TestCase):
|
15 | 16 |
|
16 | 17 | @classmethod
|
17 |
| - def setUpClass(self): |
| 18 | + def setUpClass(cls): |
18 | 19 | """ Class scope setup. """
|
19 |
| - self.p = Proxy() |
| 20 | + cls.p = Proxy() |
20 | 21 |
|
21 |
| - def setUp(self): |
| 22 | + def setUp(cls): |
22 | 23 | """ Function/test case scope setup. """
|
23 |
| - self.output = StringIO() |
24 |
| - self.saved_stdout = sys.stdout |
25 |
| - sys.stdout = self.output |
| 24 | + cls.output = StringIO() |
| 25 | + cls.saved_stdout = sys.stdout |
| 26 | + sys.stdout = cls.output |
26 | 27 |
|
27 |
| - def tearDown(self): |
| 28 | + def tearDown(cls): |
28 | 29 | """ Function/test case scope teardown. """
|
29 |
| - self.output.close() |
30 |
| - sys.stdout = self.saved_stdout |
| 30 | + cls.output.close() |
| 31 | + sys.stdout = cls.saved_stdout |
31 | 32 |
|
32 |
| - def test_sales_manager_shall_work_through_proxy_with_delay(self): |
33 |
| - self.p.busy = 'No' |
| 33 | + def test_sales_manager_shall_work_through_proxy_with_delay(cls): |
| 34 | + cls.p.busy = 'No' |
34 | 35 | start_time = time()
|
35 |
| - self.p.work() |
| 36 | + cls.p.work() |
36 | 37 | end_time = time()
|
37 | 38 | execution_time = end_time - start_time
|
38 |
| - print_output = self.output.getvalue() |
| 39 | + print_output = cls.output.getvalue() |
39 | 40 | expected_print_output = 'Proxy checking for Sales Manager availability\n\
|
40 | 41 | Sales Manager ready to talk\n'
|
41 |
| - self.assertEqual(print_output, expected_print_output) |
| 42 | + cls.assertEqual(print_output, expected_print_output) |
42 | 43 | expected_execution_time = 2
|
43 |
| - self.assertEqual(int(execution_time), expected_execution_time) |
| 44 | + cls.assertEqual(int(execution_time), expected_execution_time) |
44 | 45 |
|
45 |
| - def test_sales_manager_shall_respond_through_proxy_with_delay(self): |
46 |
| - self.p.busy = 'Yes' |
| 46 | + def test_sales_manager_shall_respond_through_proxy_with_delay(cls): |
| 47 | + cls.p.busy = 'Yes' |
47 | 48 | start_time = time()
|
48 |
| - self.p.work() |
| 49 | + cls.p.work() |
49 | 50 | end_time = time()
|
50 | 51 | execution_time = end_time - start_time
|
51 |
| - print_output = self.output.getvalue() |
| 52 | + print_output = cls.output.getvalue() |
52 | 53 | expected_print_output = 'Proxy checking for Sales Manager availability\n\
|
53 | 54 | Sales Manager is busy\n'
|
54 |
| - self.assertEqual(print_output, expected_print_output) |
| 55 | + cls.assertEqual(print_output, expected_print_output) |
55 | 56 | expected_execution_time = 2
|
56 |
| - self.assertEqual(int(execution_time), expected_execution_time) |
| 57 | + cls.assertEqual(int(execution_time), expected_execution_time) |
| 58 | + |
57 | 59 |
|
58 | 60 | class NoTalkProxyTest(unittest.TestCase):
|
59 | 61 |
|
60 | 62 | @classmethod
|
61 |
| - def setUpClass(self): |
| 63 | + def setUpClass(cls): |
62 | 64 | """ Class scope setup. """
|
63 |
| - self.ntp = NoTalkProxy() |
| 65 | + cls.ntp = NoTalkProxy() |
64 | 66 |
|
65 |
| - def setUp(self): |
| 67 | + def setUp(cls): |
66 | 68 | """ Function/test case scope setup. """
|
67 |
| - self.output = StringIO() |
68 |
| - self.saved_stdout = sys.stdout |
69 |
| - sys.stdout = self.output |
| 69 | + cls.output = StringIO() |
| 70 | + cls.saved_stdout = sys.stdout |
| 71 | + sys.stdout = cls.output |
70 | 72 |
|
71 |
| - def tearDown(self): |
| 73 | + def tearDown(cls): |
72 | 74 | """ Function/test case scope teardown. """
|
73 |
| - self.output.close() |
74 |
| - sys.stdout = self.saved_stdout |
| 75 | + cls.output.close() |
| 76 | + sys.stdout = cls.saved_stdout |
75 | 77 |
|
76 |
| - def test_sales_manager_shall_not_work_through_proxy_with_delay(self): |
77 |
| - self.ntp.busy = 'No' |
| 78 | + def test_sales_manager_shall_not_work_through_proxy_with_delay(cls): |
| 79 | + cls.ntp.busy = 'No' |
78 | 80 | start_time = time()
|
79 |
| - self.ntp.work() |
| 81 | + cls.ntp.work() |
80 | 82 | end_time = time()
|
81 | 83 | execution_time = end_time - start_time
|
82 |
| - print_output = self.output.getvalue() |
| 84 | + print_output = cls.output.getvalue() |
83 | 85 | expected_print_output = 'Proxy checking for Sales Manager availability\n\
|
84 | 86 | This Sales Manager will not talk to you whether he/she is busy or not\n'
|
85 |
| - self.assertEqual(print_output, expected_print_output) |
| 87 | + cls.assertEqual(print_output, expected_print_output) |
86 | 88 | expected_execution_time = 2
|
87 |
| - self.assertEqual(int(execution_time), expected_execution_time) |
| 89 | + cls.assertEqual(int(execution_time), expected_execution_time) |
88 | 90 |
|
89 |
| - def test_sales_manager_shall_not_respond_through_proxy_with_delay(self): |
90 |
| - self.ntp.busy = 'Yes' |
| 91 | + def test_sales_manager_shall_not_respond_through_proxy_with_delay(cls): |
| 92 | + cls.ntp.busy = 'Yes' |
91 | 93 | start_time = time()
|
92 |
| - self.ntp.work() |
| 94 | + cls.ntp.work() |
93 | 95 | end_time = time()
|
94 | 96 | execution_time = end_time - start_time
|
95 |
| - print_output = self.output.getvalue() |
| 97 | + print_output = cls.output.getvalue() |
96 | 98 | expected_print_output = 'Proxy checking for Sales Manager availability\n\
|
97 | 99 | This Sales Manager will not talk to you whether he/she is busy or not\n'
|
98 |
| - self.assertEqual(print_output, expected_print_output) |
| 100 | + cls.assertEqual(print_output, expected_print_output) |
99 | 101 | expected_execution_time = 2
|
100 |
| - self.assertEqual(int(execution_time), expected_execution_time) |
| 102 | + cls.assertEqual(int(execution_time), expected_execution_time) |
101 | 103 |
|
102 | 104 | if __name__ == "__main__":
|
103 | 105 | unittest.main()
|
0 commit comments