From d8ba0577ab5169195c67788d7dac6f5f24522c2c Mon Sep 17 00:00:00 2001 From: Jan Gosmann Date: Thu, 30 Aug 2018 12:30:57 -0400 Subject: [PATCH] Fix action selection key iteration. It was failing without a named action. --- CHANGES.rst | 4 +++- nengo_spa/action_selection.py | 1 + nengo_spa/tests/test_action_selection.py | 12 ++++++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/CHANGES.rst b/CHANGES.rst index 0854a741b..591b4a802 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -98,7 +98,9 @@ Release History ``prob_cleanup``. Also, fix the function's incorrect documentation. (`#203 `__, `#206 `__) - +- Fix ``nengo_spa.ActionSelection.keys()`` when no named actions have been + provided. + (`#210 `_) 0.5.2 (July 6, 2018) diff --git a/nengo_spa/action_selection.py b/nengo_spa/action_selection.py index dcdae8a34..0a9aa6e7a 100644 --- a/nengo_spa/action_selection.py +++ b/nengo_spa/action_selection.py @@ -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 diff --git a/nengo_spa/tests/test_action_selection.py b/nengo_spa/tests/test_action_selection.py index 07f726ab4..317b23679 100644 --- a/nengo_spa/tests/test_action_selection.py +++ b/nengo_spa/tests/test_action_selection.py @@ -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]