def test_get_board_state():

    b = Board()
    b.set("other_key", 10001)
    get_board = GetBoardState("get", "other_key")
    get_board.start(b)
    get_board.wait()
    assert get_board.flow_out == 10001
Exemplo n.º 2
0
def test_board_set_deep_copy():

    b = Board()
    test_obj = {'hello': 'world'}
    b.set('obj', test_obj, deep_copy=False)
    test_obj['hello'] = 'test'
    assert b.get('obj')['hello'] == 'test'
    assert b.get('obj')['hello'] != 'world'
Exemplo n.º 3
0
def test_internal_set():
    s1 = DummyState('s1')
    set_state = SetState('set', 'key', 'hello')
    s1.add_transition_on_success(set_state)
    exe = Machine("xe", s1)
    b = Board()
    exe.start(b, manual_exec=True)
    exe.update(b, wait=True)
    assert b.get('key') == 'hello'
Exemplo n.º 4
0
def test_board_get_deep_copy():

    b = Board()
    test_obj = {'hello': 'world'}
    b.set('obj', test_obj, deep_copy=False)
    rtn_obj = b.get('obj', False)
    assert rtn_obj['hello'] == 'world'
    test_obj['hello'] = 'test'
    assert rtn_obj['hello'] == 'test'
def test_set_board_state():

    b = Board()
    assert b.get("test_key") is None
    set_board = SetBoardState("set", "test_key", "hello")
    set_board.start(b)
    set_board.wait()
    assert b.get("test_key") == "hello"
    assert b.get("test_key")
Exemplo n.º 6
0
def test_internal_get():
    s1 = DummyState('s1')
    get_state = GetState('set', 'key')
    s1.add_transition_on_success(get_state)
    exe = Machine("xe", s1)
    b = Board()
    b.set("key", "hello_get")
    exe.start(b, manual_exec=True)
    exe.update(b, wait=True)
    assert b.get('output') == 'hello_get'
Exemplo n.º 7
0
def test_load_dictionary():

    b = Board()
    check_dict = {'k1': 'Hello', 'k2': 800}
    b.load(check_dict)
    assert b.get('k1') == 'Hello'
    assert b.get('k2') == 800
    check_dict['k2'] = 100
    assert b.get('k2') == 800
    # try replacing a previous value
    check_dict_2 = {'k2': 1000}
    b.load(check_dict_2)
    assert b.get('k2') == 1000
Exemplo n.º 8
0
def test_simple_machine(capsys):
    ps1 = PrintState("ps1", "print1")
    ps2 = PrintState("ps2", "print2")
    ps1.add_transition_on_success(ps2)
    exe = Machine("xe", ps1, end_state_ids=["ps2"], rate=10)
    b = Board()
    exe.run(b)
    assert exe.is_end()
    assert capsys.readouterr().out == "print1\nprint2\n"
Exemplo n.º 9
0
def test_chain_case():
    s1 = DummyState("s1")
    s2 = DummyState("s2")
    s1.add_transition_on_success(s2)
    s3 = DummyState("s3")
    s2.add_transition_on_success(s3)
    exe = Machine("xe", s1, end_state_ids=["s3"], rate=10)
    b = Board()
    exe.start(b, manual_exec=True)
    exe.update(b, True)
    assert not exe.is_end()
    exe.update(b, True)
    assert exe.is_end()
Exemplo n.º 10
0
def test_simple_machine2(capsys):
    ps1 = PrintState("ps1", "print1")
    ps2 = PrintState("ps2", "print2")
    ps3 = PrintState("ps3", "print3")
    ps1.add_transition_on_success(ps2)
    ps2.add_transition_on_success(ps3)
    exe = Machine("xe", ps1, rate=10)
    b = Board()
    exe.start(b, manual_exec=True)
    assert capsys.readouterr().out == "print1\n"
    exe.update(b, wait=True)
    assert capsys.readouterr().out == "print2\n"
    exe.update(b, wait=True)
    assert capsys.readouterr().out == "print3\n"
Exemplo n.º 11
0
def test_board_exist_func():
    b = Board()
    b.set('hello', 'XXX')
    assert b.exist('hello')
    assert not b.exist('hello2')
    assert not b.exist('hell')
Exemplo n.º 12
0
def test_get_non_exist():
    b = Board()
    assert b.get('key') is None
Exemplo n.º 13
0
def test_replaced_set():
    b = Board()
    b.set("x", "hello")
    b.set("x", "world")

    assert b.get('x') == 'world'
Exemplo n.º 14
0
def test_external_set_get():
    b = Board()
    b.set("x", "key1")
    assert b.get('x') == 'key1'
Exemplo n.º 15
0
 def execute(self, board: Board):
     obj = {'hello': [1, 2, 3], 'name': {'first': 'test'}}
     board.set('obj', obj)
     obj = {}
     return StateStatus.SUCCESS