Skip to content

Commit

Permalink
Merge pull request #28 from di/add-is-package
Browse files Browse the repository at this point in the history
Add _is_package
  • Loading branch information
di committed Oct 20, 2016
2 parents f5720a5 + 4caf608 commit 4f5e69e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
10 changes: 10 additions & 0 deletions vladiate/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,16 @@ def is_vlad(tup):
hasattr(item, "validators") and not name.startswith('_'))


def _is_package(path):
"""
Is the given path a Python package?
"""
return (
os.path.isdir(path)
and os.path.exists(os.path.join(path, '__init__.py'))
)


def find_vladfile(vladfile, path='.'):
"""
Attempt to locate a vladfile, either explicitly or by searching parent dirs.
Expand Down
11 changes: 10 additions & 1 deletion vladiate/test/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
from pretend import stub, call, call_recorder

from ..main import ( # NOQA
parse_args, is_vlad, find_vladfile, load_vladfile, _vladiate, main, run
parse_args, is_vlad, find_vladfile, load_vladfile, _vladiate, main, run,
_is_package
)

from ..vlad import Vlad
Expand Down Expand Up @@ -286,3 +287,11 @@ def test_main_no_vladfile(monkeypatch):
'vladiate.main.find_vladfile', lambda *args, **kwargs: None
)
assert main() == os.EX_NOINPUT


@pytest.mark.parametrize('path, expected', [
('foo/bar', False),
('vladiate/test', True),
])
def test_is_package(path, expected):
assert _is_package(path) == expected

0 comments on commit 4f5e69e

Please sign in to comment.