1
1
import subprocess
2
- import time
3
- from os import remove
2
+ import os
3
+ import sys
4
4
from pathlib import Path
5
+ import time
5
6
import unittest
6
7
7
8
8
- PROJECT_ROOT = Path (__file__ ).parent .absolute ()
9
+ PROJECT_ROOT = Path (__file__ ).parent .parent .absolute ()
10
+
11
+ from contextlib import contextmanager
12
+
9
13
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
+
17
24
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_
19
32
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 ))
24
33
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)
26
38
27
- assert output == ['Result(value=6, parser=infix, expression="3*2")' ]
39
+ if __name__ == '__maipython -m unittestn__' :
40
+ unittest .main ()
0 commit comments