From bdc35b8ee99c763d23cc29210f38797f99145b18 Mon Sep 17 00:00:00 2001 From: Joseph Flinn Date: Fri, 12 Jan 2024 08:04:57 -0800 Subject: [PATCH] Fix linting issues for RuleNameCapitalized --- lint-workflow/src/rules/name_capitalized.py | 9 +++ .../tests/rules/test_name_capitalized.py | 56 +++++++++---------- 2 files changed, 36 insertions(+), 29 deletions(-) diff --git a/lint-workflow/src/rules/name_capitalized.py b/lint-workflow/src/rules/name_capitalized.py index e66417c0..eca419b9 100644 --- a/lint-workflow/src/rules/name_capitalized.py +++ b/lint-workflow/src/rules/name_capitalized.py @@ -1,3 +1,4 @@ +"""Enforce all 'name' values start with a capital letter.""" from typing import Union, Tuple from ..rule import Rule @@ -8,7 +9,15 @@ class RuleNameCapitalized(Rule): + """Rule to enforce all 'name' values start with a capital letter.""" def __init__(self, settings: Settings = None) -> None: + """Contructor for RuleNameCapitalized. + + Args: + settings: + A Settings object that contains any default, overriden, or custom settings + required anywhere in the application. + """ self.message = "name must capitalized" self.on_fail: LintLevels = LintLevels.ERROR self.settings: Settings = settings diff --git a/lint-workflow/tests/rules/test_name_capitalized.py b/lint-workflow/tests/rules/test_name_capitalized.py index a496507d..77dea76b 100644 --- a/lint-workflow/tests/rules/test_name_capitalized.py +++ b/lint-workflow/tests/rules/test_name_capitalized.py @@ -1,18 +1,16 @@ +"""Test src/rules/name_capitalized.py.""" import pytest from ruamel.yaml import YAML -from ..conftest import FIXTURE_DIR -from ..context import src - from src.load import WorkflowBuilder from src.rules.name_capitalized import RuleNameCapitalized yaml = YAML() -@pytest.fixture -def correct_workflow(): +@pytest.fixture(name="correct_workflow") +def fixture_correct_workflow(): workflow = """\ --- name: Test Workflow @@ -31,8 +29,8 @@ def correct_workflow(): return WorkflowBuilder.build(workflow=yaml.load(workflow), from_file=False) -@pytest.fixture -def incorrect_workflow(): +@pytest.fixture(name="incorrect_workflow") +def fixture_incorrect_workflow(): workflow = """\ --- name: test @@ -50,8 +48,8 @@ def incorrect_workflow(): return WorkflowBuilder.build(workflow=yaml.load(workflow), from_file=False) -@pytest.fixture -def missing_name_workflow(): +@pytest.fixture(name="missing_name_workflow") +def fixture_missing_name_workflow(): workflow = """\ --- on: @@ -66,43 +64,43 @@ def missing_name_workflow(): return WorkflowBuilder.build(workflow=yaml.load(workflow), from_file=False) -@pytest.fixture -def rule(): +@pytest.fixture(rule="rule") +def fixture_rule(): return RuleNameCapitalized() def test_rule_on_correct_workflow(rule, correct_workflow): - result, message = rule.fn(correct_workflow) - assert result == True + result, _ = rule.fn(correct_workflow) + assert result is True - result, message = rule.fn(correct_workflow.jobs["job-key"]) - assert result == True + result, _ = rule.fn(correct_workflow.jobs["job-key"]) + assert result is True - result, message = rule.fn(correct_workflow.jobs["job-key"].steps[0]) - assert result == True + result, _ = rule.fn(correct_workflow.jobs["job-key"].steps[0]) + assert result is True def test_rule_on_incorrect_workflow_name(rule, incorrect_workflow): - result, message = rule.fn(incorrect_workflow) - assert result == False + result, _ = rule.fn(incorrect_workflow) + assert result is False def test_rule_on_incorrect_job_name(rule, incorrect_workflow): - result, message = rule.fn(incorrect_workflow.jobs["job-key"]) - assert result == False + result, _ = rule.fn(incorrect_workflow.jobs["job-key"]) + assert result is False def test_rule_on_incorrect_step_name(rule, incorrect_workflow): - result, message = rule.fn(incorrect_workflow.jobs["job-key"].steps[0]) - assert result == False + result, _ = rule.fn(incorrect_workflow.jobs["job-key"].steps[0]) + assert result is False def test_rule_on_missing_names(rule, missing_name_workflow): - result, message = rule.fn(missing_name_workflow) - assert result == True + result, _ = rule.fn(missing_name_workflow) + assert result is True - result, message = rule.fn(missing_name_workflow.jobs["job-key"]) - assert result == True + result, _ = rule.fn(missing_name_workflow.jobs["job-key"]) + assert result is True - result, message = rule.fn(missing_name_workflow.jobs["job-key"].steps[0]) - assert result == True + result, _ = rule.fn(missing_name_workflow.jobs["job-key"].steps[0]) + assert result is True