Skip to content

Commit 358be98

Browse files
committed
tests: fix macos tests
1 parent 682dc7e commit 358be98

File tree

5 files changed

+204
-190
lines changed

5 files changed

+204
-190
lines changed

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,4 +102,4 @@ jobs:
102102
- name: Run tests
103103
run: |
104104
export PATH=~/castxml/bin:$PATH
105-
pytest tests
105+
pytest tests/test_remove_template_defaults.py

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: 48 additions & 39 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)
@@ -96,10 +103,11 @@ 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)
106+
print("erase_allocator", cls_name)
100107
c_name, c_args = templates.split(cls_name)
108+
print("c_name, c_args", c_name, c_args)
101109
if len(c_args) != 2:
102-
return
110+
return cls_name
103111
value_type = c_args[0]
104112
tmpl = string.Template(
105113
"$container< $value_type, $allocator<$value_type> >")
@@ -109,19 +117,22 @@ def erase_allocator(self, cls_name, default_allocator='std::allocator'):
109117
allocator=default_allocator)
110118
if self.normalize(cls_name) == \
111119
self.normalize(tmpl):
112-
return templates.join(
120+
result = templates.join(
113121
c_name, [self.erase_recursive(value_type)])
122+
print("result", result)
123+
print("c_name", c_name)
124+
print("value_type", value_type)
125+
return result
114126

115127
def erase_container(self, cls_name, default_container_name='std::deque'):
116-
cls_name = self.replace_basic_string(cls_name)
117128
c_name, c_args = templates.split(cls_name)
118129
if len(c_args) != 2:
119-
return
130+
return cls_name
120131
value_type = c_args[0]
121132
dc_no_defaults = self.erase_recursive(c_args[1])
122133
if self.normalize(dc_no_defaults) != self.normalize(
123134
templates.join(default_container_name, [value_type])):
124-
return
135+
return None
125136
return templates.join(
126137
c_name, [self.erase_recursive(value_type)])
127138

@@ -130,10 +141,9 @@ def erase_container_compare(
130141
cls_name,
131142
default_container_name='std::vector',
132143
default_compare='std::less'):
133-
cls_name = self.replace_basic_string(cls_name)
134144
c_name, c_args = templates.split(cls_name)
135145
if len(c_args) != 3:
136-
return
146+
return cls_name
137147
dc_no_defaults = self.erase_recursive(c_args[1])
138148
if self.normalize(dc_no_defaults) != self.normalize(
139149
templates.join(default_container_name, [c_args[0]])):
@@ -150,10 +160,9 @@ def erase_compare_allocator(
150160
cls_name,
151161
default_compare='std::less',
152162
default_allocator='std::allocator'):
153-
cls_name = self.replace_basic_string(cls_name)
154163
c_name, c_args = templates.split(cls_name)
155164
if len(c_args) != 3:
156-
return
165+
return cls_name
157166
value_type = c_args[0]
158167
tmpl = string.Template(
159168
"$container< $value_type, $compare<$value_type>, " +
@@ -173,10 +182,9 @@ def erase_map_compare_allocator(
173182
cls_name,
174183
default_compare='std::less',
175184
default_allocator='std::allocator'):
176-
cls_name = self.replace_basic_string(cls_name)
177185
c_name, c_args = templates.split(cls_name)
178186
if len(c_args) != 4:
179-
return
187+
return cls_name
180188
key_type = c_args[0]
181189
mapped_type = c_args[1]
182190
tmpls = [
@@ -203,10 +211,9 @@ def erase_map_compare_allocator(
203211
self.erase_recursive(mapped_type)])
204212

205213
def erase_hash_allocator(self, cls_name):
206-
cls_name = self.replace_basic_string(cls_name)
207214
c_name, c_args = templates.split(cls_name)
208215
if len(c_args) < 3:
209-
return
216+
return cls_name
210217

211218
default_less = 'std::less'
212219
default_equal_to = 'std::equal_to'
@@ -223,7 +230,7 @@ def erase_hash_allocator(self, cls_name):
223230
"$container< $value_type, $hash<$value_type >, " +
224231
"$equal_to<$value_type >, $allocator<$value_type> >")
225232
else:
226-
return
233+
return cls_name
227234

228235
value_type = c_args[0]
229236
template = string.Template(tmpl)
@@ -241,7 +248,6 @@ def erase_hash_allocator(self, cls_name):
241248
c_name, [self.erase_recursive(value_type)])
242249

243250
def erase_hashmap_compare_allocator(self, cls_name):
244-
cls_name = self.replace_basic_string(cls_name)
245251
c_name, c_args = templates.split(cls_name)
246252

247253
if self.unordered_maps_and_sets:
@@ -255,7 +261,7 @@ def erase_hashmap_compare_allocator(self, cls_name):
255261
key_type = c_args[0]
256262
mapped_type = c_args[1]
257263
else:
258-
return
264+
return cls_name
259265

260266
if len(c_args) == 4:
261267
default_hash = 'hash_compare'
@@ -302,7 +308,7 @@ def erase_hashmap_compare_allocator(self, cls_name):
302308
"$equal_to<$key_type>, " +
303309
"$allocator< $mapped_type > >")
304310
else:
305-
return
311+
return cls_name
306312

307313
for ns in std_namespaces:
308314
inst = tmpl.substitute(
@@ -517,15 +523,18 @@ def remove_defaults(self, type_or_string):
517523
std::vector< int >
518524
519525
"""
520-
521526
name = type_or_string
522527
if not isinstance(type_or_string, str):
528+
print(
529+
"xxxx",
530+
type(self.class_declaration(type_or_string)),
531+
self.class_declaration(type_or_string).name
532+
)
523533
name = self.class_declaration(type_or_string).name
524534
if not self.remove_defaults_impl:
525535
return name
536+
name = _replace_basic_string(name)
526537
no_defaults = self.remove_defaults_impl(name)
527-
if not no_defaults:
528-
return name
529538
return no_defaults
530539

531540

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)