Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
marcin-usielski committed Oct 15, 2024
1 parent e37a65c commit 45c3949
Showing 1 changed file with 28 additions and 16 deletions.
44 changes: 28 additions & 16 deletions test/device/test_SM_unix_remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,29 @@
from moler.exceptions import DeviceFailure


def test_unix_remote_device(device_connection, unix_remote_output):
unix_remote = get_device(name="UNIX_REMOTE", connection=device_connection, device_output=unix_remote_output,
unix_remotes=['UNIX_REMOTE', 'UNIX_REMOTE3']
unix_remotes_proxy_pc=['UNIX_REMOTE_PROXY_PC', 'UNIX_REMOTE3_PROXY_PC']
unix_remotes_real_io = ['UNIX_REMOTE_REAL_IO', 'UNIX_REMOTE3_REAL_IO']

@pytest.mark.parametrize("device_name", unix_remotes)
def test_unix_remote_device(device_name, device_connection, unix_remote_output):
unix_remote = get_device(name=device_name, connection=device_connection, device_output=unix_remote_output,
test_file_path=__file__)
iterate_over_device_states(device=unix_remote)
assert None is not unix_remote._cmdnames_available_in_state['UNIX_LOCAL_ROOT']


def test_unix_remote_proxy_pc_device(device_connection, unix_remote_proxy_pc_output):
unix_remote_proxy_pc = get_device(name="UNIX_REMOTE_PROXY_PC", connection=device_connection,
@pytest.mark.parametrize("device_name", unix_remotes_proxy_pc)
def test_unix_remote_proxy_pc_device(device_name, device_connection, unix_remote_proxy_pc_output):
unix_remote_proxy_pc = get_device(name=device_name, connection=device_connection,
device_output=unix_remote_proxy_pc_output, test_file_path=__file__)

iterate_over_device_states(device=unix_remote_proxy_pc)
assert None is not unix_remote_proxy_pc._cmdnames_available_in_state['UNIX_LOCAL_ROOT']


def test_unix_remote_proxy_pc_device_multiple_prompts(device_connection, unix_remote_proxy_pc_output):
@pytest.mark.parametrize("device_name", unix_remotes_proxy_pc)
def test_unix_remote_proxy_pc_device_multiple_prompts(device_name, device_connection, unix_remote_proxy_pc_output):
unix_remote_proxy_pc_changed_output = copy_dict(unix_remote_proxy_pc_output, deep_copy=True)
combined_line = "moler_bash#"
for src_state in unix_remote_proxy_pc_output.keys():
Expand All @@ -39,7 +46,7 @@ def test_unix_remote_proxy_pc_device_multiple_prompts(device_connection, unix_re
for cmd_string in unix_remote_proxy_pc_changed_output[src_state].keys():
unix_remote_proxy_pc_changed_output[src_state][cmd_string] = combined_line

unix_remote_proxy_pc = get_device(name="UNIX_REMOTE_PROXY_PC", connection=device_connection,
unix_remote_proxy_pc = get_device(name=device_name, connection=device_connection,
device_output=unix_remote_proxy_pc_changed_output,
test_file_path=__file__)
assert unix_remote_proxy_pc._check_all_prompts_on_line is True
Expand All @@ -50,8 +57,9 @@ def test_unix_remote_proxy_pc_device_multiple_prompts(device_connection, unix_re
assert "More than 1 prompt match the same line" in str(exception.value)


def test_unix_remote_proxy_pc_device_goto_state_bg(device_connection, unix_remote_proxy_pc_output):
unix_remote_proxy_pc = get_device(name="UNIX_REMOTE_PROXY_PC", connection=device_connection,
@pytest.mark.parametrize("device_name", unix_remotes_proxy_pc)
def test_unix_remote_proxy_pc_device_goto_state_bg(device_name, device_connection, unix_remote_proxy_pc_output):
unix_remote_proxy_pc = get_device(name=device_name, connection=device_connection,
device_output=unix_remote_proxy_pc_output, test_file_path=__file__)
unix_remote_proxy_pc._goto_state_in_production_mode = True
dst_state = "UNIX_REMOTE_ROOT"
Expand All @@ -76,8 +84,9 @@ def test_unix_remote_proxy_pc_device_goto_state_bg(device_connection, unix_remot
assert time_diff < min(execution_time_fg, execution_time_bg)


def test_unix_remote_proxy_pc_device_goto_state_bg_and_goto(device_connection, unix_remote_proxy_pc_output):
unix_remote_proxy_pc = get_device(name="UNIX_REMOTE_PROXY_PC", connection=device_connection,
@pytest.mark.parametrize("device_name", unix_remotes_proxy_pc)
def test_unix_remote_proxy_pc_device_goto_state_bg_and_goto(device_name, device_connection, unix_remote_proxy_pc_output):
unix_remote_proxy_pc = get_device(name=device_name, connection=device_connection,
device_output=unix_remote_proxy_pc_output, test_file_path=__file__)
unix_remote_proxy_pc._goto_state_in_production_mode = True

Expand All @@ -91,8 +100,9 @@ def test_unix_remote_proxy_pc_device_goto_state_bg_and_goto(device_connection, u
assert unix_remote_proxy_pc.current_state == dst_state


def test_unix_remote_proxy_pc_device_goto_state_bg_await(device_connection, unix_remote_proxy_pc_output):
unix_remote_proxy_pc = get_device(name="UNIX_REMOTE_PROXY_PC", connection=device_connection,
@pytest.mark.parametrize("device_name", unix_remotes_proxy_pc)
def test_unix_remote_proxy_pc_device_goto_state_bg_await(device_name, device_connection, unix_remote_proxy_pc_output):
unix_remote_proxy_pc = get_device(name=device_name, connection=device_connection,
device_output=unix_remote_proxy_pc_output, test_file_path=__file__)
unix_remote_proxy_pc._goto_state_in_production_mode = True
dst_state = "UNIX_REMOTE_ROOT"
Expand All @@ -105,8 +115,9 @@ def test_unix_remote_proxy_pc_device_goto_state_bg_await(device_connection, unix
assert unix_remote_proxy_pc.current_state == dst_state


def test_unix_remote_proxy_pc_device_goto_state_bg_await_excption(device_connection, unix_remote_proxy_pc_output):
unix_remote_proxy_pc = get_device(name="UNIX_REMOTE_PROXY_PC", connection=device_connection,
@pytest.mark.parametrize("device_name", unix_remotes_proxy_pc)
def test_unix_remote_proxy_pc_device_goto_state_bg_await_exception(device_name, device_connection, unix_remote_proxy_pc_output):
unix_remote_proxy_pc = get_device(name=device_name, connection=device_connection,
device_output=unix_remote_proxy_pc_output, test_file_path=__file__)
unix_remote_proxy_pc._goto_state_in_production_mode = True
dst_state = "UNIX_REMOTE_ROOT"
Expand All @@ -122,10 +133,11 @@ def test_unix_remote_proxy_pc_device_goto_state_bg_await_excption(device_connect
assert unix_remote_proxy_pc.current_state == dst_state


def test_unix_remote_device_not_connected():
@pytest.mark.parametrize("device_name", unix_remotes_real_io)
def test_unix_remote_device_not_connected(device_name):
dir_path = os.path.dirname(os.path.realpath(__file__))
load_config(os.path.join(dir_path, os.pardir, os.pardir, 'test', 'resources', 'device_config.yml'))
unix_remote = DeviceFactory.get_device(name="UNIX_REMOTE_REAL_IO", initial_state="UNIX_LOCAL")
unix_remote = DeviceFactory.get_device(name=device_name, initial_state="UNIX_LOCAL")
unix_remote.goto_state("UNIX_LOCAL", sleep_after_changed_state=0)
cmd_whoami = unix_remote.get_cmd(cmd_name="whoami")
ret1 = cmd_whoami()
Expand Down

0 comments on commit 45c3949

Please sign in to comment.