Skip to content

Commit f32b2da

Browse files
committed
macos: fix tests
Attempt to fix test by normalizing spaces in templates
1 parent ff5bfd2 commit f32b2da

File tree

6 files changed

+88
-70
lines changed

6 files changed

+88
-70
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/pattern_parser.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,11 +192,11 @@ def join(self, name, args, arg_separator=None):
192192
args = [_f for _f in args if _f]
193193

194194
if not args:
195-
args_str = ' '
195+
args_str = ''
196196
elif len(args) == 1:
197-
args_str = ' ' + args[0] + ' '
197+
args_str = '' + args[0] + ''
198198
else:
199-
args_str = ' ' + arg_separator.join(args) + ' '
199+
args_str = '' + arg_separator.join(args) + ''
200200

201201
return ''.join([name, self.__begin, args_str, self.__end])
202202

src/pygccxml/parser/patcher.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,3 +303,16 @@ 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("< ", "<")

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_remove_template_defaults.py

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -30,149 +30,149 @@ def global_ns():
3030
def test_vector(global_ns):
3131
v_int = global_ns.typedef('v_int')
3232
v_traits = declarations.vector_traits
33-
assert 'vector< int >' == v_traits.remove_defaults(v_int)
33+
assert 'vector<int>' == v_traits.remove_defaults(v_int)
3434
v_string = global_ns.typedef('v_string')
35-
assert 'vector< std::string >' == \
35+
assert 'vector<std::string>' == \
3636
v_traits.remove_defaults(v_string)
3737
v_v_int = global_ns.typedef('v_v_int')
38-
assert 'vector< std::vector< int > >' == \
38+
assert 'vector<std::vector<int>>' == \
3939
v_traits.remove_defaults(v_v_int)
4040

4141

4242
def test_list(global_ns):
4343
l_int = global_ns.typedef('l_int')
4444
l_traits = declarations.list_traits
45-
assert 'list< int >' == l_traits.remove_defaults(l_int)
45+
assert 'list<int>' == l_traits.remove_defaults(l_int)
4646
l_wstring = global_ns.typedef('l_wstring')
47-
assert 'list< std::wstring >' == l_traits.remove_defaults(l_wstring)
47+
assert 'list<std::wstring>' == l_traits.remove_defaults(l_wstring)
4848

4949

5050
def test_deque(global_ns):
5151
d_v_int = global_ns.typedef('d_v_int')
5252
d_v_traits = declarations.deque_traits
53-
assert 'deque< std::vector< int > >' == \
53+
assert 'deque<std::vector<int>>' == \
5454
d_v_traits.remove_defaults(d_v_int)
5555
d_l_string = global_ns.typedef('d_l_string')
56-
assert 'deque< std::list< std::string > >' == \
56+
assert 'deque<std::list<std::string>>' == \
5757
d_v_traits.remove_defaults(d_l_string)
5858

5959

6060
def test_queue(global_ns):
6161
q_int = global_ns.typedef('q_int')
6262
q_traits = declarations.queue_traits
63-
assert 'queue< int >' == q_traits.remove_defaults(q_int)
63+
assert 'queue<int>' == q_traits.remove_defaults(q_int)
6464
q_string = global_ns.typedef('q_string')
65-
assert 'queue< std::string >' == q_traits.remove_defaults(q_string)
65+
assert 'queue<std::string>' == q_traits.remove_defaults(q_string)
6666

6767

6868
def test_priority_queue(global_ns):
6969
pq_int = global_ns.typedef('pq_int')
7070
pq_traits = declarations.priority_queue_traits
71-
assert 'priority_queue< int >' == pq_traits.remove_defaults(pq_int)
71+
assert 'priority_queue<int>' == pq_traits.remove_defaults(pq_int)
7272
pq_string = global_ns.typedef('pq_string')
73-
assert 'priority_queue< std::string >' == \
73+
assert 'priority_queue<std::string>' == \
7474
pq_traits.remove_defaults(pq_string)
7575

7676

7777
def test_set(global_ns):
7878
s_v_int = global_ns.typedef('s_v_int')
79-
assert 'set< std::vector< int > >' == \
79+
assert 'set<std::vector<int>>' == \
8080
declarations.set_traits.remove_defaults(s_v_int)
8181
s_string = global_ns.typedef('s_string')
82-
assert 'set< std::string >' == \
82+
assert 'set<std::string>' == \
8383
declarations.set_traits.remove_defaults(s_string)
8484

8585

8686
def test_multiset(global_ns):
8787
ms_v_int = global_ns.typedef('ms_v_int')
8888
ms_v_traits = declarations.multiset_traits
89-
assert 'multiset< std::vector< int > >' == \
89+
assert 'multiset<std::vector<int>>' == \
9090
ms_v_traits.remove_defaults(ms_v_int)
9191
ms_string = global_ns.typedef('ms_string')
92-
assert 'multiset< std::string >' == \
92+
assert 'multiset<std::string>' == \
9393
ms_v_traits.remove_defaults(ms_string)
9494

9595

9696
def test_map(global_ns):
9797
m_i2d = global_ns.typedef('m_i2d')
98-
assert 'map< int, double >' == \
98+
assert 'map<int, double>' == \
9999
declarations.map_traits.remove_defaults(m_i2d)
100100
m_wstr2d = global_ns.typedef('m_wstr2d')
101-
assert 'map< std::wstring, double >' == \
101+
assert 'map<std::wstring, double>' == \
102102
declarations.map_traits.remove_defaults(m_wstr2d)
103103
m_v_i2m_wstr2d = global_ns.typedef('m_v_i2m_wstr2d')
104-
m = 'map< const std::vector< int >, std::map< std::wstring, double > >'
104+
m = 'map<const std::vector<int>, std::map<std::wstring, double>>'
105105
assert m == declarations.map_traits.remove_defaults(m_v_i2m_wstr2d)
106106

107107

108108
def test_multimap(global_ns):
109109
mm_i2d = global_ns.typedef('mm_i2d')
110110
mm_traits = declarations.multimap_traits
111-
assert 'multimap< int, double >' == mm_traits.remove_defaults(mm_i2d)
111+
assert 'multimap<int, double>' == mm_traits.remove_defaults(mm_i2d)
112112
mm_wstr2d = global_ns.typedef('mm_wstr2d')
113-
assert 'multimap< const std::wstring, double >' == \
113+
assert 'multimap<const std::wstring, double>' == \
114114
mm_traits.remove_defaults(mm_wstr2d)
115115
mm_v_i2mm_wstr2d = global_ns.typedef('mm_v_i2mm_wstr2d')
116-
assert ('multimap< const std::vector< int >, ' +
117-
'const std::multimap< const std::wstring, double > >') == \
116+
assert ('multimap<const std::vector<int>, ' +
117+
'const std::multimap<const std::wstring, double>>') == \
118118
mm_traits.remove_defaults(mm_v_i2mm_wstr2d)
119119

120120

121121
def test_hash_set(global_ns):
122122
hs_v_int = global_ns.typedef('hs_v_int')
123123
hs_traits = declarations.unordered_set_traits
124124
name = 'unordered_set'
125-
assert (name + '< std::vector< int > >') == \
125+
assert (name + '<std::vector<int>>') == \
126126
hs_traits.remove_defaults(hs_v_int), \
127127
hs_traits.remove_defaults(hs_v_int)
128128
hs_string = global_ns.typedef('hs_string')
129-
assert (name + '< std::string >') == \
129+
assert (name + '<std::string>') == \
130130
hs_traits.remove_defaults(hs_string)
131131

132132

133133
def test_hash_multiset(global_ns):
134134
mhs_v_int = global_ns.typedef('mhs_v_int')
135135
mhs_traits = declarations.unordered_multiset_traits
136136
name = 'unordered_multiset'
137-
assert (name + '< std::vector< int > >') == \
137+
assert (name + '<std::vector<int>>') == \
138138
mhs_traits.remove_defaults(mhs_v_int)
139139
mhs_string = global_ns.typedef('mhs_string')
140-
assert (name + '< std::string >') == \
140+
assert (name + '<std::string>') == \
141141
mhs_traits.remove_defaults(mhs_string)
142142

143143

144144
def test_hash_map(global_ns):
145145
hm_i2d = global_ns.typedef('hm_i2d')
146146
hm_traits = declarations.unordered_map_traits
147147
name = 'unordered_map'
148-
assert (name + '< int, double >') == \
148+
assert (name + '<int, double>') == \
149149
hm_traits.remove_defaults(hm_i2d)
150150
hm_wstr2d = global_ns.typedef('hm_wstr2d')
151-
assert (name + '< std::wstring, double >') == \
151+
assert (name + '<std::wstring, double>') == \
152152
hm_traits.remove_defaults(hm_wstr2d)
153153

154154

155155
def test_hash_multimap(global_ns):
156156
hmm_i2d = global_ns.typedef('hmm_i2d')
157157
hmm_traits = declarations.unordered_multimap_traits
158158
name = 'unordered_multimap'
159-
assert (name + '< int, double >') == \
159+
assert (name + '<int, double>') == \
160160
hmm_traits.remove_defaults(hmm_i2d)
161161
hmm_wstr2d = global_ns.typedef('hmm_wstr2d')
162-
assert (name + '< const std::wstring, double >') == \
162+
assert (name + '<const std::wstring, double>') == \
163163
hmm_traits.remove_defaults(hmm_wstr2d)
164164

165165
hmm_v_i2mm_wstr2d = global_ns.typedef('hmm_v_i2mm_wstr2d')
166166

167167
hmm_traits_value = hmm_traits.remove_defaults(hmm_v_i2mm_wstr2d)
168168

169169
possible_values = (
170-
name + '< const std::vector< int >, ' +
171-
'const __gnu_cxx::' + name + '< const std::wstring, double > >',
172-
name + '< const std::vector< int >, ' +
170+
name + '<const std::vector<int>, ' +
171+
'const __gnu_cxx::' + name + '<const std::wstring, double>>',
172+
name + '<const std::vector<int>, ' +
173173
'const std::' + utils.get_tr1(hmm_traits_value) + name +
174-
'< const std::wstring, double > >',
175-
name + '< const std::vector< int >, ' +
176-
'const stdext::' + name + '< const std::wstring, double > >')
174+
'<const std::wstring, double>>',
175+
name + '<const std::vector<int>, ' +
176+
'const stdext::' + name + '<const std::wstring, double>>')
177177

178178
assert hmm_traits_value in possible_values, hmm_traits_value

0 commit comments

Comments
 (0)