Skip to content

Commit

Permalink
Ensure free floating connections are cleared
Browse files Browse the repository at this point in the history
after leaving ActionSelection block.

Fixes #230.
  • Loading branch information
jgosmann committed Jun 21, 2019
1 parent 5d13ae1 commit 730ce0f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ Release History

**Fixed**

- Fixed a bug where an exception within an ``ActionSelection`` block would
lead to every subsequent ``ActionSelection`` block to raise an exception.
(`#230 <https://github.com/nengo/nengo_spa/issues/230>`__,
`#231 <https://github.com/nengo/nengo_spa/pull/231>`__)
- Nengo SPA is now compatible with pytest 4. Support for earlier versions has
been dropped.
(`#227 <https://github.com/nengo/nengo_spa/pull/227>`__)
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 @@ -92,6 +92,7 @@ def __exit__(self, exc_type, exc_value, traceback):
ActionSelection.active = None
ModuleInput.routed_mode = False
if exc_type is not None:
RoutedConnection.free_floating.clear()
return
self._build()

Expand Down
15 changes: 15 additions & 0 deletions nengo_spa/tests/test_action_selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,3 +390,18 @@ def test_action_selection_keys_corner_cases():
with ActionSelection() as action_sel:
spa.ifmax(0.)
assert list(action_sel.keys()) == [0]


def test_action_selection_is_side_effect_free_if_exception_is_raised():
with spa.Network():
state_a = spa.State(32)
state_b = spa.State(32)
state_c = spa.State(64)

with pytest.raises(SpaTypeError):
with ActionSelection():
spa.ifmax(1, state_a >> state_b, state_a >> state_c)

with ActionSelection():
pass
# should not raise

0 comments on commit 730ce0f

Please sign in to comment.