|
| 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") |
0 commit comments