File tree Expand file tree Collapse file tree 4 files changed +47
-0
lines changed
Expand file tree Collapse file tree 4 files changed +47
-0
lines changed Original file line number Diff line number Diff line change @@ -30,6 +30,7 @@ htmlcov/
3030env /
3131venv /
3232.env
33+ .venv
3334
3435# built protos
3536* _pb2.py
Original file line number Diff line number Diff line change 1+ import json
2+ import os
3+ import unittest
4+ from unittest import mock
5+
6+ from examples import hello_world
7+ from openhtf .plugs import user_input
8+
9+
10+ class TestHelloWorld (unittest .TestCase ):
11+
12+ def setUp (self ):
13+ self .expected_output_file = None
14+
15+ def tearDown (self ):
16+ if self .expected_output_file and os .path .exists (self .expected_output_file ):
17+ os .remove (self .expected_output_file )
18+
19+ @mock .patch .object (user_input .UserInput , user_input .UserInput .prompt .__name__ )
20+ def test_main_execution (self , mock_user_prompt ):
21+ # The test only has one prompt, for the DUT ID.
22+ mock_user_prompt .return_value = "test_dut"
23+
24+ # The test configured JSON output into the current working directory.
25+ self .expected_output_file = "./test_dut.hello_world.json"
26+
27+ hello_world .main ()
28+
29+ # Assert that the output file was created
30+ self .assertTrue (os .path .exists (self .expected_output_file ))
31+
32+ with open (self .expected_output_file ) as f :
33+ output_data = json .load (f )
34+ self .assertEqual (output_data ["dut_id" ], "test_dut" )
35+ self .assertEqual (output_data ["outcome" ], "PASS" )
36+ self .assertGreaterEqual (len (output_data ["phases" ]), 2 )
37+ self .assertEqual (
38+ output_data ["phases" ][1 ]["measurements" ]["hello_world_measurement" ][
39+ "measured_value"
40+ ],
41+ "Hello Again!" ,
42+ )
43+
44+
45+ if __name__ == "__main__" :
46+ unittest .main ()
You can’t perform that action at this time.
0 commit comments