Skip to content

Commit

Permalink
tests: fix macos tests
Browse files Browse the repository at this point in the history
Fix string replacement (broken due to space mismatches)
  • Loading branch information
iMichka committed Dec 14, 2024
1 parent 682dc7e commit 8165577
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 22 deletions.
5 changes: 3 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,6 @@ examples = [
"notebook",
]
[tool.pytest.ini_options]
pythonpath = [
"src"]
pythonpath = [
"src"
]
21 changes: 12 additions & 9 deletions src/pygccxml/declarations/container_traits.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):

Expand All @@ -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
Expand Down
27 changes: 16 additions & 11 deletions src/pygccxml/declarations/type_traits.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -490,29 +490,33 @@ def _normalize_equivalences(equivalences):

string_equivalences = [
(
'::std::basic_string<char, std::char_traits<char>, '
'std::basic_string<char, std::char_traits<char>, '
'std::allocator<char>>'
),
'::std::basic_string<char>',
'::std::string'
'std::basic_string<char>',
'std::string'
]

wstring_equivalences = [
(
'::std::basic_string<wchar_t, std::char_traits<wchar_t>, '
'std::basic_string<wchar_t, std::char_traits<wchar_t>, '
'std::allocator<wchar_t>>'
),
'::std::basic_string<wchar_t>',
'::std::wstring'
'std::basic_string<wchar_t>',
'std::wstring'
]

ostream_equivalences = [
'::std::basic_ostream<char, std::char_traits<char>>',
'::std::basic_ostream<char>', '::std::ostream']
'std::basic_ostream<char, std::char_traits<char>>',
'std::basic_ostream<char>',
'std::ostream'
]

wostream_equivalences = [
'::std::basic_ostream<wchar_t, std::char_traits<wchar_t>>',
'::std::basic_ostream<wchar_t>', '::std::wostream']
'std::basic_ostream<wchar_t, std::char_traits<wchar_t>>',
'std::basic_ostream<wchar_t>',
'std::wostream'
]


normalized_string_equivalences = _normalize_equivalences(
Expand Down Expand Up @@ -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


Expand Down

0 comments on commit 8165577

Please sign in to comment.