Commit 9761fc77 authored by Maxime Perrotin's avatar Maxime Perrotin
Browse files

Add py.test case and minor cosmetic updates

parent 56dbb587
......@@ -4374,7 +4374,7 @@ def add_to_ast(ast, filename=None, string=None):
LOG.error('Parser error: ' + str(err))
raise
# Use Sam & Max output capturer to get errors from ANTLR parser
with samnmax.capture_ouput() as (stdout, stderr):
with samnmax.capture_output() as (stdout, stderr):
tree_rule_return_scope = parser.pr_file()
for e in stderr:
errors.append([e.strip()])
......@@ -4470,7 +4470,7 @@ def parseSingleElement(elem='', string='', context=None):
warnings = []
t = None
if parser:
with samnmax.capture_ouput() as (stdout, stderr):
with samnmax.capture_output() as (stdout, stderr):
r = parser_ptr()
for e in stderr:
syntax_errors.append(e.strip())
......
......@@ -14,18 +14,18 @@ from contextlib import contextmanager
@contextmanager
def capture_ouput(stdout_to=None, stderr_to=None):
def capture_output(stdout_to=None, stderr_to=None):
"""
Context manager that captures any printed ouput in the 'with' block.
Context manager that captures any printed output in the 'with' block.
:Exemple:
>>> with capture_ouput() as (stdout, stderr):
>>> with capture_output() as (stdout, stderr):
... print "hello",
...
>>> print stdout.getvalue().upper()
HELLO
>>> with capture_ouput() as (stdout, stderr):
>>> with capture_output() as (stdout, stderr):
# doctest: +IGNORE_EXCEPTION_DETAIL
... assert False
...
......@@ -33,7 +33,7 @@ def capture_ouput(stdout_to=None, stderr_to=None):
AssertionError
>>> from tempfile import NamedTemporaryFile
>>> f = NamedTemporaryFile(mode="rw+b")
>>> with capture_ouput(f) as (stdout, stderr):
>>> with capture_output(f) as (stdout, stderr):
... print "hello",
...
>>> print stdout.read()
......
#!/usr/bin/env python
from opengeode.ogParser import parser_init, antlr3, sdl92Parser, samnmax
# return a string corresponding to a token number:
token = lambda num: sdl92Parser.tokenNames[num]
def test_1():
''' Test the parsing of numbers '''
test = parser_init(string='''provided true=false; priority 5;''')
res = test.continuous_signal()
assert(not isinstance(res.tree, antlr3.tree.CommonErrorNode))
def test_2():
''' Test the parsing of numbers '''
test = parser_init(string='''provided true priority 5;''')
with samnmax.capture_output() as (stdout, stderr):
test.continuous_signal()
errCount = 0
for each in stderr:
print('[ERROR] ' + str(each))
errCount += 1
assert not errCount
if __name__ == '__main__':
for name, value in dict(globals()).viewitems():
if name.startswith('test_'):
print('---- Executing {} ----'.format(name))
value()
print('---- Done - {} ----\n'.format(name))
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment