Skip to content

Commit 835a5e2

Browse files
committed
tests: fix macos tests
1 parent 682dc7e commit 835a5e2

File tree

3 files changed

+45
-39
lines changed

3 files changed

+45
-39
lines changed

pyproject.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,5 +65,6 @@ examples = [
6565
"notebook",
6666
]
6767
[tool.pytest.ini_options]
68-
pythonpath = [
69-
"src"]
68+
pythonpath = [
69+
"src"
70+
]

src/pygccxml/declarations/container_traits.py

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,30 @@
1919

2020
std_namespaces = ('std', 'stdext', '__gnu_cxx')
2121

22+
# Take into account different equivalences (with or without spaces)
23+
string_equivalences = type_traits.string_equivalences + \
24+
type_traits.normalized_string_equivalences
25+
string_equivalences = [
26+
v for v in string_equivalences if not v == "std::string"]
27+
wstring_equivalences = type_traits.wstring_equivalences + \
28+
type_traits.normalized_wstring_equivalences
29+
wstring_equivalences = [
30+
v for v in wstring_equivalences if not v == "std::wstring"]
31+
32+
33+
def _replace_basic_string(cls_name):
34+
strings = {
35+
"std::string": string_equivalences,
36+
"std::wstring": wstring_equivalences
37+
}
38+
39+
new_name = cls_name
40+
for short_name, long_names in strings.items():
41+
for lname in long_names:
42+
new_name = new_name.replace(lname, short_name)
43+
44+
return new_name
45+
2246

2347
class defaults_eraser(object):
2448

@@ -29,24 +53,7 @@ def normalize(self, type_str):
2953
return type_str.replace(' ', '')
3054

3155
def replace_basic_string(self, cls_name):
32-
# Replace all the variations of strings by the smallest one.
33-
strings = {
34-
"std::string":
35-
[v for v in
36-
type_traits.normalized_string_equivalences
37-
if not v == "std::string"],
38-
"std::wstring":
39-
[v for v in
40-
type_traits.normalized_wstring_equivalences
41-
if not v == "std::wstring"]
42-
}
43-
44-
new_name = cls_name
45-
for short_name, long_names in strings.items():
46-
for lname in long_names:
47-
new_name = new_name.replace(lname, short_name)
48-
49-
return new_name
56+
return _replace_basic_string(cls_name)
5057

5158
def decorated_call_prefix(self, cls_name, text, doit):
5259
has_text = cls_name.startswith(text)
@@ -69,7 +76,7 @@ def decorated_call_suffix(self, cls_name, text, doit):
6976
def erase_call(self, cls_name):
7077
c_traits = find_container_traits(cls_name)
7178
if not c_traits:
72-
return cls_name
79+
return
7380
return c_traits.remove_defaults(cls_name)
7481

7582
def no_std(self, cls_name):
@@ -96,7 +103,6 @@ def erase_recursive(self, cls_name):
96103
return self.no_end_const(cls_name)
97104

98105
def erase_allocator(self, cls_name, default_allocator='std::allocator'):
99-
cls_name = self.replace_basic_string(cls_name)
100106
c_name, c_args = templates.split(cls_name)
101107
if len(c_args) != 2:
102108
return
@@ -113,7 +119,6 @@ def erase_allocator(self, cls_name, default_allocator='std::allocator'):
113119
c_name, [self.erase_recursive(value_type)])
114120

115121
def erase_container(self, cls_name, default_container_name='std::deque'):
116-
cls_name = self.replace_basic_string(cls_name)
117122
c_name, c_args = templates.split(cls_name)
118123
if len(c_args) != 2:
119124
return
@@ -130,7 +135,6 @@ def erase_container_compare(
130135
cls_name,
131136
default_container_name='std::vector',
132137
default_compare='std::less'):
133-
cls_name = self.replace_basic_string(cls_name)
134138
c_name, c_args = templates.split(cls_name)
135139
if len(c_args) != 3:
136140
return
@@ -150,7 +154,6 @@ def erase_compare_allocator(
150154
cls_name,
151155
default_compare='std::less',
152156
default_allocator='std::allocator'):
153-
cls_name = self.replace_basic_string(cls_name)
154157
c_name, c_args = templates.split(cls_name)
155158
if len(c_args) != 3:
156159
return
@@ -173,7 +176,6 @@ def erase_map_compare_allocator(
173176
cls_name,
174177
default_compare='std::less',
175178
default_allocator='std::allocator'):
176-
cls_name = self.replace_basic_string(cls_name)
177179
c_name, c_args = templates.split(cls_name)
178180
if len(c_args) != 4:
179181
return
@@ -203,7 +205,6 @@ def erase_map_compare_allocator(
203205
self.erase_recursive(mapped_type)])
204206

205207
def erase_hash_allocator(self, cls_name):
206-
cls_name = self.replace_basic_string(cls_name)
207208
c_name, c_args = templates.split(cls_name)
208209
if len(c_args) < 3:
209210
return
@@ -241,7 +242,6 @@ def erase_hash_allocator(self, cls_name):
241242
c_name, [self.erase_recursive(value_type)])
242243

243244
def erase_hashmap_compare_allocator(self, cls_name):
244-
cls_name = self.replace_basic_string(cls_name)
245245
c_name, c_args = templates.split(cls_name)
246246

247247
if self.unordered_maps_and_sets:
@@ -523,6 +523,7 @@ def remove_defaults(self, type_or_string):
523523
name = self.class_declaration(type_or_string).name
524524
if not self.remove_defaults_impl:
525525
return name
526+
name = _replace_basic_string(name)
526527
no_defaults = self.remove_defaults_impl(name)
527528
if not no_defaults:
528529
return name

src/pygccxml/declarations/type_traits.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ def is_fundamental(type_):
481481

482482

483483
def _normalize(string):
484-
return string.replace(' ', '').replace("::std", "std")
484+
return string.replace(' ', '')
485485

486486

487487
def _normalize_equivalences(equivalences):
@@ -490,29 +490,33 @@ def _normalize_equivalences(equivalences):
490490

491491
string_equivalences = [
492492
(
493-
'::std::basic_string<char, std::char_traits<char>, '
493+
'std::basic_string<char, std::char_traits<char>, '
494494
'std::allocator<char>>'
495495
),
496-
'::std::basic_string<char>',
497-
'::std::string'
496+
'std::basic_string<char>',
497+
'std::string'
498498
]
499499

500500
wstring_equivalences = [
501501
(
502-
'::std::basic_string<wchar_t, std::char_traits<wchar_t>, '
502+
'std::basic_string<wchar_t, std::char_traits<wchar_t>, '
503503
'std::allocator<wchar_t>>'
504504
),
505-
'::std::basic_string<wchar_t>',
506-
'::std::wstring'
505+
'std::basic_string<wchar_t>',
506+
'std::wstring'
507507
]
508508

509509
ostream_equivalences = [
510-
'::std::basic_ostream<char, std::char_traits<char>>',
511-
'::std::basic_ostream<char>', '::std::ostream']
510+
'std::basic_ostream<char, std::char_traits<char>>',
511+
'std::basic_ostream<char>',
512+
'std::ostream'
513+
]
512514

513515
wostream_equivalences = [
514-
'::std::basic_ostream<wchar_t, std::char_traits<wchar_t>>',
515-
'::std::basic_ostream<wchar_t>', '::std::wostream']
516+
'std::basic_ostream<wchar_t, std::char_traits<wchar_t>>',
517+
'std::basic_ostream<wchar_t>',
518+
'std::wostream'
519+
]
516520

517521

518522
normalized_string_equivalences = _normalize_equivalences(

0 commit comments

Comments
 (0)