Skip to content

Commit

Permalink
Fix action selection key iteration.
Browse files Browse the repository at this point in the history
It was failing without a named action.
  • Loading branch information
jgosmann committed Aug 30, 2018
1 parent 898d861 commit d8ba057
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
4 changes: 3 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ Release History
``prob_cleanup``. Also, fix the function's incorrect documentation.
(`#203 <https://github.com/nengo/nengo_spa/issues/203>`__,
`#206 <https://github.com/nengo/nengo_spa/pull/206>`__)

- Fix ``nengo_spa.ActionSelection.keys()`` when no named actions have been
provided.
(`#210 <https://github.com/nengo/nengo_spa/pull/210>`_)


0.5.2 (July 6, 2018)
Expand Down
1 change: 1 addition & 0 deletions nengo_spa/action_selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ def __getitem__(self, key):
def __iter__(self):
# Given not all actions have names, there will actions whose keys
# will be numbers and not names.
i = -1
for i, (name, v) in enumerate(self._name2idx.items()):
while i < v:
yield i
Expand Down
12 changes: 12 additions & 0 deletions nengo_spa/tests/test_action_selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,3 +378,15 @@ def test_naming_of_actions():
assert action_sel['name2'] is u2
for i, u in enumerate((u0, u1, u2)):
assert action_sel[i] is u


def test_action_selection_keys_corner_cases():
with spa.Network():
with ActionSelection() as action_sel:
pass
assert list(action_sel.keys()) == []

with spa.Network():
with ActionSelection() as action_sel:
spa.ifmax(0.)
assert list(action_sel.keys()) == [0]

0 comments on commit d8ba057

Please sign in to comment.