Exemple #1
0
def test_cli_include_invalid(capsys):
    try:
        cli.include.main(['invalid'])
    except SystemExit as ex:
        ex.code | should.be_equal(1)

    output = capsys.readouterr()
    output.err.strip() | should.be_equal('Error: Unknown flavor "invalid"')
Exemple #2
0
def test_cli_include(capsys):
    try:
        cli.include.main(['gtest'])
    except SystemExit as ex:
        ex.code | should.be_equal(0)

    output = capsys.readouterr()
    output.out | should_not.be_empty()
Exemple #3
0
def test_parse_basic():
    graph = parse('''
        // @state A
        // @state B
        // @transition A -> B
    ''')

    graph | should.be_instance_of(StateGraph)

    graph.states | should.have_length(2)
    graph.states[0].id | should.be_equal('A')
    graph.states[1].id | should.be_equal('B')

    graph.transitions | should.have_length(1)
    graph.transitions[0].from_state.id | should.be_equal('A')
    graph.transitions[0].to_state.id | should.be_equal('B')
    graph.transitions[0].triggers | should.be_empty()
Exemple #4
0
def test_decorator():
    class T(FailureModeResolver):
        @failure_mode
        def failing(self):
            """foobar"""
            return []

    T.failing | should.be_an_instance_of(UnboundFailureMode)

    t = T()
    t.failing | should.be_an_instance_of(FailureMode)
    t.failing.arguments | should.be_empty()
    t.failing.description | should.be_equal('foobar')
Exemple #5
0
def test_cli_graph():
    with TemporaryDirectory() as tmp:
        out_path = Path(tmp) / 'graph.png'

        try:
            cli.graph.main([
                '--input-file',
                str(EXAMPLE_PATH / 'src' / 'states.c'),
                '--output-file',
                str(out_path),
            ])
        except SystemExit as ex:
            ex.code | should.be_equal(0)

        out_path.exists() | should.be_true()
Exemple #6
0
def test_cli_analyze(capsys):
    try:
        cli.analyze.main([
            '--input-file',
            str(EXAMPLE_PATH / 'src' / 'states.c'),
        ])
    except SystemExit as ex:
        ex.code | should.be_equal(0)

    output = capsys.readouterr()
    stdout = output.out.strip()

    stdout | should.contain_the_substring('Initial state: ')
    stdout | should.contain_the_substring('States: ')
    stdout | should.contain_the_substring('Transitions: ')
    stdout | should.contain_the_substring('Closed graph: ')
    stdout | should.contain_the_substring('Isolated states: ')
    stdout | should.contain_the_substring('Single degree states: ')
Exemple #7
0
def test_cli_build():
    with TemporaryDirectory() as tmp:
        out_path = Path(tmp) / 'test_states.cpp'
        base_path = Path(tmp) / 'base_states.cpp'

        copy(EXAMPLE_PATH / 'test' / 'base_states.cpp', base_path)

        try:
            cli.build.main([
                '--input-file',
                str(EXAMPLE_PATH / 'src' / 'states.c'),
                '--base-file',
                str(base_path),
                '--output-file',
                str(out_path),
            ])
        except SystemExit as ex:
            ex.code | should.be_equal(0)

        out_path.exists() | should.be_true()
def check_http_response_code(context, code):
    # Check if the response has the correct HTTP response status code
    context.response.status_code | should.be_equal(int(code))
Exemple #9
0
def test_get_transition():
    graph, states, transitions = _get_test_graph()

    graph.get_transition(states['init'], states['middle']) | should.be_equal(
        transitions[('init', 'middle')])