Skip to content

Commit

Permalink
Change tests for resolve_class to consider different layouts
Browse files Browse the repository at this point in the history
Although this situation is different from the one described in #3000,
that issue served as inspiration behind this change.
  • Loading branch information
abravalheri committed Mar 24, 2022
1 parent f86e934 commit d489141
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions setuptools/tests/config/test_expand.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import pytest

from distutils.errors import DistutilsOptionError
from setuptools.command.sdist import sdist
from setuptools.config import expand
from setuptools.discovery import find_package_path

Expand Down Expand Up @@ -97,13 +96,25 @@ def test_import_order(self, tmp_path):
}
write_files(files, tmp_path)
attr_desc = "pkg.about.version"
pkg_dir = {"": "src"}
package_dir = {"": "src"}
# `import super_complicated_dep` should not run, otherwise the build fails
assert expand.read_attr(attr_desc, pkg_dir, tmp_path) == "42"
assert expand.read_attr(attr_desc, package_dir, tmp_path) == "42"


def test_resolve_class():
assert expand.resolve_class("setuptools.command.sdist.sdist") == sdist
@pytest.mark.parametrize(
'package_dir, file, module, return_value',
[
({"": "src"}, "src/pkg/main.py", "pkg.main", 42),
({"pkg": "lib"}, "lib/main.py", "pkg.main", 13),
({}, "single_module.py", "single_module", 70),
({}, "flat_layout/pkg.py", "flat_layout.pkg", 836),
]
)
def test_resolve_class(tmp_path, package_dir, file, module, return_value):
files = {file: f"class Custom:\n def testing(self): return {return_value}"}
write_files(files, tmp_path)
cls = expand.resolve_class(f"{module}.Custom", package_dir, tmp_path)
assert cls().testing() == return_value


@pytest.mark.parametrize(
Expand Down

0 comments on commit d489141

Please sign in to comment.