Skip to content

Commit

Permalink
Fix Document.add_path for empty groups (mathandy#170)
Browse files Browse the repository at this point in the history
  • Loading branch information
chanicpanic authored Feb 28, 2022
1 parent c84c897 commit 19df25b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion svgpathtools/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ def add_path(self, path, attribs=None, group=None):

# If given a list of strings (one or more), assume it represents
# a sequence of nested group names
elif all(isinstance(elem, str) for elem in group):
elif len(group) > 0 and all(isinstance(elem, str) for elem in group):
group = self.get_or_add_group(group)

elif not isinstance(group, Element):
Expand Down
9 changes: 8 additions & 1 deletion test/test_groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,4 +235,11 @@ def test_add_group(self):

path = parse_path(path_d)
svg_path = doc.add_path(path, group=new_leaf)
self.assertEqual(path_d, svg_path.get('d'))
self.assertEqual(path_d, svg_path.get('d'))

# Test that paths are added to the correct group
new_sibling = doc.get_or_add_group(
['base_group', 'new_parent', 'new_sibling'])
doc.add_path(path, group=new_sibling)
self.assertEqual(len(new_sibling), 1)
self.assertEqual(path_d, new_sibling[0].get('d'))

0 comments on commit 19df25b

Please sign in to comment.