From 9d23c2a931cc8c66d50f4379bddbce163f2f5652 Mon Sep 17 00:00:00 2001 From: Michka Popoff Date: Mon, 13 Jan 2025 22:42:05 +0100 Subject: [PATCH] test: debug test --- .github/workflows/tests.yml | 2 +- pyproject.toml | 2 + src/pygccxml/declarations/container_traits.py | 3 + .../declarations/traits_impl_details.py | 4 + tests/test_vector_traits.py | 101 +++++++++--------- 5 files changed, 63 insertions(+), 49 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index a3b5f842..45fff43b 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -102,4 +102,4 @@ jobs: - name: Run tests run: | export PATH=~/castxml/bin:$PATH - pytest tests + pytest tests/test_vector_traits.py diff --git a/pyproject.toml b/pyproject.toml index 8abdfac0..d0200c70 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -64,3 +64,5 @@ docs = [ examples = [ "notebook", ] +[tool.pytest.ini_options] + pythonpath = ["src"] \ No newline at end of file diff --git a/src/pygccxml/declarations/container_traits.py b/src/pygccxml/declarations/container_traits.py index 00463e57..174ebdd5 100644 --- a/src/pygccxml/declarations/container_traits.py +++ b/src/pygccxml/declarations/container_traits.py @@ -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): @@ -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." % diff --git a/src/pygccxml/declarations/traits_impl_details.py b/src/pygccxml/declarations/traits_impl_details.py index b9fce594..87f5ed58 100644 --- a/src/pygccxml/declarations/traits_impl_details.py +++ b/src/pygccxml/declarations/traits_impl_details.py @@ -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: diff --git a/tests/test_vector_traits.py b/tests/test_vector_traits.py index 1e16a407..7c477e74 100644 --- a/tests/test_vector_traits.py +++ b/tests/test_vector_traits.py @@ -15,6 +15,10 @@ "vector_traits.hpp", ] +# import logging +# from pygccxml import utils +# utils.loggers.set_level(logging.DEBUG) + @pytest.fixture def global_ns(): @@ -30,54 +34,54 @@ 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::allocator>,std::allocator, std::allocator>>>' + - '@::std::vector, ' + - 'std::allocator>, std::allocator, std::allocator>>>') - 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::allocator>,std::allocator, std::allocator>>>' + +# '@::std::vector, ' + +# 'std::allocator>, std::allocator, std::allocator>>>') +# traits = declarations.find_container_traits(cnt) +# assert declarations.vector_traits == traits def test_element_type(global_ns): @@ -85,4 +89,5 @@ def test_element_type(global_ns): v = declarations.remove_reference( declarations.remove_declarated( do_nothing.arguments[0].decl_type)) + print("v", v) declarations.vector_traits.element_type(v)