Skip to content

Commit 288956e

Browse files
committed
tests: fix macos tests
1 parent 682dc7e commit 288956e

File tree

5 files changed

+201
-190
lines changed

5 files changed

+201
-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: 45 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,27 @@
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 + type_traits.normalized_string_equivalences
24+
string_equivalences = [v for v in string_equivalences if not v == "std::string"]
25+
wstring_equivalences = type_traits.wstring_equivalences + type_traits.normalized_wstring_equivalences
26+
wstring_equivalences = [v for v in wstring_equivalences if not v == "std::wstring"]
27+
28+
29+
def _replace_basic_string(cls_name):
30+
31+
strings = {
32+
"std::string": string_equivalences,
33+
"std::wstring": wstring_equivalences
34+
}
35+
36+
new_name = cls_name
37+
for short_name, long_names in strings.items():
38+
for lname in long_names:
39+
new_name = new_name.replace(lname, short_name)
40+
41+
return new_name
42+
2243

2344
class defaults_eraser(object):
2445

@@ -29,24 +50,7 @@ def normalize(self, type_str):
2950
return type_str.replace(' ', '')
3051

3152
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
53+
return _replace_basic_string(cls_name)
5054

5155
def decorated_call_prefix(self, cls_name, text, doit):
5256
has_text = cls_name.startswith(text)
@@ -96,10 +100,11 @@ def erase_recursive(self, cls_name):
96100
return self.no_end_const(cls_name)
97101

98102
def erase_allocator(self, cls_name, default_allocator='std::allocator'):
99-
cls_name = self.replace_basic_string(cls_name)
103+
print("erase_allocator", cls_name)
100104
c_name, c_args = templates.split(cls_name)
105+
print("c_name, c_args", c_name, c_args)
101106
if len(c_args) != 2:
102-
return
107+
return cls_name
103108
value_type = c_args[0]
104109
tmpl = string.Template(
105110
"$container< $value_type, $allocator<$value_type> >")
@@ -109,19 +114,22 @@ def erase_allocator(self, cls_name, default_allocator='std::allocator'):
109114
allocator=default_allocator)
110115
if self.normalize(cls_name) == \
111116
self.normalize(tmpl):
112-
return templates.join(
117+
result = templates.join(
113118
c_name, [self.erase_recursive(value_type)])
119+
print("result", result)
120+
print("c_name", c_name)
121+
print("value_type", value_type)
122+
return result
114123

115124
def erase_container(self, cls_name, default_container_name='std::deque'):
116-
cls_name = self.replace_basic_string(cls_name)
117125
c_name, c_args = templates.split(cls_name)
118126
if len(c_args) != 2:
119-
return
127+
return cls_name
120128
value_type = c_args[0]
121129
dc_no_defaults = self.erase_recursive(c_args[1])
122130
if self.normalize(dc_no_defaults) != self.normalize(
123131
templates.join(default_container_name, [value_type])):
124-
return
132+
return None
125133
return templates.join(
126134
c_name, [self.erase_recursive(value_type)])
127135

@@ -130,10 +138,9 @@ def erase_container_compare(
130138
cls_name,
131139
default_container_name='std::vector',
132140
default_compare='std::less'):
133-
cls_name = self.replace_basic_string(cls_name)
134141
c_name, c_args = templates.split(cls_name)
135142
if len(c_args) != 3:
136-
return
143+
return cls_name
137144
dc_no_defaults = self.erase_recursive(c_args[1])
138145
if self.normalize(dc_no_defaults) != self.normalize(
139146
templates.join(default_container_name, [c_args[0]])):
@@ -150,10 +157,9 @@ def erase_compare_allocator(
150157
cls_name,
151158
default_compare='std::less',
152159
default_allocator='std::allocator'):
153-
cls_name = self.replace_basic_string(cls_name)
154160
c_name, c_args = templates.split(cls_name)
155161
if len(c_args) != 3:
156-
return
162+
return cls_name
157163
value_type = c_args[0]
158164
tmpl = string.Template(
159165
"$container< $value_type, $compare<$value_type>, " +
@@ -173,10 +179,9 @@ def erase_map_compare_allocator(
173179
cls_name,
174180
default_compare='std::less',
175181
default_allocator='std::allocator'):
176-
cls_name = self.replace_basic_string(cls_name)
177182
c_name, c_args = templates.split(cls_name)
178183
if len(c_args) != 4:
179-
return
184+
return cls_name
180185
key_type = c_args[0]
181186
mapped_type = c_args[1]
182187
tmpls = [
@@ -203,10 +208,9 @@ def erase_map_compare_allocator(
203208
self.erase_recursive(mapped_type)])
204209

205210
def erase_hash_allocator(self, cls_name):
206-
cls_name = self.replace_basic_string(cls_name)
207211
c_name, c_args = templates.split(cls_name)
208212
if len(c_args) < 3:
209-
return
213+
return cls_name
210214

211215
default_less = 'std::less'
212216
default_equal_to = 'std::equal_to'
@@ -223,7 +227,7 @@ def erase_hash_allocator(self, cls_name):
223227
"$container< $value_type, $hash<$value_type >, " +
224228
"$equal_to<$value_type >, $allocator<$value_type> >")
225229
else:
226-
return
230+
return cls_name
227231

228232
value_type = c_args[0]
229233
template = string.Template(tmpl)
@@ -241,7 +245,6 @@ def erase_hash_allocator(self, cls_name):
241245
c_name, [self.erase_recursive(value_type)])
242246

243247
def erase_hashmap_compare_allocator(self, cls_name):
244-
cls_name = self.replace_basic_string(cls_name)
245248
c_name, c_args = templates.split(cls_name)
246249

247250
if self.unordered_maps_and_sets:
@@ -255,7 +258,7 @@ def erase_hashmap_compare_allocator(self, cls_name):
255258
key_type = c_args[0]
256259
mapped_type = c_args[1]
257260
else:
258-
return
261+
return cls_name
259262

260263
if len(c_args) == 4:
261264
default_hash = 'hash_compare'
@@ -302,7 +305,7 @@ def erase_hashmap_compare_allocator(self, cls_name):
302305
"$equal_to<$key_type>, " +
303306
"$allocator< $mapped_type > >")
304307
else:
305-
return
308+
return cls_name
306309

307310
for ns in std_namespaces:
308311
inst = tmpl.substitute(
@@ -517,15 +520,18 @@ def remove_defaults(self, type_or_string):
517520
std::vector< int >
518521
519522
"""
520-
521523
name = type_or_string
522524
if not isinstance(type_or_string, str):
525+
print(
526+
"xxxx",
527+
type(self.class_declaration(type_or_string)),
528+
self.class_declaration(type_or_string).name
529+
)
523530
name = self.class_declaration(type_or_string).name
524531
if not self.remove_defaults_impl:
525532
return name
533+
name = _replace_basic_string(name)
526534
no_defaults = self.remove_defaults_impl(name)
527-
if not no_defaults:
528-
return name
529535
return no_defaults
530536

531537

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)