diff --git a/liccheck/command_line.py b/liccheck/command_line.py index 3dc2e4a..638307a 100644 --- a/liccheck/command_line.py +++ b/liccheck/command_line.py @@ -73,6 +73,11 @@ def from_pyproject_toml(cls): def elements_to_lower_str(lst): return [str(_).lower() for _ in lst] + conf_keys = {"authorized_licenses", "unauthorized_licenses", + "authorized_packages"} + if not set(liccheck_section.keys()) & conf_keys: + raise NoValidConfigurationInPyprojectToml + strategy = cls( authorized_licenses=elements_to_lower_str( liccheck_section.get("authorized_licenses", []) diff --git a/tests/test_read_strategy.py b/tests/test_read_strategy.py index a7de307..e219371 100644 --- a/tests/test_read_strategy.py +++ b/tests/test_read_strategy.py @@ -28,6 +28,11 @@ def test_falls_back_to_strategy_if_no_liccheck_section_in_pyproject_toml(self): with pytest.raises(NoValidConfigurationInPyprojectToml): Strategy.from_pyproject_toml() + @pytest.mark.usefixtures("pyproject_toml_with_liccheck_section_without_licenses_in_cwd") + def test_falls_back_to_strategy_if_liccheck_section_in_pyproject_toml_has_no_licenses(self): + with pytest.raises(NoValidConfigurationInPyprojectToml): + Strategy.from_pyproject_toml() + @pytest.mark.usefixtures("pyproject_toml_with_liccheck_section_in_cwd") def test_with_liccheck_section_in_pyproject_toml(self): strategy = Strategy.from_pyproject_toml() @@ -58,6 +63,17 @@ def empty_pyproject_toml_in_cwd(self, tmpdir): yield os.chdir(cwd) + @pytest.fixture + def pyproject_toml_with_liccheck_section_without_licenses_in_cwd(self, empty_pyproject_toml_in_cwd): + with open("pyproject.toml", "w") as file: + file.write( + """ + [tool.liccheck] + # No licenses are defined here, just point to the strategy file. + strategy_ini_file = "./liccheck.ini" + """ + ) + @pytest.fixture def pyproject_toml_with_liccheck_section_in_cwd(self, empty_pyproject_toml_in_cwd): with open("pyproject.toml", "w") as file: