Example #1
0
def test_statement_task_2(mock_emitter):
    """Tests the statement method

    PRECONDITIONS: Create parser with line source_code
    EXECUTION: par.statement()
    POSTCONDITION: No exception is thrown

    """
    source_code = "TASK<EVENT=myEvent> myTask"
    par = Parser(Lexer(source_code), mock_emitter)

    par.statement()
Example #2
0
def test_statement_rung_2(mock_emitter):
    """Tests the statement method

    PRECONDITIONS: Create parser with line source_code
    EXECUTION: par.statement()
    POSTCONDITION: No exception is thrown

    """
    source_code = "RUNG myRung"
    par = Parser(Lexer(source_code), mock_emitter)
    par.stack.append('ROUTINE')

    par.statement()
Example #3
0
def test_statement_routine_success(mock_emitter):
    """Tests the statement method

    PRECONDITIONS: Create parser with line source_code
    EXECUTION: par.statement()
    POSTCONDITION: No exception is thrown

    """
    source_code = "ROUTINE Main"
    par = Parser(Lexer(source_code), mock_emitter)
    par.stack.append('TASK')

    par.statement()
Example #4
0
def test_statement_task_3(mock_emitter):
    """Tests the statement method

    PRECONDITIONS: Create parser with line source_code
    EXECUTION: par.statement()
    POSTCONDITION: Exception is thrown with correct error message

    """
    source_code = "TASK<CONTINUOUS> myTask"
    par = Parser(Lexer(source_code), mock_emitter)

    with pytest.raises(CompilationError) as pytest_wrapped_e:
        par.statement()
    assert "Parsing error line #0 : Invalid task type CONTINUOUS" == str(pytest_wrapped_e.value)
Example #5
0
def test_statement_routine_failure(mock_emitter):
    """Tests the statement method

    PRECONDITIONS: Create parser with line source_code
    EXECUTION: par.statement()
    POSTCONDITION: Exception is thrown

    """
    source_code = "ROUTINE "
    par = Parser(Lexer(source_code), mock_emitter)
    par.stack.append('TASK')

    with pytest.raises(CompilationError) as pytest_wrapped_e:
        par.statement()
    assert "Parsing error line #1 : Expected "\
           "IDENTIFIER, but found \n" == str(pytest_wrapped_e.value)