Skip to content

Commit 97788bf

Browse files
author
thinwybk
committed
add: unit test / delete: revert to initial version
add: unit test for module strategy.py delete: revert to initial version of strategy.py
1 parent afb2491 commit 97788bf

2 files changed

Lines changed: 9 additions & 19 deletions

File tree

‎strategy.py‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,14 @@ def __init__(self, func=None):
2020

2121
def execute(self):
2222
print(self.name)
23-
return self.name
2423

2524

2625
def execute_replacement1(self):
2726
print(self.name + ' from execute 1')
28-
return self.name + ' from execute 1'
2927

3028

3129
def execute_replacement2(self):
3230
print(self.name + ' from execute 2')
33-
return self.name + ' from execute 2'
3431

3532

3633
if __name__ == '__main__':

‎test_strategy.py‎

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,17 @@
11
import unittest
2-
import strategy
2+
import subprocess
33

44
class StrategyTest(unittest.TestCase):
55

66
def test_print_output(self):
7-
strat0 = strategy.StrategyExample()
8-
9-
strat1 = strategy.StrategyExample(strategy.execute_replacement1)
10-
strat1.name = 'Strategy Example 1'
11-
12-
strat2 = strategy.StrategyExample(strategy.execute_replacement2)
13-
strat2.name = 'Strategy Example 2'
14-
15-
first_line = strat0.execute()
16-
second_line = strat1.execute()
17-
third_line = strat2.execute()
18-
19-
self.assertEqual(first_line, 'Strategy Example 0')
20-
self.assertEqual(second_line, 'Strategy Example 1 from execute 1')
21-
self.assertEqual(third_line, 'Strategy Example 2 from execute 2')
7+
output = subprocess.check_output(["python", "strategy.py"])
8+
print(output)
9+
expected_output = 'Strategy Example 0\r\n\
10+
Strategy Example 1 from execute 1\r\n\
11+
Strategy Example 2 from execute 2\r\n'
12+
# byte representation required due to EOF returned subprocess
13+
expected_output_as_bytes = expected_output.encode(encoding='UTF-8')
14+
self.assertEqual(output, expected_output_as_bytes)
2215

2316
if __name__ == "__main__":
2417
unitest.main()

0 commit comments

Comments
 (0)