From 81655776957b3a28270dad7798e5dd3c12d6f892 Mon Sep 17 00:00:00 2001 From: Michka Popoff Date: Sun, 8 Dec 2024 20:55:07 +0100 Subject: [PATCH] tests: fix macos tests Fix string replacement (broken due to space mismatches) --- pyproject.toml | 5 ++-- src/pygccxml/declarations/container_traits.py | 21 ++++++++------- src/pygccxml/declarations/type_traits.py | 27 +++++++++++-------- 3 files changed, 31 insertions(+), 22 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index d966316d..9522d4ff 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -65,5 +65,6 @@ examples = [ "notebook", ] [tool.pytest.ini_options] - pythonpath = [ - "src"] \ No newline at end of file +pythonpath = [ + "src" +] diff --git a/src/pygccxml/declarations/container_traits.py b/src/pygccxml/declarations/container_traits.py index b2c4c104..0f8d1d61 100644 --- a/src/pygccxml/declarations/container_traits.py +++ b/src/pygccxml/declarations/container_traits.py @@ -19,6 +19,16 @@ std_namespaces = ('std', 'stdext', '__gnu_cxx') +# Take into account different equivalences (with or without spaces) +string_equivalences = type_traits.string_equivalences + \ + type_traits.normalized_string_equivalences +string_equivalences = [ + v for v in string_equivalences if not v == "std::string"] +wstring_equivalences = type_traits.wstring_equivalences + \ + type_traits.normalized_wstring_equivalences +wstring_equivalences = [ + v for v in wstring_equivalences if not v == "std::wstring"] + class defaults_eraser(object): @@ -29,16 +39,9 @@ def normalize(self, type_str): return type_str.replace(' ', '') def replace_basic_string(self, cls_name): - # Replace all the variations of strings by the smallest one. strings = { - "std::string": - [v for v in - type_traits.normalized_string_equivalences - if not v == "std::string"], - "std::wstring": - [v for v in - type_traits.normalized_wstring_equivalences - if not v == "std::wstring"] + "std::string": string_equivalences, + "std::wstring": wstring_equivalences } new_name = cls_name diff --git a/src/pygccxml/declarations/type_traits.py b/src/pygccxml/declarations/type_traits.py index 49aa6950..96766c32 100644 --- a/src/pygccxml/declarations/type_traits.py +++ b/src/pygccxml/declarations/type_traits.py @@ -481,7 +481,7 @@ def is_fundamental(type_): def _normalize(string): - return string.replace(' ', '').replace("::std", "std") + return string.replace(' ', '').replace('::std', 'std') def _normalize_equivalences(equivalences): @@ -490,29 +490,33 @@ def _normalize_equivalences(equivalences): string_equivalences = [ ( - '::std::basic_string, ' + 'std::basic_string, ' 'std::allocator>' ), - '::std::basic_string', - '::std::string' + 'std::basic_string', + 'std::string' ] wstring_equivalences = [ ( - '::std::basic_string, ' + 'std::basic_string, ' 'std::allocator>' ), - '::std::basic_string', - '::std::wstring' + 'std::basic_string', + 'std::wstring' ] ostream_equivalences = [ - '::std::basic_ostream>', - '::std::basic_ostream', '::std::ostream'] + 'std::basic_ostream>', + 'std::basic_ostream', + 'std::ostream' + ] wostream_equivalences = [ - '::std::basic_ostream>', - '::std::basic_ostream', '::std::wostream'] + 'std::basic_ostream>', + 'std::basic_ostream', + 'std::wostream' + ] normalized_string_equivalences = _normalize_equivalences( @@ -541,6 +545,7 @@ def is_std_string(type_): type_ = remove_alias(type_) type_ = remove_reference(type_) type_ = remove_cv(type_) + return _normalize(type_.decl_string) in normalized_string_equivalences