Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Alexander Reinauer
pystencils
Commits
b962a099
Commit
b962a099
authored
Jan 24, 2020
by
Stephan Seitz
Browse files
Add assertion that headers follow the pattern /"..."/ or /<...>/
parent
de3489c4
Changes
2
Hide whitespace changes
Inline
Side-by-side
pystencils/backends/cbackend.py
View file @
b962a099
import
re
from
collections
import
namedtuple
from
typing
import
Set
...
...
@@ -24,6 +25,9 @@ except ImportError:
__all__
=
[
'generate_c'
,
'CustomCodeNode'
,
'PrintNode'
,
'get_headers'
,
'CustomSympyPrinter'
]
HEADER_REGEX
=
re
.
compile
(
r
'^[<"].*[">]$'
)
KERNCRAFT_NO_TERNARY_MODE
=
False
...
...
@@ -112,6 +116,9 @@ def get_headers(ast_node: Node) -> Set[str]:
if
isinstance
(
g
,
Node
):
headers
.
update
(
get_headers
(
g
))
for
h
in
headers
:
assert
HEADER_REGEX
.
match
(
h
),
f
'header /
{
h
}
/ does not follow the pattern /"..."/ or /<...>/'
return
sorted
(
headers
)
...
...
pystencils_tests/test_helpful_errors.py
0 → 100644
View file @
b962a099
"""
"""
import
pytest
from
pystencils.astnodes
import
Block
from
pystencils.backends.cbackend
import
CustomCodeNode
,
get_headers
def
test_headers_have_quotes_or_brackets
():
class
ErrorNode1
(
CustomCodeNode
):
def
__init__
(
self
):
super
().
__init__
(
""
,
[],
[])
self
.
headers
=
[
"iostream"
]
class
ErrorNode2
(
CustomCodeNode
):
headers
=
[
"<iostream>"
,
"foo"
]
def
__init__
(
self
):
super
().
__init__
(
""
,
[],
[])
self
.
headers
=
[
"<iostream>"
,
"foo"
]
class
OkNode3
(
CustomCodeNode
):
def
__init__
(
self
):
super
().
__init__
(
""
,
[],
[])
self
.
headers
=
[
"<iostream>"
,
'"foo"'
]
with
pytest
.
raises
(
AssertionError
,
match
=
'.* does not follow the pattern .*'
):
get_headers
(
Block
([
ErrorNode1
()]))
with
pytest
.
raises
(
AssertionError
,
match
=
'.* does not follow the pattern .*'
):
get_headers
(
ErrorNode2
())
get_headers
(
OkNode3
())
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