Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
TASTE
OpenGEODE
Commits
9761fc77
Commit
9761fc77
authored
Jun 23, 2016
by
Maxime Perrotin
Browse files
Add py.test case and minor cosmetic updates
parent
56dbb587
Changes
5
Hide whitespace changes
Inline
Side-by-side
opengeode/ogParser.py
View file @
9761fc77
...
...
@@ -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_ou
t
put
()
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_ou
t
put
()
as
(
stdout
,
stderr
):
r
=
parser_ptr
()
for
e
in
stderr
:
syntax_errors
.
append
(
e
.
strip
())
...
...
opengeode/samnmax.py
View file @
9761fc77
...
...
@@ -14,18 +14,18 @@ from contextlib import contextmanager
@
contextmanager
def
capture_ouput
(
stdout_to
=
None
,
stderr_to
=
None
):
def
capture_ou
t
put
(
stdout_to
=
None
,
stderr_to
=
None
):
"""
Context manager that captures any printed ouput in the 'with' block.
Context manager that captures any printed ou
t
put in the 'with' block.
:Exemple:
>>> with capture_ouput() as (stdout, stderr):
>>> with capture_ou
t
put() as (stdout, stderr):
... print "hello",
...
>>> print stdout.getvalue().upper()
HELLO
>>> with capture_ouput() as (stdout, stderr):
>>> with capture_ou
t
put() 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_ou
t
put(f) as (stdout, stderr):
... print "hello",
...
>>> print stdout.read()
...
...
tests/parser/aggreg.py
→
tests/parser/
test_
aggreg.py
View file @
9761fc77
File moved
tests/parser/expression
s
.py
→
tests/parser/
test_
expression.py
View file @
9761fc77
File moved
tests/parser/test_provided.py
0 → 100755
View file @
9761fc77
#!/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
))
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment