def run(source_code):
    """Run the source code.

    :param source_code: code to run
    :type source_code: :class:`str`
    """
    eval_(parse(lex(source_code)), Context(apply_stencil))
def assert_lex_token_list(code, expected_token_tuples):
    stream = lex(code)

    # For some reason, pytest always says there is a diff at index 0, even when
    # it occurs elsewhere in the list. Falling back to asserting in a loop.
    # expected_tokens = [
    #     Token(name, value) for name, value in expected_token_tuples]
    # assert list(lex(code)) == expected_tokens

    for name, value in expected_token_tuples:
        computed_token = next(stream)
        expected_token = Token(name, value)
        assert computed_token == expected_token

    with raises(StopIteration):
        next(stream)
 def test_empty_file_name(self):
     stream = lex('""')
     with raises(LexingError):
         next(stream)
 def test_unclosed_file_name(self):
     stream = lex('"')
     with raises(LexingError):
         next(stream)
 def test_invalid_continues_to_raise_lexing_errors(self):
     stream = lex('ABCD')
     for _ in xrange(5):
         with raises(LexingError):
             next(stream)
 def test_invalid_next_instruction(self):
     stream = lex('STO 1 123.3\nawesome')
     for _ in xrange(3):
         next(stream)
     with raises(LexingError):
         next(stream)
 def test_invalid_sto(self):
     stream = lex('STO 1 hello')
     for _ in xrange(2):
         next(stream)
     with raises(LexingError):
         next(stream)
 def test_invalid_token(self):
     stream = lex('ABCD')
     with raises(LexingError):
         next(stream)
 def test_nothing(self):
     stream = lex('')
     with raises(StopIteration):
         next(stream)