Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure free floating connections are cleared #231

Merged
merged 1 commit into from
Jun 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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