From 0fec4343802ac44f837c31aaf0af26d28a58db80 Mon Sep 17 00:00:00 2001 From: Anthony Sottile Date: Sun, 13 Apr 2014 14:45:39 -0700 Subject: [PATCH] Improve coverage for validators. --- tests/clientlib/validate_config_test.py | 23 +++++++++++++---------- tests/clientlib/validate_manifest_test.py | 23 +++++++++++++---------- 2 files changed, 26 insertions(+), 20 deletions(-) diff --git a/tests/clientlib/validate_config_test.py b/tests/clientlib/validate_config_test.py index 581e3827..93b8fd45 100644 --- a/tests/clientlib/validate_config_test.py +++ b/tests/clientlib/validate_config_test.py @@ -6,18 +6,21 @@ from pre_commit.clientlib.validate_config import run from pre_commit.clientlib.validate_config import validate_config_extra from pre_commit.jsonschema_extensions import apply_defaults from testing.util import is_valid_according_to_schema +from testing.util import get_resource_path -def test_returns_0_for_valid_config(): - assert run(['example_pre-commit-config.yaml']) == 0 - - -def test_returns_0_for_out_manifest(): - assert run([]) == 0 - - -def test_returns_1_for_failing(): - assert run(['tests/data/valid_yaml_but_invalid_config.yaml']) == 1 +@pytest.mark.parametrize( + ('input', 'expected_output'), + ( + (['example_pre-commit-config.yaml'], 0), + (['.pre-commit-config.yaml'], 0), + (['non_existent_file.yaml'], 1), + ([get_resource_path('valid_yaml_but_invalid_config.yaml')], 1), + ([get_resource_path('non_parseable_yaml_file.notyaml')], 1), + ), +) +def test_run(input, expected_output): + assert run(input) == expected_output @pytest.mark.parametrize(('manifest_obj', 'expected'), ( diff --git a/tests/clientlib/validate_manifest_test.py b/tests/clientlib/validate_manifest_test.py index d8d5b180..ecacf10f 100644 --- a/tests/clientlib/validate_manifest_test.py +++ b/tests/clientlib/validate_manifest_test.py @@ -5,18 +5,21 @@ from pre_commit.clientlib.validate_manifest import InvalidManifestError from pre_commit.clientlib.validate_manifest import MANIFEST_JSON_SCHEMA from pre_commit.clientlib.validate_manifest import run from testing.util import is_valid_according_to_schema +from testing.util import get_resource_path -def test_returns_0_for_valid_manifest(): - assert run(['example_hooks.yaml']) == 0 - - -def test_returns_0_for_our_manifest(): - assert run([]) == 0 - - -def test_returns_1_for_failing(): - assert run(['tests/data/valid_yaml_but_invalid_manifest.yaml']) == 1 +@pytest.mark.parametrize( + ('input', 'expected_output'), + ( + (['example_hooks.yaml'], 0), + (['hooks.yaml'], 0), + (['non_existent_file.yaml'], 1), + ([get_resource_path('valid_yaml_but_invalid_manifest.yaml')], 1), + ([get_resource_path('non_parseable_yaml_file.notyaml')], 1), + ), +) +def test_run(input, expected_output): + assert run(input) == expected_output def test_additional_manifest_check_raises_for_bad_language():