From 3e87b5da7fae91c24cbfbf857d86b7aa032b7693 Mon Sep 17 00:00:00 2001 From: Yannik Tausch Date: Mon, 13 May 2024 16:27:54 +0200 Subject: [PATCH] use pytest, add tests for AzureRunnerSettings and CondaBuildConfig --- conda_smithy/lint_recipe.py | 1 - tests/test_lint_recipe.py | 43 +++++++++++++++++++++++++++++-------- 2 files changed, 34 insertions(+), 10 deletions(-) diff --git a/conda_smithy/lint_recipe.py b/conda_smithy/lint_recipe.py index c60935c06..d289fef43 100644 --- a/conda_smithy/lint_recipe.py +++ b/conda_smithy/lint_recipe.py @@ -1214,7 +1214,6 @@ def main_debug(): lints, hints = main(rel_path, False, True) messages = [] if lints: - all_pass = False messages.append( "\nFor **{}**:\n\n{}".format( rel_path, "\n".join("* {}".format(lint) for lint in lints) diff --git a/tests/test_lint_recipe.py b/tests/test_lint_recipe.py index a5d9b6cac..318d5659c 100644 --- a/tests/test_lint_recipe.py +++ b/tests/test_lint_recipe.py @@ -1654,7 +1654,7 @@ def assert_jinja(jinja_var, is_good=True): assert_jinja('{% set version= "0.27.3"%}', is_good=False) -class TestLintifyForgeYamlHintExtraFields(unittest.TestCase): +class TestLintifyForgeYamlHintExtraFields: def test_extra_build_platforms_platform(self): forge_yml = { "build_platform": { @@ -1665,11 +1665,9 @@ def test_extra_build_platforms_platform(self): hints = linter._forge_yaml_hint_extra_fields(forge_yml) - self.assertEquals(len(hints), 1) + assert len(hints) == 1 - self.assertIn( - "Unexpected key build_platform.UNKNOWN_PLATFORM", hints[0] - ) + assert "Unexpected key build_platform.UNKNOWN_PLATFORM" in hints[0] def test_extra_os_version_platform(self): forge_yml = { @@ -1680,9 +1678,9 @@ def test_extra_os_version_platform(self): hints = linter._forge_yaml_hint_extra_fields(forge_yml) - self.assertEquals(len(hints), 1) + assert len(hints) == 1 - self.assertIn("Unexpected key os_version.UNKNOWN_PLATFORM_2", hints[0]) + assert "Unexpected key os_version.UNKNOWN_PLATFORM_2" in hints[0] def test_extra_provider_platform(self): forge_yml = { @@ -1694,9 +1692,36 @@ def test_extra_provider_platform(self): hints = linter._forge_yaml_hint_extra_fields(forge_yml) - self.assertEquals(len(hints), 1) + assert len(hints) == 1 + + assert "Unexpected key provider.UNKNOWN_PLATFORM_3" in hints[0] + + @pytest.mark.parametrize( + "top_field", ["settings_linux", "settings_osx", "settings_win"] + ) + def test_extra_azure_runner_settings_no_hint(self, top_field: str): + forge_yml = { + "azure": { + top_field: { + "EXTRA_FIELD": "EXTRA_VALUE", + } + } + } + + hints = linter._forge_yaml_hint_extra_fields(forge_yml) + + assert len(hints) == 0 + + def test_extra_conda_build_config_no_hint(self): + forge_yml = { + "conda_build": { + "EXTRA_FIELD": "EXTRA_VALUE", + } + } + + hints = linter._forge_yaml_hint_extra_fields(forge_yml) - self.assertIn("Unexpected key provider.UNKNOWN_PLATFORM_3", hints[0]) + assert len(hints) == 0 if __name__ == "__main__":