From 21313638bdd1009e20d62f30465ccd0a584882fa Mon Sep 17 00:00:00 2001 From: Joseph Flinn Date: Fri, 12 Jan 2024 07:59:33 -0800 Subject: [PATCH] Fix linting issues on job_environment_prefix --- lint-workflow/Taskfile.yml | 8 ++++---- .../src/rules/job_environment_prefix.py | 18 ++++++++++++++--- .../rules/test_job_environment_prefix.py | 20 +++++++++---------- 3 files changed, 28 insertions(+), 18 deletions(-) diff --git a/lint-workflow/Taskfile.yml b/lint-workflow/Taskfile.yml index 673a01a1..98dea17d 100644 --- a/lint-workflow/Taskfile.yml +++ b/lint-workflow/Taskfile.yml @@ -17,14 +17,14 @@ tasks: silent: true cmds: - pipenv run pytype src - + test:unit: cmds: - pipenv run pytest tests - test:unit: + test:unit:single: cmds: - - pipenv run pytest tests + - pipenv run pytest {{.CLI_ARGS}} test:cov: cmds: @@ -44,4 +44,4 @@ tasks: test:e2e:actions:update: cmds: - - pipenv run python cli.py -v actions update --output test.json + - pipenv run python cli.py -v actions update --output test.json diff --git a/lint-workflow/src/rules/job_environment_prefix.py b/lint-workflow/src/rules/job_environment_prefix.py index 95748277..13a33172 100644 --- a/lint-workflow/src/rules/job_environment_prefix.py +++ b/lint-workflow/src/rules/job_environment_prefix.py @@ -1,4 +1,5 @@ -from typing import Union, Tuple +"""A Rule to enforce prefixes environment variables.""" +from typing import Union, Tuple, List from ..rule import Rule from ..models.job import Job @@ -8,8 +9,19 @@ class RuleJobEnvironmentPrefix(Rule): + """Rule to enforce specific prefixes for environemnt variables. + + Maintaining l + """ def __init__(self, settings: Settings = None) -> None: - self.message: str = f"Job Environment vars should start with and underscore:" + """RuleJobEnvironmentPrefix constructor. + + Args: + settings: + A Settings object that contains any default, overriden, or custom settings + required anywhere in the application. + """ + self.message: str = "Job Environment vars should start with and underscore:" self.on_fail: LintLevels = LintLevels.ERROR self.compatibility: List[Union[Workflow, Job, Step]] = [Job] self.settings: Settings = settings @@ -39,7 +51,7 @@ def fn(self, obj: Job) -> Tuple[bool, str]: correct = True offending_keys = [] - for key, value in obj.env.items(): + for key in obj.env.keys(): if key[0] != "_": offending_keys.append(key) correct = False diff --git a/lint-workflow/tests/rules/test_job_environment_prefix.py b/lint-workflow/tests/rules/test_job_environment_prefix.py index c77478f6..25f03c42 100644 --- a/lint-workflow/tests/rules/test_job_environment_prefix.py +++ b/lint-workflow/tests/rules/test_job_environment_prefix.py @@ -1,18 +1,16 @@ +"""Test src/rules/job_environment_prefix.""" import pytest from ruamel.yaml import YAML -from ..conftest import FIXTURE_DIR -from ..context import src - from src.load import WorkflowBuilder from src.rules.job_environment_prefix import RuleJobEnvironmentPrefix yaml = YAML() -@pytest.fixture -def correct_workflow(): +@pytest.fixture(name="correct_workflow") +def fixture_correct_workflow(): workflow = """\ --- on: @@ -29,8 +27,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 = """\ --- on: @@ -47,8 +45,8 @@ def incorrect_workflow(): return WorkflowBuilder.build(workflow=yaml.load(workflow), from_file=False) -@pytest.fixture -def rule(): +@pytest.fixture(name="rule") +def fixture_rule(): return RuleJobEnvironmentPrefix() @@ -56,7 +54,7 @@ def test_rule_on_correct_workflow(rule, correct_workflow): obj = correct_workflow.jobs["job-key"] result, message = rule.fn(correct_workflow.jobs["job-key"]) - assert result == True + assert result is True assert message == "" finding = rule.execute(obj) @@ -67,7 +65,7 @@ def test_rule_on_incorrect_workflow(rule, incorrect_workflow): obj = incorrect_workflow.jobs["job-key"] result, message = rule.fn(obj) - assert result == False + assert result is False assert "TEST_ENV" in message finding = rule.execute(obj)