-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix linting warnings for RuleNameExists
- Loading branch information
1 parent
bdc35b8
commit 9d91c1f
Showing
4 changed files
with
80 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,69 @@ | ||
"""Test src/rules/name_exists.py.""" | ||
import pytest | ||
from ..conftest import FIXTURE_DIR | ||
from ..context import src | ||
|
||
from src.load import WorkflowBuilder | ||
from src.rules.name_exists import RuleNameExists | ||
|
||
|
||
@pytest.fixture | ||
def correct_workflow(): | ||
return WorkflowBuilder.build(f"{FIXTURE_DIR}/test-min.yaml") | ||
@pytest.fixture(name="correct_workflow") | ||
def fixture_correct_workflow(): | ||
workflow = """\ | ||
--- | ||
name: Test Workflow | ||
on: | ||
workflow_dispatch: | ||
@pytest.fixture | ||
def incorrect_workflow(): | ||
return WorkflowBuilder.build(f"{FIXTURE_DIR}/test-min-incorrect.yaml") | ||
jobs: | ||
job-key: | ||
name: Test | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Test | ||
run: echo test | ||
""" | ||
return WorkflowBuilder.build(workflow=workflow, from_file=False) | ||
|
||
|
||
@pytest.fixture | ||
def rule(): | ||
@pytest.fixture(name="incorrect_workflow") | ||
def fixture_incorrect_workflow(): | ||
workflow = """\ | ||
--- | ||
on: | ||
workflow_dispatch: | ||
jobs: | ||
job-key: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- run: echo test | ||
""" | ||
return WorkflowBuilder.build(workflow=workflow, from_file=False) | ||
|
||
|
||
@pytest.fixture(name="rule") | ||
def fixture_rule(): | ||
return RuleNameExists() | ||
|
||
|
||
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(rule, incorrect_workflow): | ||
print(f"Workflow name: {incorrect_workflow.name}") | ||
result, message = rule.fn(incorrect_workflow) | ||
assert result == False | ||
result, _ = rule.fn(incorrect_workflow) | ||
assert result is False | ||
|
||
result, message = rule.fn(incorrect_workflow.jobs["job-key"]) | ||
assert result == False | ||
result, _ = rule.fn(incorrect_workflow.jobs["job-key"]) | ||
assert result is False | ||
|
||
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 |