Skip to content

Commit 42706c9

Browse files
committed
tests: fix macos tests
1 parent aa563e6 commit 42706c9

File tree

5 files changed

+177
-156
lines changed

5 files changed

+177
-156
lines changed

.github/workflows/tests.yml

+1-1
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

+4
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,7 @@ docs = [
6464
examples = [
6565
"notebook",
6666
]
67+
[tool.pytest.ini_options]
68+
pythonpath = [
69+
"src"
70+
]

src/pygccxml/declarations/container_traits.py

+21-14
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def normalize(self, type_str):
2929
return type_str.replace(' ', '')
3030

3131
def replace_basic_string(self, cls_name):
32-
32+
print("replace_basic_string", cls_name)
3333
# Take the lists of all possible string variations
3434
# and clean them up by replacing ::std by std.
3535
str_eq = [
@@ -99,10 +99,13 @@ def erase_recursive(self, cls_name):
9999
return self.no_end_const(cls_name)
100100

101101
def erase_allocator(self, cls_name, default_allocator='std::allocator'):
102+
print("erase_allocator", cls_name)
102103
cls_name = self.replace_basic_string(cls_name)
104+
print("erase_allocator", cls_name)
103105
c_name, c_args = templates.split(cls_name)
106+
print("c_name, c_args", c_name, c_args)
104107
if len(c_args) != 2:
105-
return
108+
return None
106109
value_type = c_args[0]
107110
tmpl = string.Template(
108111
"$container< $value_type, $allocator<$value_type> >")
@@ -112,19 +115,24 @@ def erase_allocator(self, cls_name, default_allocator='std::allocator'):
112115
allocator=default_allocator)
113116
if self.normalize(cls_name) == \
114117
self.normalize(tmpl):
115-
return templates.join(
118+
result = templates.join(
116119
c_name, [self.erase_recursive(value_type)])
120+
print("result", result)
121+
print("c_name", c_name)
122+
print("value_type", value_type)
123+
print("erase", self.erase_recursive(value_type))
124+
return result
117125

118126
def erase_container(self, cls_name, default_container_name='std::deque'):
119127
cls_name = self.replace_basic_string(cls_name)
120128
c_name, c_args = templates.split(cls_name)
121129
if len(c_args) != 2:
122-
return
130+
return cls_name
123131
value_type = c_args[0]
124132
dc_no_defaults = self.erase_recursive(c_args[1])
125133
if self.normalize(dc_no_defaults) != self.normalize(
126134
templates.join(default_container_name, [value_type])):
127-
return
135+
return cls_name
128136
return templates.join(
129137
c_name, [self.erase_recursive(value_type)])
130138

@@ -136,7 +144,7 @@ def erase_container_compare(
136144
cls_name = self.replace_basic_string(cls_name)
137145
c_name, c_args = templates.split(cls_name)
138146
if len(c_args) != 3:
139-
return
147+
return cls_name
140148
dc_no_defaults = self.erase_recursive(c_args[1])
141149
if self.normalize(dc_no_defaults) != self.normalize(
142150
templates.join(default_container_name, [c_args[0]])):
@@ -156,7 +164,7 @@ def erase_compare_allocator(
156164
cls_name = self.replace_basic_string(cls_name)
157165
c_name, c_args = templates.split(cls_name)
158166
if len(c_args) != 3:
159-
return
167+
return cls_name
160168
value_type = c_args[0]
161169
tmpl = string.Template(
162170
"$container< $value_type, $compare<$value_type>, " +
@@ -179,7 +187,7 @@ def erase_map_compare_allocator(
179187
cls_name = self.replace_basic_string(cls_name)
180188
c_name, c_args = templates.split(cls_name)
181189
if len(c_args) != 4:
182-
return
190+
return cls_name
183191
key_type = c_args[0]
184192
mapped_type = c_args[1]
185193
tmpls = [
@@ -209,7 +217,7 @@ def erase_hash_allocator(self, cls_name):
209217
cls_name = self.replace_basic_string(cls_name)
210218
c_name, c_args = templates.split(cls_name)
211219
if len(c_args) < 3:
212-
return
220+
return cls_name
213221

214222
default_less = 'std::less'
215223
default_equal_to = 'std::equal_to'
@@ -226,7 +234,7 @@ def erase_hash_allocator(self, cls_name):
226234
"$container< $value_type, $hash<$value_type >, " +
227235
"$equal_to<$value_type >, $allocator<$value_type> >")
228236
else:
229-
return
237+
return cls_name
230238

231239
value_type = c_args[0]
232240
template = string.Template(tmpl)
@@ -258,7 +266,7 @@ def erase_hashmap_compare_allocator(self, cls_name):
258266
key_type = c_args[0]
259267
mapped_type = c_args[1]
260268
else:
261-
return
269+
return cls_name
262270

263271
if len(c_args) == 4:
264272
default_hash = 'hash_compare'
@@ -305,7 +313,7 @@ def erase_hashmap_compare_allocator(self, cls_name):
305313
"$equal_to<$key_type>, " +
306314
"$allocator< $mapped_type > >")
307315
else:
308-
return
316+
return cls_name
309317

310318
for ns in std_namespaces:
311319
inst = tmpl.substitute(
@@ -520,14 +528,13 @@ def remove_defaults(self, type_or_string):
520528
std::vector< int >
521529
522530
"""
523-
524531
name = type_or_string
525532
if not isinstance(type_or_string, str):
526533
name = self.class_declaration(type_or_string).name
527534
if not self.remove_defaults_impl:
528535
return name
529536
no_defaults = self.remove_defaults_impl(name)
530-
if not no_defaults:
537+
if no_defaults is None:
531538
return name
532539
return no_defaults
533540

src/pygccxml/declarations/type_traits.py

+14-4
Original file line numberDiff line numberDiff line change
@@ -481,23 +481,33 @@ def is_fundamental(type_):
481481

482482

483483
string_equivalences = [
484+
# (
485+
# 'std::basic_string<char, std::char_traits<char>, '
486+
# 'std::allocator<char>>, '
487+
# 'std::allocator<std::basic_string<'
488+
# 'char, std::char_traits<char>, std::allocator<char>>>'),
484489
(
485-
'::std::basic_string<char,std::char_traits<char>,'
490+
'::std::basic_string<char, std::char_traits<char>, '
486491
'std::allocator<char>>'),
487492
'::std::basic_string<char>', '::std::string']
488493

489494
wstring_equivalences = [
490495
(
491-
'::std::basic_string<wchar_t,std::char_traits<wchar_t>,' +
496+
'std::basic_string<wchar_t, std::char_traits<wchar_t>, '
497+
'std::allocator<wchar_t>>, '
498+
'std::allocator<std::basic_string<'
499+
'wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t>>>'),
500+
(
501+
'::std::basic_string<wchar_t, std::char_traits<wchar_t>, '
492502
'std::allocator<wchar_t>>'),
493503
'::std::basic_string<wchar_t>', '::std::wstring']
494504

495505
ostream_equivalences = [
496-
'::std::basic_ostream<char,std::char_traits<char>>',
506+
'::std::basic_ostream<char std::char_traits<char>>',
497507
'::std::basic_ostream<char>', '::std::ostream']
498508

499509
wostream_equivalences = [
500-
'::std::basic_ostream<wchar_t,std::char_traits<wchar_t>>',
510+
'::std::basic_ostream<wchar_t, std::char_traits<wchar_t>>',
501511
'::std::basic_ostream<wchar_t>', '::std::wostream']
502512

503513

0 commit comments

Comments
 (0)