diff options
author | Anderson Bravalheri <andersonbravalheri@gmail.com> | 2022-03-25 17:23:25 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-25 17:23:25 +0000 |
commit | 1a3e1ccee8f740425081863109e26a04d2c10471 (patch) | |
tree | 6db48019d021d22085359591ea8029f7abfa9bfe /setuptools/tests/config/test_pyprojecttoml.py | |
parent | 1957e0e9da7ee408b64dc59d3af8b34860ef1c01 (diff) | |
parent | 4569a87030b1e905303b06b72827ad8475223c86 (diff) | |
download | python-setuptools-git-1a3e1ccee8f740425081863109e26a04d2c10471.tar.gz |
Make sure dynamic classifiers in pyproject.toml don't fail (#3210)
Diffstat (limited to 'setuptools/tests/config/test_pyprojecttoml.py')
-rw-r--r-- | setuptools/tests/config/test_pyprojecttoml.py | 83 |
1 files changed, 58 insertions, 25 deletions
diff --git a/setuptools/tests/config/test_pyprojecttoml.py b/setuptools/tests/config/test_pyprojecttoml.py index 0fdca253..1b5b90e2 100644 --- a/setuptools/tests/config/test_pyprojecttoml.py +++ b/setuptools/tests/config/test_pyprojecttoml.py @@ -11,6 +11,8 @@ from setuptools.config.pyprojecttoml import ( expand_configuration, validate, ) +from setuptools.errors import OptionError + import setuptools # noqa -- force distutils.core to be patched import distutils.core @@ -193,32 +195,63 @@ def test_expand_entry_point(tmp_path): assert "gui-scripts" not in expanded_project -def test_dynamic_classifiers(tmp_path): - # Let's create a project example that has dynamic classifiers - # coming from a txt file. - create_example(tmp_path, "src") - classifiers = """\ - Framework :: Flask - Programming Language :: Haskell - """ - (tmp_path / "classifiers.txt").write_text(cleandoc(classifiers)) +class TestClassifiers: + def test_dynamic(self, tmp_path): + # Let's create a project example that has dynamic classifiers + # coming from a txt file. + create_example(tmp_path, "src") + classifiers = """\ + Framework :: Flask + Programming Language :: Haskell + """ + (tmp_path / "classifiers.txt").write_text(cleandoc(classifiers)) + + pyproject = tmp_path / "pyproject.toml" + config = read_configuration(pyproject, expand=False) + dynamic = config["project"]["dynamic"] + config["project"]["dynamic"] = list({*dynamic, "classifiers"}) + dynamic_config = config["tool"]["setuptools"]["dynamic"] + dynamic_config["classifiers"] = {"file": "classifiers.txt"} + + # When the configuration is expanded, + # each line of the file should be an different classifier. + validate(config, pyproject) + expanded = expand_configuration(config, tmp_path) + + assert set(expanded["project"]["classifiers"]) == { + "Framework :: Flask", + "Programming Language :: Haskell", + } - pyproject = tmp_path / "pyproject.toml" - config = read_configuration(pyproject, expand=False) - dynamic = config["project"]["dynamic"] - config["project"]["dynamic"] = list({*dynamic, "classifiers"}) - dynamic_config = config["tool"]["setuptools"]["dynamic"] - dynamic_config["classifiers"] = {"file": "classifiers.txt"} - - # When the configuration is expanded, - # each line of the file should be an different classifier. - validate(config, pyproject) - expanded = expand_configuration(config, tmp_path) - - assert set(expanded["project"]["classifiers"]) == { - "Framework :: Flask", - "Programming Language :: Haskell", - } + def test_dynamic_without_config(self, tmp_path): + config = """ + [project] + name = "myproj" + version = '42' + dynamic = ["classifiers"] + """ + + pyproject = tmp_path / "pyproject.toml" + pyproject.write_text(cleandoc(config)) + with pytest.raises(OptionError, match="No configuration found"): + read_configuration(pyproject) + + def test_dynamic_without_file(self, tmp_path): + config = """ + [project] + name = "myproj" + version = '42' + dynamic = ["classifiers"] + + [tool.setuptools.dynamic] + classifiers = {file = ["classifiers.txt"]} + """ + + pyproject = tmp_path / "pyproject.toml" + pyproject.write_text(cleandoc(config)) + with pytest.warns(UserWarning, match="File .*classifiers.txt. cannot be found"): + expanded = read_configuration(pyproject) + assert not expanded["project"]["classifiers"] @pytest.mark.parametrize( |