Ejemplo n.º 1
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'
Ejemplo n.º 2
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'
Ejemplo n.º 3
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'
Ejemplo n.º 4
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'
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"
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()
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"
Ejemplo n.º 8
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')
Ejemplo n.º 9
0
def test_get_non_exist():
    b = Board()
    assert b.get('key') is None
Ejemplo n.º 10
0
def test_replaced_set():
    b = Board()
    b.set("x", "hello")
    b.set("x", "world")

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