Skip to content

Commit 635c0ab

Browse files
Merge pull request #1228 from glados-verma:test/hello-world-integration
PiperOrigin-RevId: 761292572
2 parents 5085a9a + 02ccd59 commit 635c0ab

File tree

4 files changed

+47
-0
lines changed

4 files changed

+47
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ htmlcov/
3030
env/
3131
venv/
3232
.env
33+
.venv
3334

3435
# built protos
3536
*_pb2.py

test/__init__.py

Whitespace-only changes.

test/examples/__init__.py

Whitespace-only changes.

test/examples/test_hello_world.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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()

0 commit comments

Comments
 (0)