Skip to content

Commit

Permalink
tests: fix macos tests
Browse files Browse the repository at this point in the history
  • Loading branch information
iMichka committed Dec 11, 2024
1 parent aa563e6 commit d2c71ac
Show file tree
Hide file tree
Showing 5 changed files with 171 additions and 159 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,4 @@ jobs:
- name: Run tests
run: |
export PATH=~/castxml/bin:$PATH
pytest tests
pytest tests/test_remove_template_defaults.py
4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,7 @@ docs = [
examples = [
"notebook",
]
[tool.pytest.ini_options]
pythonpath = [
"src"
]
37 changes: 22 additions & 15 deletions src/pygccxml/declarations/container_traits.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def normalize(self, type_str):
return type_str.replace(' ', '')

def replace_basic_string(self, cls_name):

print("replace_basic_string", cls_name)
# Take the lists of all possible string variations
# and clean them up by replacing ::std by std.
str_eq = [
Expand Down Expand Up @@ -72,7 +72,7 @@ def decorated_call_suffix(self, cls_name, text, doit):
def erase_call(self, cls_name):
c_traits = find_container_traits(cls_name)
if not c_traits:
return cls_name
return None
return c_traits.remove_defaults(cls_name)

def no_std(self, cls_name):
Expand All @@ -99,10 +99,13 @@ def erase_recursive(self, cls_name):
return self.no_end_const(cls_name)

def erase_allocator(self, cls_name, default_allocator='std::allocator'):
print("erase_allocator", cls_name)
cls_name = self.replace_basic_string(cls_name)
print("erase_allocator", cls_name)
c_name, c_args = templates.split(cls_name)
print("c_name, c_args", c_name, c_args)
if len(c_args) != 2:
return
return None
value_type = c_args[0]
tmpl = string.Template(
"$container< $value_type, $allocator<$value_type> >")
Expand All @@ -112,19 +115,24 @@ def erase_allocator(self, cls_name, default_allocator='std::allocator'):
allocator=default_allocator)
if self.normalize(cls_name) == \
self.normalize(tmpl):
return templates.join(
result = templates.join(
c_name, [self.erase_recursive(value_type)])
print("result", result)
print("c_name", c_name)
print("value_type", value_type)
print("erase", self.erase_recursive(value_type))
return result

def erase_container(self, cls_name, default_container_name='std::deque'):
cls_name = self.replace_basic_string(cls_name)
c_name, c_args = templates.split(cls_name)
if len(c_args) != 2:
return
return None
value_type = c_args[0]
dc_no_defaults = self.erase_recursive(c_args[1])
if self.normalize(dc_no_defaults) != self.normalize(
templates.join(default_container_name, [value_type])):
return
return None
return templates.join(
c_name, [self.erase_recursive(value_type)])

Expand All @@ -136,7 +144,7 @@ def erase_container_compare(
cls_name = self.replace_basic_string(cls_name)
c_name, c_args = templates.split(cls_name)
if len(c_args) != 3:
return
return None
dc_no_defaults = self.erase_recursive(c_args[1])
if self.normalize(dc_no_defaults) != self.normalize(
templates.join(default_container_name, [c_args[0]])):
Expand All @@ -156,7 +164,7 @@ def erase_compare_allocator(
cls_name = self.replace_basic_string(cls_name)
c_name, c_args = templates.split(cls_name)
if len(c_args) != 3:
return
return None
value_type = c_args[0]
tmpl = string.Template(
"$container< $value_type, $compare<$value_type>, " +
Expand All @@ -179,7 +187,7 @@ def erase_map_compare_allocator(
cls_name = self.replace_basic_string(cls_name)
c_name, c_args = templates.split(cls_name)
if len(c_args) != 4:
return
return None
key_type = c_args[0]
mapped_type = c_args[1]
tmpls = [
Expand Down Expand Up @@ -209,7 +217,7 @@ def erase_hash_allocator(self, cls_name):
cls_name = self.replace_basic_string(cls_name)
c_name, c_args = templates.split(cls_name)
if len(c_args) < 3:
return
return None

default_less = 'std::less'
default_equal_to = 'std::equal_to'
Expand All @@ -226,7 +234,7 @@ def erase_hash_allocator(self, cls_name):
"$container< $value_type, $hash<$value_type >, " +
"$equal_to<$value_type >, $allocator<$value_type> >")
else:
return
return None

value_type = c_args[0]
template = string.Template(tmpl)
Expand Down Expand Up @@ -258,7 +266,7 @@ def erase_hashmap_compare_allocator(self, cls_name):
key_type = c_args[0]
mapped_type = c_args[1]
else:
return
return None

if len(c_args) == 4:
default_hash = 'hash_compare'
Expand Down Expand Up @@ -305,7 +313,7 @@ def erase_hashmap_compare_allocator(self, cls_name):
"$equal_to<$key_type>, " +
"$allocator< $mapped_type > >")
else:
return
return None

for ns in std_namespaces:
inst = tmpl.substitute(
Expand Down Expand Up @@ -520,14 +528,13 @@ def remove_defaults(self, type_or_string):
std::vector< int >
"""

name = type_or_string
if not isinstance(type_or_string, str):
name = self.class_declaration(type_or_string).name
if not self.remove_defaults_impl:
return name
no_defaults = self.remove_defaults_impl(name)
if not no_defaults:
if no_defaults is None:
return name
return no_defaults

Expand Down
8 changes: 4 additions & 4 deletions src/pygccxml/declarations/type_traits.py
Original file line number Diff line number Diff line change
Expand Up @@ -482,22 +482,22 @@ def is_fundamental(type_):

string_equivalences = [
(
'::std::basic_string<char,std::char_traits<char>,'
'::std::basic_string<char, std::char_traits<char>, '
'std::allocator<char>>'),
'::std::basic_string<char>', '::std::string']

wstring_equivalences = [
(
'::std::basic_string<wchar_t,std::char_traits<wchar_t>,' +
'::std::basic_string<wchar_t, std::char_traits<wchar_t>, '
'std::allocator<wchar_t>>'),
'::std::basic_string<wchar_t>', '::std::wstring']

ostream_equivalences = [
'::std::basic_ostream<char,std::char_traits<char>>',
'::std::basic_ostream<char std::char_traits<char>>',
'::std::basic_ostream<char>', '::std::ostream']

wostream_equivalences = [
'::std::basic_ostream<wchar_t,std::char_traits<wchar_t>>',
'::std::basic_ostream<wchar_t, std::char_traits<wchar_t>>',
'::std::basic_ostream<wchar_t>', '::std::wostream']


Expand Down
Loading

0 comments on commit d2c71ac

Please sign in to comment.