Skip to content

Commit

Permalink
test: debug test
Browse files Browse the repository at this point in the history
  • Loading branch information
iMichka committed Jan 13, 2025
1 parent 4beedf5 commit 9d23c2a
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 49 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,4 @@ jobs:
- name: Run tests
run: |
export PATH=~/castxml/bin:$PATH
pytest tests
pytest tests/test_vector_traits.py
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,5 @@ docs = [
examples = [
"notebook",
]
[tool.pytest.ini_options]
pythonpath = ["src"]
3 changes: 3 additions & 0 deletions src/pygccxml/declarations/container_traits.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,7 @@ def __find_xxx_type(
xxx_typedef,
cache_property_name):
cls_declaration = self.class_declaration(type_)
print(cls_declaration, cls_declaration.top_parent)
result = getattr(cls_declaration.cache, cache_property_name)
if not result:
if isinstance(cls_declaration, class_declaration.class_t):
Expand All @@ -475,8 +476,10 @@ def __find_xxx_type(
result = type_traits.remove_declarated(xxx_type)
else:
xxx_type_str = templates.args(cls_declaration.name)[xxx_index]
print("xxx_type_str", xxx_type_str)
result = traits_impl_details.impl_details.find_value_type(
cls_declaration.top_parent, xxx_type_str)
print("result", result)
if None is result:
raise RuntimeError(
"Unable to find out %s '%s' key\\value type." %
Expand Down
4 changes: 4 additions & 0 deletions src/pygccxml/declarations/traits_impl_details.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,16 @@ def is_defined_in_xxx(xxx, cls):
@staticmethod
def find_value_type(global_ns, value_type_str):
"""implementation details"""
print("find_value_type", value_type_str)
if not value_type_str.startswith('::'):
value_type_str = '::' + value_type_str
found = global_ns.decls(
name=value_type_str,
function=lambda decl: not isinstance(decl, calldef.calldef_t),
allow_empty=True)
print("xxx", found, len(found))
for d in found:
print("found", d)
if not found:
no_global_ns_value_type_str = value_type_str[2:]
if no_global_ns_value_type_str in cpptypes.FUNDAMENTAL_TYPES:
Expand Down
101 changes: 53 additions & 48 deletions tests/test_vector_traits.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
"vector_traits.hpp",
]

# import logging
# from pygccxml import utils
# utils.loggers.set_level(logging.DEBUG)


@pytest.fixture
def global_ns():
Expand All @@ -30,59 +34,60 @@ def global_ns():
return global_ns


def validate_yes(value_type, container):
traits = declarations.vector_traits
assert traits.is_my_case(container) is True
assert declarations.is_same(
value_type,
traits.element_type(container)) is True
assert traits.is_sequence(container) is True


def test_global_ns(global_ns):
value_type = global_ns.class_('_0_')
container = global_ns.typedef('container', recursive=False)
validate_yes(value_type, container)


def test_yes(global_ns):
yes_ns = global_ns.namespace('yes')
for struct in yes_ns.classes():
if not struct.name.startswith('_'):
continue
if not struct.name.endswith('_'):
continue
validate_yes(
struct.typedef('value_type'),
struct.typedef('container'))


def test_no(global_ns):
traits = declarations.vector_traits
no_ns = global_ns.namespace('no')
for struct in no_ns.classes():
if not struct.name.startswith('_'):
continue
if not struct.name.endswith('_'):
continue
assert traits.is_my_case(struct.typedef('container')) is False


def test_declaration():
cnt = (
'std::vector<std::basic_string<char, std::char_traits<char>, ' +
'std::allocator<char>>,std::allocator<std::basic_string<char, ' +
'std::char_traits<char>, std::allocator<char>>>>' +
'@::std::vector<std::basic_string<char, std::char_traits<char>, ' +
'std::allocator<char>>, std::allocator<std::basic_string<char, ' +
'std::char_traits<char>, std::allocator<char>>>>')
traits = declarations.find_container_traits(cnt)
assert declarations.vector_traits == traits
# def validate_yes(value_type, container):
# traits = declarations.vector_traits
# assert traits.is_my_case(container) is True
# assert declarations.is_same(
# value_type,
# traits.element_type(container)) is True
# assert traits.is_sequence(container) is True


# def test_global_ns(global_ns):
# value_type = global_ns.class_('_0_')
# container = global_ns.typedef('container', recursive=False)
# validate_yes(value_type, container)


# def test_yes(global_ns):
# yes_ns = global_ns.namespace('yes')
# for struct in yes_ns.classes():
# if not struct.name.startswith('_'):
# continue
# if not struct.name.endswith('_'):
# continue
# validate_yes(
# struct.typedef('value_type'),
# struct.typedef('container'))


# def test_no(global_ns):
# traits = declarations.vector_traits
# no_ns = global_ns.namespace('no')
# for struct in no_ns.classes():
# if not struct.name.startswith('_'):
# continue
# if not struct.name.endswith('_'):
# continue
# assert traits.is_my_case(struct.typedef('container')) is False


# def test_declaration():
# cnt = (
# 'std::vector<std::basic_string<char, std::char_traits<char>, ' +
# 'std::allocator<char>>,std::allocator<std::basic_string<char, ' +
# 'std::char_traits<char>, std::allocator<char>>>>' +
# '@::std::vector<std::basic_string<char, std::char_traits<char>, ' +
# 'std::allocator<char>>, std::allocator<std::basic_string<char, ' +
# 'std::char_traits<char>, std::allocator<char>>>>')
# traits = declarations.find_container_traits(cnt)
# assert declarations.vector_traits == traits


def test_element_type(global_ns):
do_nothing = global_ns.free_function('do_nothing')
v = declarations.remove_reference(
declarations.remove_declarated(
do_nothing.arguments[0].decl_type))
print("v", v)
declarations.vector_traits.element_type(v)

0 comments on commit 9d23c2a

Please sign in to comment.