Skip to content

Commit

Permalink
Add Selector.add_str() classmethod.
Browse files Browse the repository at this point in the history
  • Loading branch information
lebedov committed Dec 21, 2015
1 parent 4fec83d commit 6edf0c5
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
27 changes: 23 additions & 4 deletions neurokernel/plsel.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,11 @@ def max_levels(self):
@classmethod
def add(cls, *sels):
"""
Combine the identifiers in multiple selectors into a single selector
Combine the identifiers in multiple selectors into a single selector.
Parameters
----------
sels : Selector
sels : iterable of Selector
Selector instances.
Returns
Expand All @@ -151,14 +151,22 @@ def add(cls, *sels):
for i in s._expanded if s.nonempty) or ((),)
return out

@classmethod
def add_str(cls, *s):
"""
Combine the identifiers in multiple selector strings into a single selector.
"""

return cls.add(*map(cls, s))

@classmethod
def concat(cls, *sels):
"""
Concatenate the identifiers in multiple selectors elementwise.
Parameters
----------
sels : Selector
sels : iterable of Selector
Selector instances.
Returns
Expand Down Expand Up @@ -193,7 +201,7 @@ def prod(cls, *sels):
Parameters
----------
sels : Selector
sels : iterable of Selector
Selector instances.
Returns
Expand All @@ -217,6 +225,17 @@ def prod(cls, *sels):
def union(cls, *sels):
"""
Compute the union of the identifiers in multiple selectors.
Parameters
----------
sels : iterable of Selector
Selector instances.
Returns
-------
result : Selector
Selector containing all of the port identifiers comprised by the
union of all of the arguments.
"""

out = cls('')
Expand Down
8 changes: 8 additions & 0 deletions tests/test_plsel.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,14 @@ def test_selector_add_nonempty(self):
assert s.max_levels == 0
assert s.str == ''

def test_selector_add_str(self):
s = Selector.add_str('/foo[0]', '/bar[0]')
assert len(s) == 2
assert s.nonempty
assert s.expanded == (('foo', 0), ('bar', 0))
assert s.max_levels == 2
assert s.str == '/foo/0,/bar/0'

def test_selector_concat_empty(self):
s = Selector.concat(Selector(''), Selector(''))
assert len(s) == 0
Expand Down

0 comments on commit 6edf0c5

Please sign in to comment.