コード例 #1
0
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
コード例 #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'
コード例 #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'
コード例 #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'
コード例 #5
0
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")
コード例 #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'
コード例 #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
コード例 #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"
コード例 #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()
コード例 #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"
コード例 #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')
コード例 #12
0
def test_get_non_exist():
    b = Board()
    assert b.get('key') is None
コード例 #13
0
def test_replaced_set():
    b = Board()
    b.set("x", "hello")
    b.set("x", "world")

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