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

[Bugfix] Moved access to first element to after the length check #2265

Merged
merged 3 commits into from
Apr 5, 2020
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
3 changes: 1 addition & 2 deletions poetry/masonry/utils/package_include.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,12 @@ def refresh(self): # type: () -> PackageInclude
return self.check_elements()

def check_elements(self): # type: () -> PackageInclude
root = self._elements[0]

if not self._elements:
raise ValueError(
"{} does not contain any element".format(self._base / self._include)
)

root = self._elements[0]
if len(self._elements) > 1:
# Probably glob
self._is_package = True
Expand Down
9 changes: 9 additions & 0 deletions tests/masonry/utils/test_package_include.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,12 @@ def test_package_include_with_no_python_files_in_dir():
PackageInclude(base=with_includes, include="not_a_python_pkg")

assert str(e.value) == "not_a_python_pkg is not a package."


def test_package_include_with_non_existent_directory():
with pytest.raises(ValueError) as e:
PackageInclude(base=with_includes, include="not_a_dir")

err_str = str(with_includes / "not_a_dir") + " does not contain any element"

assert str(e.value) == err_str