Example #1
0
 def test_create_task_with_and_without_result_handler(self):
     t1 = Task()
     assert t1.result_handler is None
     t2 = Task(result_handler=JSONResultHandler())
     assert isinstance(t2.result_handler, ResultHandler)
     assert isinstance(t2.result_handler, JSONResultHandler)
Example #2
0
 def test_create_task_with_retry_delay_and_invalid_max_retries(self, max_retries):
     with pytest.raises(
         ValueError,
         match="A `max_retries` argument greater than 0 must be provided if specifying a retry delay",
     ):
         Task(retry_delay=timedelta(seconds=30), max_retries=max_retries)
Example #3
0
 def test_pending_or_running_are_ok(self, state):
     flow = Flow(name="test", tasks=[Task()])
     new_state = FlowRunner(flow=flow).check_flow_is_pending_or_running(
         state=state)
     assert new_state is state
Example #4
0
 def test_task_check_mapped_args_are_subscriptable_in_advance(self):
     t = Task()
     with pytest.raises(TypeError):
         with Flow(name="test") as f:
             res = t.map({1, 2, 3, 4})
Example #5
0
def test_result_handler_option_shows_deprecation():
    with pytest.warns(
        UserWarning, match="the result_handler Task option will be deprecated*"
    ):
        Task(result_handler=object())
Example #6
0
 def test_deserialization(self):
     t = Task(name="test")
     s = t.serialize()
     t2 = prefect.serialization.task.TaskSchema().load(s)
     assert isinstance(t2, Task)
     assert t2.name == t.name
Example #7
0
 def test_task_args_raises_for_non_attrs(self):
     t = Task()
     with Flow(name="test") as f:
         with pytest.raises(AttributeError, match="foo"):
             res = t(task_args={"foo": "bar"})
Example #8
0
def test_task_produces_no_result():
    t = Task()
    assert t.run() is None
Example #9
0
def test_task_is_not_iterable():
    t = Task()
    with pytest.raises(TypeError):
        list(t)
Example #10
0
def test_task_has_logger_with_informative_name():
    t = Task(name="foo")
    assert isinstance(t.logger, logging.Logger)
    assert t.logger.name == "prefect.foo"
Example #11
0
 def test_create_task_is_not_auto_generated(self):
     assert Task().auto_generated is False
Example #12
0
def test_task_has_logger():
    t = Task()
    assert isinstance(t.logger, logging.Logger)
    assert t.logger.name == "prefect.Task"
Example #13
0
    def test_create_task_with_and_without_log_stdout(self):
        t = Task()
        assert t.log_stdout is False

        s = Task(log_stdout=True)
        assert s.log_stdout is True
Example #14
0
    def test_create_task_with_and_without_checkpoint(self):
        t = Task()
        assert t.checkpoint is None

        s = Task(checkpoint=True)
        assert s.checkpoint is True
Example #15
0
 def test_set_upstream_no_flow(self):
     f = Flow(name="test")
     t1 = Task()
     t2 = Task()
     with pytest.raises(ValueError, match="No Flow was passed"):
         t2.set_upstream(t1)
Example #16
0
    def test_create_task_with_name(self):
        t1 = Task()
        assert t1.name == "Task"

        t2 = Task(name="test")
        assert t2.name == "test"
Example #17
0
 def test_set_upstream_with_properties(self, props):
     with Flow(name="test") as f:
         t1 = Task()
         t2 = Task()
         t2.set_upstream(t1, **props)
         assert Edge(t1, t2, **props) in f.edges
Example #18
0
    def test_create_task_with_cache_key(self):
        t1 = Task()
        assert t1.cache_key is None

        t2 = Task(cache_key="test")
        assert t2.cache_key == "test"
Example #19
0
    def test_create_task_with_max_retries(self):
        t1 = Task()
        assert t1.max_retries == 0

        t2 = Task(max_retries=5, retry_delay=timedelta(0))
        assert t2.max_retries == 5
Example #20
0
 def test_copy_changes_slug(self):
     t1 = Task(slug="test")
     t2 = t1.copy()
     assert t1.slug == "test"
     assert t1.slug != t2.slug
Example #21
0
    def test_task_args_sets_new_attrs(self, attr, val):
        t = Task()
        with Flow(name="test") as f:
            res = t(task_args={attr: val})

        assert getattr(f.tasks.pop(), attr) == val
Example #22
0
 def test_copy_accepts_slug_as_task_args(self):
     t = Task(slug="test")
     t2 = t.copy(slug="test-2")
     assert t.slug == "test"
     assert t2.slug == "test-2"
Example #23
0
 def test_create_task_with_retry_delay(self):
     t2 = Task(retry_delay=timedelta(seconds=30), max_retries=1)
     assert t2.retry_delay == timedelta(seconds=30)
Example #24
0
def test_task_has_slug():
    t1 = Task()
    t2 = Task()

    assert t1.slug and t1.slug != t2.slug
Example #25
0
 def test_create_task_with_max_retries_and_no_retry_delay(self):
     with pytest.raises(ValueError):
         Task(max_retries=1, retry_delay=None)
Example #26
0
 def test_set_upstream(self):
     f = Flow(name="test")
     t1 = Task()
     t2 = Task()
     t2.set_upstream(t1, flow=f)
     assert Edge(t1, t2) in f.edges
Example #27
0
    def test_create_task_with_trigger(self):
        t1 = Task()
        assert t1.trigger is prefect.triggers.all_successful

        t2 = Task(trigger=prefect.triggers.all_failed)
        assert t2.trigger == prefect.triggers.all_failed
Example #28
0
 def test_set_upstream_context(self):
     with Flow(name="test") as f:
         t1 = Task()
         t2 = Task()
         t2.set_upstream(t1)
         assert Edge(t1, t2) in f.edges
Example #29
0
 def test_not_pending_or_running_raise_endrun(self, state):
     flow = Flow(name="test", tasks=[Task()])
     with pytest.raises(ENDRUN):
         FlowRunner(flow=flow).check_flow_is_pending_or_running(state=state)
Example #30
0
 def test_bad_cache_kwarg_combo(self):
     with pytest.warns(UserWarning, match=".*Task will not be cached.*"):
         Task(cache_validator=all_inputs)