From 48a91a3007136d5083aa3ea18ddf962e7d5ed99f Mon Sep 17 00:00:00 2001 From: Xavier Francisco Date: Fri, 3 Apr 2020 21:38:33 +0100 Subject: [PATCH 1/3] Moved access to first element to after the length check --- poetry/masonry/utils/package_include.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/poetry/masonry/utils/package_include.py b/poetry/masonry/utils/package_include.py index 42ecbbc1fd0..512c6c48f63 100644 --- a/poetry/masonry/utils/package_include.py +++ b/poetry/masonry/utils/package_include.py @@ -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 From 75cb097d525d8bb2204a1f6e0ed6b664f2b31852 Mon Sep 17 00:00:00 2001 From: Xavier Francisco Date: Sun, 5 Apr 2020 22:37:46 +0100 Subject: [PATCH 2/3] Add test --- tests/masonry/utils/test_package_include.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/masonry/utils/test_package_include.py b/tests/masonry/utils/test_package_include.py index a79ff96f03c..d70b6d45ff7 100644 --- a/tests/masonry/utils/test_package_include.py +++ b/tests/masonry/utils/test_package_include.py @@ -41,3 +41,10 @@ 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") + + assert str(e.value) == f"{with_includes / 'not_a_dir'} does not contain any element" From 62eabca8c399d72b151c6a2d6dbdef7877f871aa Mon Sep 17 00:00:00 2001 From: Xavier Francisco Date: Sun, 5 Apr 2020 22:45:49 +0100 Subject: [PATCH 3/3] Fix test --- tests/masonry/utils/test_package_include.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/masonry/utils/test_package_include.py b/tests/masonry/utils/test_package_include.py index d70b6d45ff7..36b5985800b 100644 --- a/tests/masonry/utils/test_package_include.py +++ b/tests/masonry/utils/test_package_include.py @@ -47,4 +47,6 @@ def test_package_include_with_non_existent_directory(): with pytest.raises(ValueError) as e: PackageInclude(base=with_includes, include="not_a_dir") - assert str(e.value) == f"{with_includes / 'not_a_dir'} does not contain any element" + err_str = str(with_includes / "not_a_dir") + " does not contain any element" + + assert str(e.value) == err_str