From d489141419688ae3cb87d70506c774011aa8a3cb Mon Sep 17 00:00:00 2001 From: Anderson Bravalheri Date: Thu, 24 Mar 2022 10:44:04 +0000 Subject: [PATCH] Change tests for resolve_class to consider different layouts Although this situation is different from the one described in #3000, that issue served as inspiration behind this change. --- setuptools/tests/config/test_expand.py | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/setuptools/tests/config/test_expand.py b/setuptools/tests/config/test_expand.py index 96f499dd86..d8078d0a80 100644 --- a/setuptools/tests/config/test_expand.py +++ b/setuptools/tests/config/test_expand.py @@ -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 @@ -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(