Skip to content

Commit d50105e

Browse files
committed
test: isolate tools for C tests
1 parent ddc6104 commit d50105e

File tree

3 files changed

+23
-13
lines changed

3 files changed

+23
-13
lines changed

test/common.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import collections.abc
44
import datetime
5-
import io
65
import itertools
76
import os
87
import pathlib
@@ -14,7 +13,6 @@
1413

1514
import horast
1615
import numpy as np
17-
import pycparser.c_ast
1816
# import static_typing as st
1917
import typed_ast.ast3
2018
import typed_astunparse
@@ -116,16 +114,6 @@ def make_tmp_folder(sub_path: pathlib.Path, input_path: pathlib.Path) -> pathlib
116114
return output_dir
117115

118116

119-
def c_ast_dump(node: pycparser.c_ast.Node) -> str:
120-
io_ = io.StringIO()
121-
node.show(io_, attrnames=True, nodenames=True, showcoord=True)
122-
return io_.getvalue()
123-
124-
125-
def basic_check_c_ast(case: unittest.TestCase, path, c_tree, **kwargs):
126-
basic_check_ast(case, path, c_tree, pycparser.c_ast.FileAST, '.yaml', c_ast_dump, **kwargs)
127-
128-
129117
def basic_check_cpp_code(case: unittest.TestCase, path, code, **kwargs):
130118
basic_check_code(case, path, code, 'cpp14', **kwargs)
131119

test/test_c.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@
1616
pass
1717
from transpyle.general import AstGeneralizer, CodeReader, Parser
1818

19-
from .common import basic_check_c_ast, basic_check_python_ast, execute_on_language_examples
19+
from .common import basic_check_python_ast, execute_on_language_examples
20+
try:
21+
from .tools_c import basic_check_c_ast
22+
except ImportError:
23+
pass
2024

2125
_LOG = logging.getLogger(__name__)
2226

test/tools_c.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
"""Tools for testing C language support."""
2+
3+
import io
4+
import unittest
5+
6+
import pycparser.c_ast
7+
8+
from .common import basic_check_ast
9+
10+
11+
def c_ast_dump(node: pycparser.c_ast.Node) -> str:
12+
io_ = io.StringIO()
13+
node.show(io_, attrnames=True, nodenames=True, showcoord=True)
14+
return io_.getvalue()
15+
16+
17+
def basic_check_c_ast(case: unittest.TestCase, path, c_tree, **kwargs):
18+
basic_check_ast(case, path, c_tree, pycparser.c_ast.FileAST, '.yaml', c_ast_dump, **kwargs)

0 commit comments

Comments
 (0)