Skip to content

Commit

Permalink
Merge 6e79b3c into e6b51eb
Browse files Browse the repository at this point in the history
  • Loading branch information
leonkozlowski committed Feb 22, 2020
2 parents e6b51eb + 6e79b3c commit 93bf3c8
Show file tree
Hide file tree
Showing 10 changed files with 141 additions and 41 deletions.
21 changes: 21 additions & 0 deletions examples/jiggy-playbook-passing.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Eureka
author: xyz@jiggy.dev
description: This is a passing JiggyPlaybook
version: 0.0.1

pipeline:
runner: sequential
secrets:
location: ../examples/secrets/.env-example
source: jiggy.EnvSecrets
tasks:

- name: print-somethin
description: Print something
function:
source: jpl.rules.pipeline.pipeline.PipelineHasRunner
params:
- type: str
value: 'THIS PIPELINE IS BONKERS'
output: null
requires: null
8 changes: 2 additions & 6 deletions jpl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@
class JiggyPlaybookLint(object): # pragma no cover
"""Runner for jpl."""

def __init__(self, path: str, allow_warning=False, show=None):
def __init__(self, path: str, allow_warning=False):
self.playbook = self._read(path)
self.aw = allow_warning
self.show = show
self.exe = ["PASSED"]

def run(self):
Expand All @@ -34,9 +33,6 @@ def run(self):

jiggy_response.append(init_rule)

if self.show:
jiggy_response = [rule for rule in jiggy_response if rule.mark != "PASSED"]

return jiggy_response

def validate(self) -> tuple:
Expand All @@ -55,7 +51,7 @@ def validate(self) -> tuple:

prevent = list(filter(lambda rule: rule.mark not in self.exe, response))

return (prevent is None, prevent)
return bool(not prevent), prevent

@staticmethod
def _read(path: str): # pragma no cover
Expand Down
2 changes: 1 addition & 1 deletion jpl/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import jpl


def main():
def main(): # pragma no cover
"""Entrypoint to the `jpl` main command."""

if sys.path[0] == "" or sys.path[0] == os.getcwd():
Expand Down
11 changes: 11 additions & 0 deletions jpl/cli/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
"""Configuration for CLI."""

################
# CLICK COLORS #
################

MARK_TO_COLOR = {
"PASSED": "green",
"WARNING": "yellow",
"FAILED": "red"
}
56 changes: 28 additions & 28 deletions jpl/cli/main_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import click
import jpl

MARK_TO_COLOR = {"PASSED": "green", "WARNING": "yellow", "FAILED": "red"}
import jpl.cli.config as config


@click.command()
Expand All @@ -18,7 +18,7 @@
help="Show `PASSED` rules in jpl report",
)
@click.option("-p", "--playbook", required=True, help="Filepath to Jiggy Playbook")
def lint(verbose, show, playbook):
def lint(verbose, show, playbook): # pragma no cover
"""Click CLI entrypoint to run JiggyPlaybookLint.
CLI Args:
Expand All @@ -43,18 +43,22 @@ def lint(verbose, show, playbook):
\/_____/iggy \/_/laybook \/_____/inter
"""
)
linted = jpl.JiggyPlaybookLint(path=playbook, show=show).run()

generate_jpl_report(linted=linted, verbose=verbose)
linted = jpl.JiggyPlaybookLint(path=playbook).run()
generate_jpl_report(linted=linted, show=show, verbose=verbose)


def generate_jpl_report(linted: list, verbose=None): # pragma no cover
def generate_jpl_report(
linted: list, show: bool, verbose=None, passing=True
): # pragma no cover
"""
Generate `Click` response for jpl linter.
Args:
linted: (list) - array of JiggyRule response objects
show: (bool) - boolean flag to show "PASSED" rules in CLI
verbose: (count) - flag to denote response with verbosity
passing: (bool) - indicator for CLI success message
Returns:
click.echo - `with style`
Expand All @@ -66,29 +70,25 @@ def generate_jpl_report(linted: list, verbose=None): # pragma no cover
rule.rule, rule.__class__.__name__, rule.task
)

if verbose == 1:
click.echo(
"{:<50}{:<20} {}".format(
rule_meta,
click.style(rule.mark, fg=MARK_TO_COLOR.get(rule.mark)),
rule.message,
)
)
elif verbose > 1:
click.echo(
"{:<50}{:<20} {} \nPriority: `{}` - Description: `{}`\n".format(
rule_meta,
click.style(rule.mark, fg=MARK_TO_COLOR.get(rule.mark)),
rule.message,
rule.priority,
rule.description,
)
)
else:
click.echo(
"{:<50}{:<50}".format(
rule_meta, click.style(rule.mark, fg=MARK_TO_COLOR.get(rule.mark))
)
if show and rule.mark == "PASSED":
continue

passing = False
resp = "{:<50}{:<30}".format(
rule_meta,
click.style(rule.mark, bold=True, fg=config.MARK_TO_COLOR.get(rule.mark)),
)

if verbose:
resp = "{} {}".format(resp, rule.message)

click.echo(resp)

if passing:
click.echo(
click.style(
"All checks passed - Time to get jiggy wit' it!", fg="green"
)
)

return exit()
2 changes: 1 addition & 1 deletion jpl/rules/jiggyrule.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"""


class JiggyRule(object):
class JiggyRule(object): # pragma no cover
"""Base class for JiggyRule."""

rule = ""
Expand Down
6 changes: 3 additions & 3 deletions jpl/rules/task/function.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,11 @@ def run(self, playbook: dict) -> str:
return self.param_has_attr_value(playbook)


class FunctionOutputIsSingular(JiggyRule):
class FunctionOutputObject(JiggyRule):
"""Validate task.function.prams has `type` and `value`"""

rule = "F04"
description = "Validate `JiggyPlaybook.pipeline.task.function.output` is singular."
description = "Validate `JiggyPlaybook.pipeline.task.function.output` structure."
priority = "high"
commands = ["command", "core"]
mark = "PASSED"
Expand Down Expand Up @@ -138,5 +138,5 @@ def run(self, playbook: dict) -> str:
FunctionSourceExists,
ParamHasType,
ParamHasValue,
FunctionOutputIsSingular,
FunctionOutputObject,
]
Empty file added tests/integration/__init__.py
Empty file.
72 changes: 72 additions & 0 deletions tests/integration/test_integration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
"""Integration test modules."""
import pytest

from unittest import TestCase

from jpl import JiggyPlaybookLint


class TestJiggyPlaybookLintEmpty(TestCase):
"""Integration test client (empty)."""
def setUp(self):
"""Build JiggyPlaybookLintClient."""
self.empty_jpl = JiggyPlaybookLint(
path="../examples/jiggy-playbook-empty.yml"
)

def test_validate(self):
"""Emptry TestCase for jpl."""
validity_result, jpl_response = self.empty_jpl.validate()

assert validity_result is False
assert len(jpl_response) == 1


class TestJiggyPlaybookLintPassing(TestCase):
"""Integration test client (passing)."""
def setUp(self):
"""Build JiggyPlaybookLintClient."""
self.passing_jpl = JiggyPlaybookLint(
path="../examples/jiggy-playbook-passing.yml"
)

def test_validate(self):
"""Passing TestCase for jpl."""
validity_result, jpl_response = self.passing_jpl.validate()

assert validity_result is True
assert not jpl_response


class TestJiggyPlaybookLintBasic(TestCase):
"""Integration test client (basic)."""
def setUp(self):
"""Build JiggyPlaybookLintClient."""
self.basic_jpl = JiggyPlaybookLint(
path="../examples/jiggy-playbook.yml",
allow_warning=False,
)

def test_validate(self):
"""Basic TestCase for jpl."""
validity_result, jpl_response = self.basic_jpl.validate()

assert validity_result is False
assert len(jpl_response) == 7


class TestJiggyPlaybookLintComplex(TestCase):
"""Integration test client (basic)."""
def setUp(self):
"""Build JiggyPlaybookLintClient."""
self.complex_jpl = JiggyPlaybookLint(
path="../examples/jiggy-playbook-flawed.yml",
allow_warning=False,
)

def test_validate(self):
"""Basic TestCase for jpl."""
validity_result, jpl_response = self.complex_jpl.validate()

assert validity_result is False
assert len(jpl_response) == 15
4 changes: 2 additions & 2 deletions tests/testRules/test_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
FunctionSourceExists,
ParamHasType,
ParamHasValue,
FunctionOutputIsSingular
FunctionOutputObject
)

from tests.test_utils import load_from_json
Expand Down Expand Up @@ -104,7 +104,7 @@ def test_param_has_value(task, expected):
]
)
def test_output_is_singular(task, expected):
rule = FunctionOutputIsSingular()
rule = FunctionOutputObject()
result = rule.run(
playbook=task
)
Expand Down

0 comments on commit 93bf3c8

Please sign in to comment.