Skip to content

Commit

Permalink
test: isolate tools for C tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mbdevpl committed Feb 15, 2025
1 parent ddc6104 commit d50105e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 13 deletions.
12 changes: 0 additions & 12 deletions test/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import collections.abc
import datetime
import io
import itertools
import os
import pathlib
Expand All @@ -14,7 +13,6 @@

import horast
import numpy as np
import pycparser.c_ast
# import static_typing as st
import typed_ast.ast3
import typed_astunparse
Expand Down Expand Up @@ -116,16 +114,6 @@ def make_tmp_folder(sub_path: pathlib.Path, input_path: pathlib.Path) -> pathlib
return output_dir


def c_ast_dump(node: pycparser.c_ast.Node) -> str:
io_ = io.StringIO()
node.show(io_, attrnames=True, nodenames=True, showcoord=True)
return io_.getvalue()


def basic_check_c_ast(case: unittest.TestCase, path, c_tree, **kwargs):
basic_check_ast(case, path, c_tree, pycparser.c_ast.FileAST, '.yaml', c_ast_dump, **kwargs)


def basic_check_cpp_code(case: unittest.TestCase, path, code, **kwargs):
basic_check_code(case, path, code, 'cpp14', **kwargs)

Expand Down
6 changes: 5 additions & 1 deletion test/test_c.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@
pass
from transpyle.general import AstGeneralizer, CodeReader, Parser

from .common import basic_check_c_ast, basic_check_python_ast, execute_on_language_examples
from .common import basic_check_python_ast, execute_on_language_examples
try:
from .tools_c import basic_check_c_ast
except ImportError:
pass

_LOG = logging.getLogger(__name__)

Expand Down
18 changes: 18 additions & 0 deletions test/tools_c.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
"""Tools for testing C language support."""

import io
import unittest

import pycparser.c_ast

from .common import basic_check_ast


def c_ast_dump(node: pycparser.c_ast.Node) -> str:
io_ = io.StringIO()
node.show(io_, attrnames=True, nodenames=True, showcoord=True)
return io_.getvalue()


def basic_check_c_ast(case: unittest.TestCase, path, c_tree, **kwargs):
basic_check_ast(case, path, c_tree, pycparser.c_ast.FileAST, '.yaml', c_ast_dump, **kwargs)

0 comments on commit d50105e

Please sign in to comment.