Skip to content

Commit

Permalink
Fix iterating over Mock objects
Browse files Browse the repository at this point in the history
These are used in tests, so tests that iterate over something
that has been mocked out could iterate forever.

Fixes #1441.
  • Loading branch information
tbekolay committed Jun 8, 2018
1 parent 4067660 commit 0c09550
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
3 changes: 3 additions & 0 deletions nengo/utils/testing.py
Expand Up @@ -25,6 +25,9 @@ def __call__(self, *args, **kwargs):
def __getitem__(self, key):
return Mock()

def __iter__(self):
return iter([])

def __mul__(self, other):
return 1.0

Expand Down
7 changes: 7 additions & 0 deletions nengo/utils/tests/test_testing.py
Expand Up @@ -72,3 +72,10 @@ def test_logger_norecord():
logger.info("Testing that logger doesn't record")
with pytest.raises(ValueError):
logger_obj.get_filepath(ext='txt')


def test_mock_iter(plt):
fig = plt.figure()
for i, ax in enumerate(fig.axes):
assert False, "Mock object iterating forever"
plt.saveas = None

0 comments on commit 0c09550

Please sign in to comment.