Skip to content

Commit 709cf16

Browse files
Kathryn BakerKathryn Baker
authored andcommitted
Moving the testing scripts to somewhere easier to access
1 parent 8e09e72 commit 709cf16

File tree

2 files changed

+142
-0
lines changed

2 files changed

+142
-0
lines changed
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
from genie_python import genie as g
2+
3+
"""
4+
A manual system test for exercising genie_python block functionality
5+
"""
6+
7+
8+
def genie_python_blocks_test() -> None:
9+
str_block_name = "TEST_BLOCK_STR"
10+
num_block_name = "TEST_BLOCK_NUM"
11+
12+
def float_in_tolerance(actual: float, expected: float, tolerance: float = 0.0005) -> float:
13+
return abs(actual - expected) < tolerance
14+
15+
def assert_numeric_block(
16+
name: str,
17+
value: float = None,
18+
runcontrol: bool = None,
19+
lowlimit: float = None,
20+
highlimit: float = None,
21+
connected: bool = None,
22+
max_wait: int = 10,
23+
) -> None:
24+
import time
25+
26+
steps = 10
27+
for i in range(steps):
28+
try:
29+
block = g.cget(num_block_name)
30+
if value is not None:
31+
assert float_in_tolerance(block["value"], value)
32+
if lowlimit is not None:
33+
assert float_in_tolerance(block["lowlimit"], lowlimit)
34+
if highlimit is not None:
35+
assert float_in_tolerance(block["highlimit"], highlimit)
36+
if connected is not None:
37+
assert block["connected"] == connected
38+
if runcontrol is not None:
39+
assert block["runcontrol"] == runcontrol
40+
return
41+
except AssertionError:
42+
if i < steps - 1:
43+
time.sleep(float(max_wait) / float(steps))
44+
else:
45+
print(
46+
f"Expected value: {value}, {connected}, {runcontrol}, {lowlimit}, "
47+
f"{highlimit}. Actual value: {block['value']}, {block['connected']}, "
48+
f"{block['runcontrol']}, {block['lowlimit']}, {block['highlimit']} "
49+
f"(val, connected, rc, low, high)"
50+
)
51+
assert False
52+
53+
def assert_from_user_input(question: str) -> None:
54+
assert (input("{}? (Y/N) ".format(question)).lower() + "n")[0] == "y"
55+
56+
print("Test required blocks exist")
57+
assert num_block_name in g.get_blocks()
58+
assert str_block_name in g.get_blocks()
59+
60+
print("Test can set block values")
61+
new_str_value = "TEST"
62+
g.cset(str_block_name, new_str_value)
63+
assert g.cget(str_block_name)["value"] == new_str_value
64+
65+
new_num_value = 1.234
66+
g.cset(num_block_name, new_num_value)
67+
assert_numeric_block(num_block_name, value=new_num_value)
68+
69+
print("Test setting run control")
70+
starting_value = 0.0
71+
lowlimit = -1.0
72+
highlimit = 1.0
73+
g.cset(num_block_name, starting_value, runcontrol=True, lowlimit=lowlimit, highlimit=highlimit)
74+
assert_numeric_block(
75+
num_block_name,
76+
lowlimit=lowlimit,
77+
highlimit=highlimit,
78+
runcontrol=True,
79+
value=starting_value,
80+
)
81+
assert_from_user_input("Is TEST_BLOCK_NUM displaying within its run control limit")
82+
83+
g.cset(num_block_name, highlimit + 1.0)
84+
assert_from_user_input("Is TEST_BLOCK_NUM displaying outside its run control limit")
85+
g.cset(num_block_name, starting_value)
86+
87+
print("Test show block data")
88+
g.cshow(num_block_name)
89+
assert_from_user_input("Does the data above look sensible for TEST_BLOCK_NUM")
90+
g.cshow(str_block_name)
91+
assert_from_user_input("Does the data above look sensible for TEST_BLOCK_STR")
92+
93+
print("TESTS COMPLETED SUCCESSFULLY")
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
from genie_python import genie as g
2+
3+
"""
4+
A manual system test for exercising genie_python dae functionality
5+
"""
6+
7+
8+
def genie_python_dae_test() -> None:
9+
def float_in_tolerance(actual: float, expected: float, tolerance: float = 0.0005) -> float:
10+
return abs(actual - expected) < tolerance
11+
12+
def assert_from_user_input(question: str) -> None:
13+
assert (input("{}? (Y/N) ".format(question)).lower() + "n")[0] == "y"
14+
15+
print("Test get/set title")
16+
new_title = "NEW TITLE"
17+
print("Setting: " + str(new_title))
18+
print("Getting: " + str(g.get_title()))
19+
g.change_title(new_title)
20+
assert g.get_title() == new_title
21+
22+
print("Test get/set users")
23+
new_users = "Adrian, Kevin, Kathryn"
24+
g.change_users(new_users)
25+
# DAE replaces final "," with "and"
26+
assert g.get_dashboard()["user"].replace(" and", ",") == new_users
27+
28+
print("Test change run state")
29+
# Use a range of verbosities
30+
assert g.get_runstate() == "SETUP"
31+
g.begin(True)
32+
assert g.get_runstate() == "RUNNING"
33+
g.pause()
34+
assert g.get_runstate() == "PAUSED"
35+
g.resume(False)
36+
assert g.get_runstate() == "RUNNING"
37+
g.abort()
38+
assert g.get_runstate() == "SETUP"
39+
g.begin(True)
40+
assert g.get_runstate() == "RUNNING"
41+
g.end(False)
42+
assert g.get_runstate() == "SETUP"
43+
44+
print("Testing waitfors")
45+
g.waitfor_time(seconds=0.1)
46+
g.waitfor_uamps(0.1)
47+
g.waitfor_frames(1)
48+
49+
print("TESTS COMPLETED SUCCESSFULLY")

0 commit comments

Comments
 (0)