Skip to content
This repository has been archived by the owner on Jan 14, 2024. It is now read-only.

Commit

Permalink
Increased coverage of tasks parsing in YAML parser
Browse files Browse the repository at this point in the history
  • Loading branch information
blackandred committed May 8, 2020
1 parent 6013731 commit bb6893c
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
1 change: 0 additions & 1 deletion src/rkd/syntax.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ def parse_name(name: str) -> tuple:
return task_name, group



class GroupDeclaration(GroupDeclarationInterface):
""" Internal DTO: Processed definition of TaskAliasDeclaration into TaskDeclaration """

Expand Down
21 changes: 21 additions & 0 deletions src/rkd/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from argparse import ArgumentParser
from .syntax import TaskDeclaration
from .contract import TaskInterface, ExecutionContext


class TestTask(TaskInterface):
def get_name(self) -> str:
pass

def get_group_name(self) -> str:
pass

def execute(self, context: ExecutionContext) -> bool:
pass

def configure_argparse(self, parser: ArgumentParser):
pass


def get_test_declaration() -> TaskDeclaration:
return TaskDeclaration(TestTask(), {}, [])
17 changes: 17 additions & 0 deletions test/test_yaml_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from rkd.inputoutput import IO, NullSystemIO, BufferedSystemIO
from rkd.exception import DeclarationException, YamlParsingException
from rkd.contract import ExecutionContext
from rkd.test import get_test_declaration


class TestYamlContext(unittest.TestCase):
Expand Down Expand Up @@ -94,3 +95,19 @@ def test_parse_tasks_signals_error_instead_of_throwing_exception(self):
self.assertEqual(False, result, msg='Expected that syntax error would result in a failure')
self.assertIn("NameError: name 'syntax' is not defined", io.get_value(), msg='Error message should be attached')
self.assertIn('File ":song@step 1", line 1', io.get_value(), msg='Stacktrace should be attached')

def test_create_bash_callable_successful_case(self):
""" Bash callable test: Successful case """

io = BufferedSystemIO()
factory = YamlParser(io)

declaration = get_test_declaration()

execute_callable = factory.create_bash_callable(
'python --version > /tmp/.test_create_bash_callable_successful_case', 500, ':test', '')
result = execute_callable(ExecutionContext(declaration), declaration.get_task_to_execute())

with open('/tmp/.test_create_bash_callable_successful_case', 'r') as test_result:
self.assertIn("Python", test_result.read())
self.assertTrue(result, msg='python --version should result with a True')

0 comments on commit bb6893c

Please sign in to comment.