Skip to content

Commit

Permalink
Fix linting issues for RuleNameCapitalized
Browse files Browse the repository at this point in the history
  • Loading branch information
joseph-flinn committed Jan 12, 2024
1 parent 2131363 commit bdc35b8
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 29 deletions.
9 changes: 9 additions & 0 deletions lint-workflow/src/rules/name_capitalized.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"""Enforce all 'name' values start with a capital letter."""
from typing import Union, Tuple

from ..rule import Rule
Expand All @@ -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
Expand Down
56 changes: 27 additions & 29 deletions lint-workflow/tests/rules/test_name_capitalized.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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:
Expand All @@ -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

0 comments on commit bdc35b8

Please sign in to comment.