Esempio n. 1
0
def test_run__error_on_invalid_start_actor():
    sess = session.Session()
    sess.actor('A', lambda value, out: None)
    sess.actor('B', lambda value, out: None)
    sess.load_graph(get_graph_file('t1.e2c'))
    with pytest.raises(errors.E2CSessionError) as info:
        sess.run(2, actor="X")
    assert str(info.value) == 'X is not a registered actor!'
Esempio n. 2
0
def test_run_continues():
    data = []
    sess = session.Session()
    sess.actor('A', lambda value, out: out(value + 1))
    sess.actor('B', lambda value, out: out(value * 3))
    sess.load_graph(get_graph_file('t4.e2c'))

    sess.run_continues(3, lambda value: data.append(value))
    assert data == [12, 12, 12]
Esempio n. 3
0
def test_run__call_trace():
    data = []
    sess = session.Session()
    sess.actor('A', lambda value, out: out(value))
    sess.actor('B', lambda value, out: out(value))
    sess.actor('Trace', lambda value: data.append(value))
    sess.load_graph(get_graph_file('t3.e2c'))

    sess.run(None)
    assert data == ['A', 'B']
Esempio n. 4
0
def test_run__assign_before_define():
    config = ('A.out -- B', '.run -- A')

    data = []
    sess = session.Session(config)
    sess.actor('A', lambda data, out: out(data))
    sess.actor('B', lambda d: data.append(d))
    sess.run(1)

    assert data[0] == 1
Esempio n. 5
0
def test_run__call_end():
    data = []
    sess = session.Session()
    sess.actor('A', lambda value, out: out(value))
    sess.actor('B', lambda value, out: out(value + 2))
    sess.actor('C', lambda value: data.append(value))
    sess.load_graph(get_graph_file('t2.e2c'))

    start_value = 1
    assert sess.run(start_value) == 3
    assert data[0] == start_value
Esempio n. 6
0
def test_run__raise_exception_missing_run():
    config = ('.trace -- trace', )

    def trace(name: str):
        pass

    sess = session.Session(config)
    sess.actor('trace', trace)
    with pytest.raises(errors.E2CSessionError) as info:
        sess.run()
    assert str(info.value) == 'Missing .run -- ? in graph!'
Esempio n. 7
0
def test_run__raise_exception_catch_actor():
    config = ('.err -- error', '.run -- A')

    def raise_error():
        raise Exception('Invalid operation')

    def error_handler():
        error['error'] = 1

    error = {}
    sess = session.Session(config)
    sess.actor('A', raise_error)
    sess.actor('error', error_handler)
    sess.run()

    assert error
Esempio n. 8
0
def test_run():
    # class method as actor
    class Dummy():
        def operation(self, value, out):
            out(value + 5)

    # function as actor
    def operation(value, out):
        out(value * 2)

    sess = session.Session()
    sess.actor('A', Dummy().operation)
    sess.actor('B', operation)
    sess.load_graph(get_graph_file('t1.e2c'))
    assert sess.run(3) == 16
    assert sess.run(3, actor="A") == 16
    assert sess.run(3, actor="B") == 6
    assert sess.run(2, actor="A") == 14
Esempio n. 9
0
def test_parse_graph__error_on_missing_target():
    with pytest.raises(errors.E2CParserError) as info:
        session.Session(['.run --', ''])
    assert str(info.value) == 'Missing actor in line 1!'
Esempio n. 10
0
def test_parse_graph__error_on_missing_double_line():
    with pytest.raises(errors.E2CParserError) as info:
        session.Session(['.run', ''])
    assert str(info.value) == 'Missing -- in line 1!'
Esempio n. 11
0
def test_parse_graph__error_on_empty_graph():
    with pytest.raises(errors.E2CParserError) as info:
        session.Session([
            '',
        ])
    assert str(info.value) == 'No data to parse!'
Esempio n. 12
0
def test_actor__error_on_double_name():
    sess = session.Session()
    sess.actor('A', lambda: None)
    with pytest.raises(errors.E2CSessionError) as info:
        sess.actor('A', lambda: None)
    assert str(info.value) == 'Actor A was already registered!'