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

Commit

Permalink
#66: Fixes after removal of :init task
Browse files Browse the repository at this point in the history
  • Loading branch information
blackandred committed Aug 18, 2021
1 parent ff8f0be commit e633f9c
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 42 deletions.
2 changes: 1 addition & 1 deletion src/core/rkd/core/argparsing/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ def preparse_global_arguments_before_tasks(args: List[str]):

limited_args = []

for arg in args[1:]:
for arg in args:
# parse everything before any task or block starts
if arg.startswith(':') or arg.startswith('@') or arg.startswith('{@'):
break
Expand Down
5 changes: 3 additions & 2 deletions src/core/rkd/core/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,13 @@ def main(self, argv: list):
if not CommandlineParsingHelper.has_any_task(argv) and not CommandlineParsingHelper.was_help_used(argv):
self.print_banner_and_exit()

self.increment_depth()

# parse arguments that are before tasks e.g. rkd --help (in comparison to rkd :task1 --help)
pre_parsed_args = CommandlineParsingHelper.preparse_global_arguments_before_tasks(argv)
pre_parsed_args = CommandlineParsingHelper.preparse_global_arguments_before_tasks(argv[1:])

# system wide IO instance with defaults
io = self.setup_global_io(pre_parsed_args)
self.increment_depth()

cmdline_parser = CommandlineParsingHelper(io)

Expand Down
7 changes: 0 additions & 7 deletions src/core/tests/test_argparsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,6 @@ def test_creates_grouped_arguments_into_tasks__task_after_flag(self):
"\"ArgumentBlock<[':status'], [TaskCall<:status ([])>]>\"]",
str(self.list_to_str(parsed)))

def test_creates_grouped_arguments_into_tasks__no_task_defined_goes_to_rkd_initialization(self):
parsed = CommandlineParsingHelper(IO()).create_grouped_arguments([
'--help'
])

self.assertEqual("[TaskCall<rkd:initialize (['--help'])>]", str(parsed[0].tasks()))

def test_creates_grouped_arguments_into_tasks__tasks_only(self):
parsed = CommandlineParsingHelper(IO()).create_grouped_arguments([
':harbor:start', ':harbor:status', ':harbor:stop'
Expand Down
19 changes: 9 additions & 10 deletions src/core/tests/test_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
from rkd.core.api.syntax import GroupDeclaration
from rkd.core.api.testing import BasicTestingCase
from rkd.core.test import TaskForTesting
from rkd.core.standardlib import InitTask

TESTS_DIR = os.path.dirname(os.path.realpath(__file__))

Expand Down Expand Up @@ -189,10 +188,10 @@ def _common_test_loads_task_from_file(self, path: str, task: str, filename: str)

def test_context_resolves_recursively_task_aliases(self):
ctx = ApplicationContext([
TaskDeclaration(InitTask())
TaskDeclaration(TaskForTesting())
], [
TaskAliasDeclaration(':deeper', [':init', ':init']),
TaskAliasDeclaration(':deep', [':init', ':deeper'])
TaskAliasDeclaration(':deeper', [':test', ':test']),
TaskAliasDeclaration(':deep', [':test', ':deeper'])
], directory='',
subprojects=[],
workdir='',
Expand All @@ -205,15 +204,15 @@ def test_context_resolves_recursively_task_aliases(self):

# :deeper = :init
# :deep = :init :deeper = :init :init :init
self.assertEqual(':init', task.get_declarations()[0].to_full_name())
self.assertEqual(':init', task.get_declarations()[1].to_full_name())
self.assertEqual(':init', task.get_declarations()[2].to_full_name())
self.assertEqual(':test', task.get_declarations()[0].to_full_name())
self.assertEqual(':test', task.get_declarations()[1].to_full_name())
self.assertEqual(':test', task.get_declarations()[2].to_full_name())

def test_expand_contexts_expands_one_context(self) -> None:
# MAIN PROJECT context
ctx = ApplicationContext(
tasks=[
TaskDeclaration(InitTask())
TaskDeclaration(TaskForTesting())
],
aliases=[
TaskAliasDeclaration(':kropotkin', [':init', ':init']),
Expand All @@ -227,7 +226,7 @@ def test_expand_contexts_expands_one_context(self) -> None:
# SUBPROJECT context
subproject_1_ctx = ApplicationContext(
tasks=[
TaskDeclaration(InitTask())
TaskDeclaration(TaskForTesting())
],
aliases=[
TaskAliasDeclaration(':book', [':init', ':init']),
Expand Down Expand Up @@ -255,7 +254,7 @@ def test_expand_contexts_expands_one_context(self) -> None:
def test_expand_contexts_ignores_subprojects_if_no_any(self):
ctx = ApplicationContext(
tasks=[
TaskDeclaration(InitTask())
TaskDeclaration(TaskForTesting())
],
aliases=[
TaskAliasDeclaration(':malatesta', [':init', ':init']),
Expand Down
4 changes: 2 additions & 2 deletions src/core/tests/test_contract_execution_context.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#!/usr/bin/env python3

from rkd.core.standardlib import InitTask
from rkd.core.api.contract import ExecutionContext
from rkd.core.api.contract import ArgumentEnv
from rkd.core.api.syntax import TaskDeclaration
from rkd.core.api.inputoutput import IO
from rkd.core.api.testing import BasicTestingCase
from rkd.core.exception import MissingInputException
from rkd.core.test import TaskForTesting


class TestExecutionContext(BasicTestingCase):
Expand Down Expand Up @@ -104,7 +104,7 @@ def test_get_arg_or_env(self):
# Actual test code
#
def test(dataset_name, dataset):
task = InitTask()
task = TaskForTesting()
task._io = IO()
task.get_declared_envs = lambda: dataset['declared_envs']

Expand Down
40 changes: 20 additions & 20 deletions src/core/tests/test_taskutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,32 @@
from collections import OrderedDict
from io import StringIO
from rkd.core.api.testing import BasicTestingCase, OutputCapturingSafeTestCase
from rkd.core.standardlib import InitTask
from rkd.core.api.inputoutput import IO, BufferedSystemIO
from rkd.core.taskutil import evaluate_code
from rkd.core.test import TaskForTesting

CURRENT_SCRIPT_PATH = os.path.dirname(os.path.realpath(__file__))


class TestTaskUtil(BasicTestingCase, OutputCapturingSafeTestCase):
def test_sh_accepts_script_syntax(self):
task = InitTask()
task = TaskForTesting()
task._io = IO()
self.assertIn('__init__.py', task.sh("ls -la rkd/core\npwd", capture=True))

def test_exec_spawns_process(self):
task = InitTask()
task = TaskForTesting()
task._io = IO()
self.assertIn('__init__.py', task.exec('ls rkd/core', capture=True))

def test_sh_executes_in_background(self):
task = InitTask()
task = TaskForTesting()
task._io = IO()
task.exec('ls', background=True)

def test_exec_background_capture_validation_raises_error(self):
def test():
task = InitTask()
task = TaskForTesting()
task._io = IO()
task.exec('ls', background=True, capture=True)

Expand All @@ -47,7 +47,7 @@ def test_sh_captures_output_in_correct_order_with_various_timing(self):
"""
for i in range(1, 100):
self.maxDiff = None # unittest setting
task = InitTask()
task = TaskForTesting()
task._io = IO()

io = IO()
Expand Down Expand Up @@ -78,7 +78,7 @@ def test_sh_producing_large_outputs(self):
"""

self.maxDiff = None # unittest setting
task = InitTask()
task = TaskForTesting()
task._io = IO()

io = IO()
Expand Down Expand Up @@ -109,7 +109,7 @@ def test_sh_captures_output_in_correct_order_with_fixed_timing(self):

for i in range(1, 30):
self.maxDiff = None # unittest setting
task = InitTask()
task = TaskForTesting()
task._io = IO()

io = IO()
Expand All @@ -135,7 +135,7 @@ def test_sh_rkd_in_rkd_shows_first_lines_on_error(self):

for i in range(1, 5):
for std_redirect in ['', '>&2']:
task = InitTask()
task = TaskForTesting()
task._io = IO()
io = IO()
out = StringIO()
Expand All @@ -159,7 +159,7 @@ def test_non_interactive_session_returns_output(self):
should be turned off for stdin
"""

task = InitTask()
task = TaskForTesting()
task._io = IO()
io = IO()
out = StringIO()
Expand All @@ -175,7 +175,7 @@ def test_full_command_is_shown_only_in_debug_output_level(self):
:return:
"""

task = InitTask()
task = TaskForTesting()
task._io = IO()
io = IO()
out = StringIO()
Expand All @@ -201,7 +201,7 @@ def test_full_command_is_shown_only_in_debug_output_level(self):
def test_dollar_symbols_are_escaped_in_shell_commands(self):
"""Check that in envrionment variable there can be defined a value that contains dollar symbols"""

task = InitTask()
task = TaskForTesting()
task._io = IO()
io = IO()
out = StringIO()
Expand All @@ -216,7 +216,7 @@ def test_dollar_symbols_are_escaped_in_shell_commands(self):
self.assertIn('TEST_ENV_NOT_ESCAPED=Hello Mikhail$1Bakunin$PATHtest', out.getvalue())

def test_quotes_are_escaped_in_shell_commands(self):
task = InitTask()
task = TaskForTesting()
task._io = IO()
io = IO()
out = StringIO()
Expand All @@ -233,7 +233,7 @@ def test_sh_3rd_depth_rkd_calls(self):
"""

for std_redirect in ['', '>&2']:
task = InitTask()
task = TaskForTesting()
task._io = IO()
io = IO()
out = StringIO()
Expand All @@ -251,7 +251,7 @@ def test_sh_3rd_depth_rkd_calls(self):

@unittest.skip("Github issue #1")
def test_sh_provides_stdout_and_stderr_in_exception(self):
task = InitTask()
task = TaskForTesting()
task._io = IO()

try:
Expand All @@ -269,7 +269,7 @@ def test_sh_has_valid_order_of_defining_environment_variables(self):
"""Checks if built-in sh() method is registering variables in proper order
"""

task = InitTask()
task = TaskForTesting()
task._io = IO()

envs = OrderedDict()
Expand All @@ -285,7 +285,7 @@ def test_sh_has_valid_order_of_defining_environment_variables(self):
def test_py_executes_python_scripts_without_specifying_script_path(self):
"""Simply - check basic successful case - executing a Python code"""

task = InitTask()
task = TaskForTesting()
task._io = IO()
out = task.py('''
import os
Expand All @@ -299,7 +299,7 @@ def test_py_executes_a_custom_python_script(self):
And the code will be passed to that script as stdin.
"""

task = InitTask()
task = TaskForTesting()
task._io = IO()

with NamedTemporaryFile() as temp_file:
Expand All @@ -313,7 +313,7 @@ def test_py_executes_a_custom_python_script(self):
def test_py_inherits_environment_variables(self):
os.putenv('PY_INHERITS_ENVIRONMENT_VARIABLES', 'should')

task = InitTask()
task = TaskForTesting()
task._io = IO()
out = task.py(
code='import os; print("ENV VALUE IS: " + str(os.environ["PY_INHERITS_ENVIRONMENT_VARIABLES"]))',
Expand All @@ -325,7 +325,7 @@ def test_py_inherits_environment_variables(self):
def test_py_uses_sudo_when_become_specified(self):
"""Expect that sudo with proper parameters is used"""

task = InitTask()
task = TaskForTesting()
task._io = IO()

with unittest.mock.patch('rkd.core.taskutil.check_output') as mocked_subprocess:
Expand Down

0 comments on commit e633f9c

Please sign in to comment.