Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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
Ejemplo n.º 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})
Ejemplo n.º 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())
Ejemplo n.º 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
Ejemplo n.º 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"})
Ejemplo n.º 8
0
def test_task_produces_no_result():
    t = Task()
    assert t.run() is None
Ejemplo n.º 9
0
def test_task_is_not_iterable():
    t = Task()
    with pytest.raises(TypeError):
        list(t)
Ejemplo n.º 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"
Ejemplo n.º 11
0
 def test_create_task_is_not_auto_generated(self):
     assert Task().auto_generated is False
Ejemplo n.º 12
0
def test_task_has_logger():
    t = Task()
    assert isinstance(t.logger, logging.Logger)
    assert t.logger.name == "prefect.Task"
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 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)
Ejemplo n.º 16
0
    def test_create_task_with_name(self):
        t1 = Task()
        assert t1.name == "Task"

        t2 = Task(name="test")
        assert t2.name == "test"
Ejemplo n.º 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
Ejemplo n.º 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"
Ejemplo n.º 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
Ejemplo n.º 20
0
 def test_copy_changes_slug(self):
     t1 = Task(slug="test")
     t2 = t1.copy()
     assert t1.slug == "test"
     assert t1.slug != t2.slug
Ejemplo n.º 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
Ejemplo n.º 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"
Ejemplo n.º 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)
Ejemplo n.º 24
0
def test_task_has_slug():
    t1 = Task()
    t2 = Task()

    assert t1.slug and t1.slug != t2.slug
Ejemplo n.º 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)
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 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)
Ejemplo n.º 30
0
 def test_bad_cache_kwarg_combo(self):
     with pytest.warns(UserWarning, match=".*Task will not be cached.*"):
         Task(cache_validator=all_inputs)