Skip to content

Commit

Permalink
Fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
joseph-flinn committed Jan 11, 2024
1 parent a2930d8 commit fc9cbf7
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 19 deletions.
4 changes: 2 additions & 2 deletions lint-workflow/tests/rules/test_job_environment_prefix.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def correct_workflow():
steps:
- run: echo test
"""
return WorkflowBuilder.build(yaml=yaml.load(workflow), from_file=False)
return WorkflowBuilder.build(workflow=yaml.load(workflow), from_file=False)


@pytest.fixture
Expand All @@ -44,7 +44,7 @@ def incorrect_workflow():
steps:
- run: echo test
"""
return WorkflowBuilder.build(yaml=yaml.load(workflow), from_file=False)
return WorkflowBuilder.build(workflow=yaml.load(workflow), from_file=False)


@pytest.fixture
Expand Down
6 changes: 3 additions & 3 deletions lint-workflow/tests/rules/test_name_capitalized.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def correct_workflow():
- name: Test
run: echo test
"""
return WorkflowBuilder.build(yaml=yaml.load(workflow), from_file=False)
return WorkflowBuilder.build(workflow=yaml.load(workflow), from_file=False)


@pytest.fixture
Expand All @@ -47,7 +47,7 @@ def incorrect_workflow():
- name: test
run: echo test
"""
return WorkflowBuilder.build(yaml=yaml.load(workflow), from_file=False)
return WorkflowBuilder.build(workflow=yaml.load(workflow), from_file=False)


@pytest.fixture
Expand All @@ -63,7 +63,7 @@ def missing_name_workflow():
steps:
- run: echo test
"""
return WorkflowBuilder.build(yaml=yaml.load(workflow), from_file=False)
return WorkflowBuilder.build(workflow=yaml.load(workflow), from_file=False)


@pytest.fixture
Expand Down
1 change: 0 additions & 1 deletion lint-workflow/tests/rules/test_name_exists.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import pytest

from ..conftest import FIXTURE_DIR
from ..context import src

Expand Down
4 changes: 2 additions & 2 deletions lint-workflow/tests/rules/test_pinned_job_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def correct_runner():
steps:
- run: echo test
"""
return WorkflowBuilder.build(yaml=yaml.load(workflow), from_file=False)
return WorkflowBuilder.build(workflow=yaml.load(workflow), from_file=False)


@pytest.fixture
Expand All @@ -40,7 +40,7 @@ def incorrect_runner():
steps:
- run: echo test
"""
return WorkflowBuilder.build(yaml=yaml.load(workflow), from_file=False)
return WorkflowBuilder.build(workflow=yaml.load(workflow), from_file=False)


@pytest.fixture
Expand Down
4 changes: 2 additions & 2 deletions lint-workflow/tests/rules/test_step_approved.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def correct_workflow():
- name: Test Run Action
run: echo "test"
"""
return WorkflowBuilder.build(yaml=yaml.load(workflow), from_file=False)
return WorkflowBuilder.build(workflow=yaml.load(workflow), from_file=False)


@pytest.fixture
Expand All @@ -74,7 +74,7 @@ def incorrect_workflow():
- name: Out of date action
uses: actions/download-artifact@7a1cd3216ca9260cd8022db641d960b1db4d1be4 # v4.0.0
"""
return WorkflowBuilder.build(yaml=yaml.load(workflow), from_file=False)
return WorkflowBuilder.build(workflow=yaml.load(workflow), from_file=False)


@pytest.fixture
Expand Down
4 changes: 2 additions & 2 deletions lint-workflow/tests/rules/test_step_pinned.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def correct_workflow():
- name: Test Run Action
run: echo "test"
"""
return WorkflowBuilder.build(yaml=yaml.load(workflow), from_file=False)
return WorkflowBuilder.build(workflow=yaml.load(workflow), from_file=False)


@pytest.fixture
Expand All @@ -57,7 +57,7 @@ def incorrect_workflow():
- name: Test Internal Commit
uses: bitwarden/gh-actions/get-keyvault-secrets@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
"""
return WorkflowBuilder.build(yaml=yaml.load(workflow), from_file=False)
return WorkflowBuilder.build(workflow=yaml.load(workflow), from_file=False)


@pytest.fixture
Expand Down
9 changes: 2 additions & 7 deletions lint-workflow/tests/test_rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from ruamel.yaml import YAML

from src.load import WorkflowBuilder
from src.rule import Rule
from src.rule import Rule, RuleExecutionException
from src.models import Workflow, Job, Step


Expand Down Expand Up @@ -65,18 +65,13 @@ def fn(self, obj: Union[Workflow, Job, Step]) -> bool:
return obj.name is not None, self.message


class TestException(Exception):
"""Test Exception."""
pass


class RuleException(Rule):
def __init__(self):
self.message = "should raise Exception"
self.on_fail = "error"

def fn(self, obj: Union[Workflow, Job, Step]) -> bool:
raise TestException("test Exception")
raise RuleExecutionException("test Exception")


@pytest.fixture(name="step_rule")
Expand Down

0 comments on commit fc9cbf7

Please sign in to comment.