def pipline_that_has_airflow():
     t1 = TTask()
     t2 = BashOperator(task_id="sleep",
                       bash_command="sleep 0.1",
                       retries=3)
     t1.set_upstream(t2)
     return t1
Exemplo n.º 2
0
    def _test_run(self, databand_test_context):
        task = TTask()
        run = task.dbnd_run()

        self.task = task
        self.task_af_id = run.get_task_run_by_id(task.task_id).task_af_id
        self.dag_id = task.task_name
        self.task_execution_date_str = airflow_datetime_str(run.execution_date)
Exemplo n.º 3
0
 def test_dbnd_run(self, tmpdir):
     t = targets.target(tmpdir.join("task_output"))
     args = [
         TTask.get_task_family(), "-r", "t_param=10", "-r",
         "t_output=" + t.path
     ]
     run_dbnd_subprocess_test(args)
     assert t.exists()
Exemplo n.º 4
0
 def test_sign_by_task_code_build(self):
     with new_dbnd_context(
             conf={"task_build": {
                 "sign_with_full_qualified_name": "True"
             }}):
         task = TTask()
         assert str(
             TTask.__module__) in task.task_meta.task_signature_source
Exemplo n.º 5
0
    def test_wrong_config_validation(self):
        # raise exception
        with pytest.raises(UnknownParameterError) as e:
            with config({
                    "TTask": {
                        "t_parammm": 2,
                        "validate_no_extra_params": ParamValidation.error,
                    }
            }):
                TTask()

        assert "Did you mean: t_param" in e.value.help_msg

        # log warning to log
        with config({
                "TTask": {
                    "t_parammm": 2,
                    "validate_no_extra_params": ParamValidation.warn,
                }
        }):
            TTask()
        # tried to add a capsys assert here but couldn't get it to work

        # do nothing
        with config({
                "TTask": {
                    "t_parammm": 2,
                    "validate_no_extra_params": ParamValidation.disabled,
                }
        }):
            TTask()

        # handle core config sections too
        with pytest.raises(
                DatabandError
        ):  # might be other extra params in the config in which case a DatabandBuildError will be raised
            with config({
                    "config": {
                        "validate_no_extra_params": ParamValidation.error
                    },
                    "core": {
                        "blabla": "bla"
                    },
            }):
                CoreConfig()
Exemplo n.º 6
0
 def test_exception(self):
     s = TTask(t_param="my_param")
     try:
         raise Exception("MyException")
     except Exception:
         actual = TaskVisualiser(s).banner("Runinng task",
                                           exc_info=sys.exc_info())
         assert actual
         assert "MyException" in actual
Exemplo n.º 7
0
    def test_inconsistent_output(self, monkeypatch):
        from dbnd._core.task_run.task_run_runner import TaskRunRunner

        task = TTask()
        with initialized_run(task):
            validator = task.ctrl.validator

            with monkeypatch.context() as m:
                m.setattr(FileTarget, "exist_after_write_consistent",
                          lambda a: False)
                m.setattr(FileTarget, "exists", lambda a: False)
                m.setattr(
                    dbnd._core.task_ctrl.task_validator,
                    "EVENTUAL_CONSISTENCY_MAX_SLEEPS",
                    1,
                )
                assert not validator.wait_for_consistency()
Exemplo n.º 8
0
 def band(self):
     self.t_output = TTask(t_param=SomeObject(1)).t_output
Exemplo n.º 9
0
 def test_cmdline_main_task_cls(self):
     dbnd_run_cmd([TTask.get_task_family(), "-r", "t_param=100"])
Exemplo n.º 10
0
 def ret_dict():
     v = TTask(t_param=1)
     return v
Exemplo n.º 11
0
 def test_task_version_parse(self):
     target = TTask(task_version="now")
     assert target.task_version != "now"
Exemplo n.º 12
0
 def band(self):
     t_inputs = {t: TTask(t_param=t).t_output for t in self.t_types}
     self.t_output = TTaskCombineInputs(t_inputs=t_inputs).t_output
Exemplo n.º 13
0
 def test_input_task(self):
     t = TTaskWithInput(t_input=TTask())
     assert_run_task(t)
Exemplo n.º 14
0
 def band(self):
     self.t_output = {
         t: TTask(t_param=t).t_output
         for t in self.t_types
     }
Exemplo n.º 15
0
 def test_dbnd_help(self):
     stdout = run_dbnd_subprocess_test([TTask.get_task_family(), "--help"])
     assert "-r", "t_param" in stdout
Exemplo n.º 16
0
 def test_task_call_source_class(self):
     task = TTask()
     logger.info(task.task_meta.task_call_source)
     assert task.task_meta.task_call_source
     assert task.task_meta.task_call_source[0].filename in __file__
Exemplo n.º 17
0
 def test_verbose_build(self):
     with new_dbnd_context(conf={"task_build": {"verbose": "True"}}):
         task = TTask(override={TTask.t_param: "test_driver"})
         assert task.t_param == "test_driver"
Exemplo n.º 18
0
 def test_object_parameters_immutable(self):
     assert (TTask(t_param=SomeObject(1)).task_id !=
             TTask(t_param=SomeObject(2)).task_id)
Exemplo n.º 19
0
 def test_save_time_1(self, benchmark):
     s = TTask()
     self._benchmark_pipeline_save(benchmark=benchmark, pipeline=s)
Exemplo n.º 20
0
 def band(self):
     return TTask(t_param=1)
Exemplo n.º 21
0
    def test_save_databand_run(self):
        s = TTask()
        r = self._save_graph(s)

        actual = DatabandRun.load_run(r.driver_dump, False)
        assert actual
Exemplo n.º 22
0
 def test_simple_dump(self):
     s = TTask(t_param="my_param")
     actual = TaskVisualiser(s).banner("Runinng task")
     assert "my_param" in actual