1- import pytest ,os ,re ,io ,sys , mock , json , unittest
2- from unittest .mock import patch
1+ import pytest ,os ,re ,io ,sys , mock , json
32
43
5- # @pytest.mark.it('The solution should work with other entries ')
6- # def test_expected_output_5(stdin ):
4+ @pytest .mark .it ('Almost there! But you need to convert the incoming input from string to integer ' )
5+ def test_convert_inputs ( capsys , app ):
76
8- # _stdin = ['5']
9- # with mock.patch('builtins.input', lambda x: _stdin.pop(0)):
7+ fake_input = ["8" ] #fake input
8+ with mock .patch ('builtins.input' , lambda x : fake_input .pop ()):
9+ app ()
10+ captured = capsys .readouterr ()
11+ assert captured .out == "{1: 1, 2: 4, 3: 9, 4: 16, 5: 25, 6: 36, 7: 49, 8: 64}\n "
1012
11- # sys.stdout = buffer = io.StringIO()
12- # import app
13- # # _stdin = json.loads(stdin)
14- # result = {1: 1, 2: 4, 3: 9, 4: 16, 5: 25}
15- # assert buffer.getvalue() == str(result) + "\n"
1613
17- @pytest .mark .it ('The solution should return the expected output' )
18- def test_expected_output_8 (stdin ):
14+ @pytest .mark .it ('Almost there! But you need to convert the incoming input from string to integer' )
15+ def test_convert_inputs_2 (capsys , app ):
16+
17+ fake_input = ["5" ] #fake input
18+ with mock .patch ('builtins.input' , lambda x : fake_input .pop ()):
19+ app ()
20+ captured = capsys .readouterr ()
21+ assert captured .out == "{1: 1, 2: 4, 3: 9, 4: 16, 5: 25}\n "
1922
20- _stdin = ['8' ]
21- with mock .patch ('builtins.input' , lambda x : _stdin .pop (0 )):
2223
23- sys .stdout = buffer = io .StringIO ()
24- import app
25- # _stdin = json.loads(stdin)
26- result = {1 : 1 , 2 : 4 , 3 : 9 , 4 : 16 , 5 : 25 , 6 : 36 , 7 : 49 , 8 : 64 }
27- assert buffer .getvalue () == str (result ) + "\n "
0 commit comments