Skip to content

Commit

Permalink
Provide more information when the StopIteration happens. Ref #28.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaraco committed Jan 12, 2015
1 parent 7458fc1 commit eb5b376
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
6 changes: 5 additions & 1 deletion hgtools/managers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ def get_valid_managers(cls, location):

@staticmethod
def get_first_valid_manager(location='.'):
return next(RepoManager.get_valid_managers(location))
try:
return next(RepoManager.get_valid_managers(location))
except StopIteration as e:
e.args = "No source repo or suitable VCS version found",
raise

@staticmethod
def existing_only(managers):
Expand Down
14 changes: 14 additions & 0 deletions hgtools/tests/test_managers.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import mock
import pytest

from hgtools import managers

def test_existing_only():
Expand All @@ -9,3 +12,14 @@ def test_existing_only():
mgrs = managers.RepoManager.get_valid_managers('/')
existing = list(managers.RepoManager.existing_only(mgrs))
assert not existing

@mock.patch.object(managers.RepoManager, 'get_valid_managers',
classmethod(lambda cls, location: iter(())))
def test_no_valid_managers():
"""
When no valid managers can be found, a StopIteration is raised providing
a nice message.
"""
with pytest.raises(StopIteration) as err:
managers.RepoManager.get_first_valid_manager()
assert 'no source repo' in str(err).lower()

0 comments on commit eb5b376

Please sign in to comment.