From f0b7c39d3e51092a851b006b6601853392a72fe6 Mon Sep 17 00:00:00 2001 From: goFrendiAsgard Date: Wed, 29 Nov 2023 17:06:17 +0700 Subject: [PATCH] add test for non-renderable env --- test/task/test_task.py | 22 ---------------------- test/task/test_task_env.py | 27 +++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 22 deletions(-) diff --git a/test/task/test_task.py b/test/task/test_task.py index df91d1e7..0391128c 100644 --- a/test/task/test_task.py +++ b/test/task/test_task.py @@ -1,5 +1,4 @@ from zrb.task.task import Task -from zrb.task.cmd_task import CmdTask from zrb.task_input.str_input import StrInput import asyncio @@ -103,24 +102,3 @@ def test_callable_as_task_should_execute_value(): function = task.to_function() result = function() assert result == 'articuno' - - -def test_consistent_execution_id(): - task_upstream_1 = Task( - name='task-upstream-1', - run=lambda *args, **kwargs: kwargs.get('_task').get_execution_id() - ) - task_upstream_2 = CmdTask( - name='task-upstream-2', - cmd='echo $_ZRB_EXECUTION_ID' - ) - task = Task( - name='task', - upstreams=[ - task_upstream_1, task_upstream_2 - ], - return_upstream_result=True - ) - function = task.to_function() - result = function() - assert result[0] == result[1].output diff --git a/test/task/test_task_env.py b/test/task/test_task_env.py index 60ba4c6d..026f6f76 100644 --- a/test/task/test_task_env.py +++ b/test/task/test_task_env.py @@ -30,6 +30,33 @@ def _run(*args, **kwargs) -> str: assert result == 'Elixir of immortality' +def test_task_env_with_should_not_be_rendered_jinja_value(): + def _run(*args, **kwargs) -> str: + task: Task = kwargs.get('_task') + env_map = task.get_env_map() + return env_map.get('ZRB_TEST_TASK_ENV_2') + task = Task( + name='templated-env', + envs=[ + Env(name='ZRB_TEST_TASK_ENV_1', default='Elixir'), + Env( + name='ZRB_TEST_TASK_ENV_2', + default='{{env.ZRB_TEST_TASK_ENV_1}} of immortality', + should_render=False + ) + ], + run=_run, + retry=0 + ) + function = task.to_function() + if 'ZRB_TEST_TASK_ENV_1' in os.environ: + del os.environ['ZRB_TEST_TASK_ENV_1'] + if 'ZRB_TEST_TASK_ENV_2' in os.environ: + del os.environ['ZRB_TEST_TASK_ENV_2'] + result = function() + assert result == '{{env.ZRB_TEST_TASK_ENV_1}} of immortality' + + def test_task_env_with_none_as_os_name(): ''' When env exist, it should override env_file