Skip to content

Commit eacb262

Browse files
author
Lorena Mesa
committed
Start Python unittests
1 parent f10653c commit eacb262

File tree

1 file changed

+30
-17
lines changed

1 file changed

+30
-17
lines changed

test/sample_cases_test.py

+30-17
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,40 @@
11
import subprocess
2-
import time
3-
from os import remove
2+
import os
3+
import sys
44
from pathlib import Path
5+
import time
56
import unittest
67

78

8-
PROJECT_ROOT = Path(__file__).parent.absolute()
9+
PROJECT_ROOT = Path(__file__).parent.parent.absolute()
10+
11+
from contextlib import contextmanager
12+
913

10-
def test_sample_case_one():
11-
subprocess.Popen(
12-
f'python3 main.py --t [email protected] --o lorenaemail',
13-
cwd=f"{PROJECT_ROOT.parent}",
14-
stdin=subprocess.PIPE,
15-
shell=True,
16-
)
14+
@contextmanager
15+
def redirect_stdout(new_out):
16+
# https://stackoverflow.com/questions/47066063/how-to-capture-python-subprocess-stdout-in-unittest
17+
old_stdout = os.dup(1)
18+
try:
19+
os.dup2(new_out, sys.stdout.fileno())
20+
yield
21+
finally:
22+
os.dup2(old_stdout, 1)
23+
1724

18-
time.sleep(1)
25+
class TestHappyPath(unittest.TestCase):
26+
def test_fails_to_create_identicon_with_input_text_missing(self):
27+
with self.assertRaises(subprocess.CalledProcessError) as context:
28+
error_received = subprocess.check_output(f'python3 {PROJECT_ROOT}/main.py', shell=True, stderr=subprocess.STDOUT).strip()
29+
self.assertIn(context.exception.message, "main.py: error: the following arguments are required: -s/--string")
30+
31+
def generates_
1932

20-
output = []
21-
with open(f"{PROJECT_ROOT}/lorenaoutput.png", "rb") as f:
22-
output = f.readlines(); print(output)
23-
output = list(map(lambda l: l.decode("utf-8"), output))
2433

25-
remove(f"{PROJECT_ROOT}/lorenaoutput.png")
34+
# hash_str =convert_string_to_sha_hash("931D387731bBbC988B31220")
35+
# hash_str = convert_string_to_sha_hash("[email protected]")
36+
# grid = build_grid(hash_str)
37+
# draw_image(grid, hash_str)
2638

27-
assert output == ['Result(value=6, parser=infix, expression="3*2")']
39+
if __name__ == '__maipython -m unittestn__':
40+
unittest.main()

0 commit comments

Comments
 (0)