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 12, 2024
1 parent 682dc7e commit ce87716
Show file tree
Hide file tree
Showing 4 changed files with 167 additions and 163 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
5 changes: 3 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,6 @@ examples = [
"notebook",
]
[tool.pytest.ini_options]
pythonpath = [
"src"]
pythonpath = [
"src"
]
44 changes: 23 additions & 21 deletions src/pygccxml/declarations/container_traits.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,11 @@ def erase_recursive(self, cls_name):
return self.no_end_const(cls_name)

def erase_allocator(self, cls_name, default_allocator='std::allocator'):
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 cls_name
value_type = c_args[0]
tmpl = string.Template(
"$container< $value_type, $allocator<$value_type> >")
Expand All @@ -109,19 +110,22 @@ 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)
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 cls_name
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 @@ -130,10 +134,9 @@ def erase_container_compare(
cls_name,
default_container_name='std::vector',
default_compare='std::less'):
cls_name = self.replace_basic_string(cls_name)
c_name, c_args = templates.split(cls_name)
if len(c_args) != 3:
return
return cls_name
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 @@ -150,10 +153,9 @@ def erase_compare_allocator(
cls_name,
default_compare='std::less',
default_allocator='std::allocator'):
cls_name = self.replace_basic_string(cls_name)
c_name, c_args = templates.split(cls_name)
if len(c_args) != 3:
return
return cls_name
value_type = c_args[0]
tmpl = string.Template(
"$container< $value_type, $compare<$value_type>, " +
Expand All @@ -173,10 +175,9 @@ def erase_map_compare_allocator(
cls_name,
default_compare='std::less',
default_allocator='std::allocator'):
cls_name = self.replace_basic_string(cls_name)
c_name, c_args = templates.split(cls_name)
if len(c_args) != 4:
return
return cls_name
key_type = c_args[0]
mapped_type = c_args[1]
tmpls = [
Expand All @@ -203,10 +204,9 @@ def erase_map_compare_allocator(
self.erase_recursive(mapped_type)])

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 cls_name

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

value_type = c_args[0]
template = string.Template(tmpl)
Expand All @@ -241,7 +241,6 @@ def erase_hash_allocator(self, cls_name):
c_name, [self.erase_recursive(value_type)])

def erase_hashmap_compare_allocator(self, cls_name):
cls_name = self.replace_basic_string(cls_name)
c_name, c_args = templates.split(cls_name)

if self.unordered_maps_and_sets:
Expand All @@ -255,7 +254,7 @@ def erase_hashmap_compare_allocator(self, cls_name):
key_type = c_args[0]
mapped_type = c_args[1]
else:
return
return cls_name

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

for ns in std_namespaces:
inst = tmpl.substitute(
Expand Down Expand Up @@ -517,15 +516,18 @@ def remove_defaults(self, type_or_string):
std::vector< int >
"""

name = type_or_string
if not isinstance(type_or_string, str):
print(
"xxxx",
type(self.class_declaration(type_or_string)),
self.class_declaration(type_or_string).name
)
name = self.class_declaration(type_or_string).name
if not self.remove_defaults_impl:
return name
name = self.replace_basic_string(name)
no_defaults = self.remove_defaults_impl(name)
if not no_defaults:
return name
return no_defaults


Expand Down
Loading

0 comments on commit ce87716

Please sign in to comment.