Skip to content

Commit 26c772a

Browse files
committed
macos: fix tests
Attempt to fix test by normalizing spaces in templates
1 parent 5f6f235 commit 26c772a

File tree

8 files changed

+107
-84
lines changed

8 files changed

+107
-84
lines changed

pyproject.toml

Lines changed: 4 additions & 0 deletions
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

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ def erase_allocator(self, cls_name, default_allocator='std::allocator'):
105105
return
106106
value_type = c_args[0]
107107
tmpl = string.Template(
108-
"$container< $value_type, $allocator<$value_type> >")
108+
"$container<$value_type, $allocator<$value_type>>")
109109
tmpl = tmpl.substitute(
110110
container=c_name,
111111
value_type=value_type,
@@ -159,8 +159,8 @@ def erase_compare_allocator(
159159
return
160160
value_type = c_args[0]
161161
tmpl = string.Template(
162-
"$container< $value_type, $compare<$value_type>, " +
163-
"$allocator<$value_type> >")
162+
"$container<$value_type, $compare<$value_type>, " +
163+
"$allocator<$value_type>>")
164164
tmpl = tmpl.substitute(
165165
container=c_name,
166166
value_type=value_type,
@@ -184,14 +184,14 @@ def erase_map_compare_allocator(
184184
mapped_type = c_args[1]
185185
tmpls = [
186186
string.Template(
187-
"$container< $key_type, $mapped_type, $compare<$key_type>, " +
188-
"$allocator< std::pair< const $key_type, $mapped_type> > >"),
187+
"$container<$key_type, $mapped_type, $compare<$key_type>, " +
188+
"$allocator<std::pair<const $key_type, $mapped_type>>>"),
189189
string.Template(
190-
"$container< $key_type, $mapped_type, $compare<$key_type>, " +
191-
"$allocator< std::pair< $key_type const, $mapped_type> > >"),
190+
"$container<$key_type, $mapped_type, $compare<$key_type>, " +
191+
"$allocator<std::pair<$key_type const, $mapped_type>>>"),
192192
string.Template(
193-
"$container< $key_type, $mapped_type, $compare<$key_type>, " +
194-
"$allocator< std::pair< $key_type, $mapped_type> > >")]
193+
"$container<$key_type, $mapped_type, $compare<$key_type>, " +
194+
"$allocator<std::pair<$key_type, $mapped_type>>>")]
195195
for tmpl in tmpls:
196196
tmpl = tmpl.substitute(
197197
container=c_name,
@@ -218,13 +218,13 @@ def erase_hash_allocator(self, cls_name):
218218
if len(c_args) == 3:
219219
default_hash = 'hash_compare'
220220
tmpl = (
221-
"$container< $value_type, $hash<$value_type, " +
222-
"$less<$value_type> >, $allocator<$value_type> >")
221+
"$container<$value_type, $hash<$value_type, " +
222+
"$less<$value_type>>, $allocator<$value_type>>")
223223
elif len(c_args) == 4:
224224
default_hash = 'hash'
225225
tmpl = (
226-
"$container< $value_type, $hash<$value_type >, " +
227-
"$equal_to<$value_type >, $allocator<$value_type> >")
226+
"$container<$value_type, $hash<$value_type>, " +
227+
"$equal_to<$value_type>, $allocator<$value_type>>")
228228
else:
229229
return
230230

@@ -263,14 +263,14 @@ def erase_hashmap_compare_allocator(self, cls_name):
263263
if len(c_args) == 4:
264264
default_hash = 'hash_compare'
265265
tmpl = string.Template(
266-
"$container< $key_type, $mapped_type, " +
267-
"$hash<$key_type, $less<$key_type> >, " +
268-
"$allocator< std::pair< const $key_type, $mapped_type> > >")
266+
"$container<$key_type, $mapped_type, " +
267+
"$hash<$key_type, $less<$key_type>>, " +
268+
"$allocator<std::pair<const $key_type, $mapped_type>>>")
269269
if key_type.startswith('const ') or key_type.endswith(' const'):
270270
tmpl = string.Template(
271-
"$container< $key_type, $mapped_type, $hash<$key_type, " +
272-
"$less<$key_type> >, $allocator< std::pair< $key_type, " +
273-
"$mapped_type> > >")
271+
"$container<$key_type, $mapped_type, $hash<$key_type, " +
272+
"$less<$key_type>>, $allocator<std::pair<$key_type, " +
273+
"$mapped_type>>>")
274274
elif len(c_args) == 5:
275275
default_hash = 'hash'
276276
if self.unordered_maps_and_sets:
@@ -279,31 +279,31 @@ def erase_hashmap_compare_allocator(self, cls_name):
279279
"$hash<$key_type>, " +
280280
"$equal_to<$key_type>, " +
281281
"$allocator<std::pair<const$key_type, " +
282-
"$mapped_type> > >")
282+
"$mapped_type>>>")
283283
if key_type.startswith('const ') or \
284284
key_type.endswith(' const'):
285285
tmpl = string.Template(
286286
"$container<$key_type, $mapped_type, " +
287-
"$hash<$key_type >, " +
288-
"$equal_to<$key_type >, " +
287+
"$hash<$key_type>, " +
288+
"$equal_to<$key_type>, " +
289289
"$allocator<std::pair<$key_type, " +
290-
"$mapped_type> > >")
290+
"$mapped_type>>>")
291291
else:
292292
tmpl = string.Template(
293-
"$container< $key_type, $mapped_type, "
294-
"$hash<$key_type >, " +
293+
"$container<$key_type, $mapped_type, "
294+
"$hash<$key_type>, " +
295295
"$equal_to<$key_type>, "
296-
"$allocator< $mapped_type> >")
296+
"$allocator<$mapped_type>>")
297297
if key_type.startswith('const ') or \
298298
key_type.endswith(' const'):
299299
# TODO: this template is the same than above.
300300
# Make sure why this was needed and if this is
301301
# tested. There may be a const missing somewhere.
302302
tmpl = string.Template(
303-
"$container< $key_type, $mapped_type, " +
304-
"$hash<$key_type >, " +
303+
"$container<$key_type, $mapped_type, " +
304+
"$hash<$key_type>, " +
305305
"$equal_to<$key_type>, " +
306-
"$allocator< $mapped_type > >")
306+
"$allocator<$mapped_type>>")
307307
else:
308308
return
309309

@@ -512,12 +512,12 @@ def remove_defaults(self, type_or_string):
512512
For example:
513513
.. code-block:: c++
514514
515-
std::vector< int, std::allocator< int > >
515+
std::vector<int, std::allocator<int>>
516516
517517
will become:
518518
.. code-block:: c++
519519
520-
std::vector< int >
520+
std::vector<int>
521521
522522
"""
523523

src/pygccxml/declarations/declaration.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,10 @@ def partial_name(self):
189189

190190
return self._partial_name
191191

192+
@partial_name.setter
193+
def partial_name(self, new_partial_name):
194+
self._partial_name = new_partial_name
195+
192196
@property
193197
def parent(self):
194198
"""

src/pygccxml/parser/patcher.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,3 +303,18 @@ def update_unnamed_class(decls):
303303
if referent.name or not isinstance(referent, declarations.class_t):
304304
continue
305305
referent.name = decl.name
306+
307+
308+
def remove_spaces_from_template_names(decls):
309+
"""
310+
Cleanup names that can have different spaces at different places.
311+
This depends on the compiler / platform, so just remove spaces.
312+
Examples:
313+
before hash<std::vector<int> >
314+
after hash<std::vector<int>>
315+
"""
316+
for decl in decls:
317+
if isinstance(decl, declarations.declaration_t):
318+
decl.name = decl.name.replace(" >", ">").replace("< ", "<")
319+
decl.partial_name = \
320+
decl.partial_name.replace(" >", ">").replace("< ", "<")

src/pygccxml/parser/source_reader.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,7 @@ def __parse_xml_file(self, xml_file):
420420
patcher.update_unnamed_class(decls.values())
421421
patcher.fix_calldef_decls(
422422
scanner_.calldefs(), scanner_.enums(), self.__cxx_std)
423+
patcher.remove_spaces_from_template_names(decls.values())
423424

424425
decls = [inst for inst in iter(decls.values()) if self.__check(inst)]
425426
return decls, list(files.values())

tests/test_find_container_traits.py

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ def __cmp_traits(global_ns, typedef, expected, partial_name, key_type=None):
3333
assert declarations.find_container_traits(cls) == expected
3434
assert cls.partial_name == partial_name
3535
cls = traits.class_declaration(cls)
36-
print("xxxx", traits, typedef)
3736
assert traits.element_type(typedef) is not None
3837
assert cls.cache.container_element_type is not None
3938

@@ -51,91 +50,91 @@ def test_find_traits(global_ns):
5150
global_ns,
5251
"v_int",
5352
declarations.vector_traits,
54-
"vector< int >"
53+
"vector<int>"
5554
)
5655
__cmp_traits(
5756
global_ns,
5857
"l_int",
5958
declarations.list_traits,
60-
"list< int >"
59+
"list<int>"
6160
)
6261
__cmp_traits(
6362
global_ns, "d_v_int",
6463
declarations.deque_traits,
65-
"deque< std::vector< int > >"
64+
"deque<std::vector<int>>"
6665
)
6766
__cmp_traits(
6867
global_ns, "q_int",
6968
declarations.queue_traits,
70-
"queue< int >"
69+
"queue<int>"
7170
)
7271
__cmp_traits(
7372
global_ns, "pq_int",
7473
declarations.priority_queue_traits,
75-
"priority_queue< int >"
74+
"priority_queue<int>"
7675
)
7776
__cmp_traits(
7877
global_ns, "s_v_int",
7978
declarations.set_traits,
80-
"set< std::vector< int > >"
79+
"set<std::vector<int>>"
8180
)
8281
__cmp_traits(
8382
global_ns,
8483
"ms_v_int",
8584
declarations.multiset_traits,
86-
"multiset< std::vector< int > >",
85+
"multiset<std::vector<int>>",
8786
)
8887
__cmp_traits(
8988
global_ns, "m_i2d",
9089
declarations.map_traits,
91-
"map< int, double >",
90+
"map<int, double>",
9291
"int"
9392
)
9493
__cmp_traits(
9594
global_ns,
9695
"mm_i2d",
9796
declarations.multimap_traits,
98-
"multimap< int, double >",
97+
"multimap<int, double>",
9998
"int",
10099
)
101100
__cmp_traits(
102101
global_ns,
103102
"hs_v_int",
104103
declarations.unordered_set_traits,
105-
"unordered_set< std::vector< int > >",
104+
"unordered_set<std::vector<int>>",
106105
)
107106
__cmp_traits(
108107
global_ns,
109108
"mhs_v_int",
110109
declarations.unordered_multiset_traits,
111-
"unordered_multiset< std::vector< int > >",
110+
"unordered_multiset<std::vector<int>>",
112111
)
113112
__cmp_traits(
114113
global_ns,
115114
"hm_i2d",
116115
declarations.unordered_map_traits,
117-
"unordered_map< int, double >",
116+
"unordered_map<int, double>",
118117
"int",
119118
)
120119
__cmp_traits(
121120
global_ns,
122121
"hmm_i2d",
123122
declarations.unordered_multimap_traits,
124-
"unordered_multimap< int, double >",
123+
"unordered_multimap<int, double>",
125124
"int",
126125
)
127126

128127

129128
def test_multimap(global_ns):
130129
m = global_ns.class_(lambda decl: decl.name.startswith("multimap"))
131130
declarations.find_container_traits(m)
132-
assert m.partial_name == "multimap< int, int >"
131+
assert m.partial_name == "multimap<int, int>"
133132

134133

135134
def test_recursive_partial_name(global_ns):
136135
f1 = global_ns.free_function("f1")
137136
t1 = declarations.class_traits.get_declaration(f1.arguments[0].decl_type)
138-
assert "type< std::set< std::vector< int > > >" == t1.partial_name
137+
assert "type<std::set<std::vector<int>>>" == t1.partial_name
139138

140139

141140
def test_remove_defaults_partial_name_namespace(global_ns):

0 commit comments

Comments
 (0)