Esempio n. 1
0
def test_options(configure) -> None:
    logging.getLogger("myspace").setLevel(logging.INFO)

    o = NominalPipeline(
        loggernamespace="myspace",
        showprogress=False,
        dryrun=True,
        quick=True,
        force=True,
        verbose=True,
        timestamp="2020-01-01",
        date=datetime.date(2020, 1, 1),
    )
    assert o.loggernamespace == "myspace"
    assert not o.showprogress
    assert o.dryrun
    assert o.force
    assert o.verbose
    assert o.timestamp == "2020-01-01"
    assert o.date == datetime.date(2020, 1, 1)

    logger = addTestLogger(o)

    o.run()
    assert (logger.getvalue() ==
            """myspace.NominalTask - INFO - Hello, from NominalTask!
myspace.NominalTask - INFO - Called with options={'loggernamespace': 'myspace.NominalTask', 'showprogress': False, 'dryrun': True, 'quick': True, 'force': True, 'verbose': True, 'timestamp': '2020-01-01', 'date': datetime.date(2020, 1, 1)}
myspace.NominalTask2 - INFO - Hello, from NominalTask2!
myspace.NominalTask2 - INFO - Called with options={'loggernamespace': 'myspace.NominalTask2', 'showprogress': False, 'dryrun': True, 'quick': True, 'force': True, 'verbose': True, 'timestamp': '2020-01-01', 'date': datetime.date(2020, 1, 1)}
""")
Esempio n. 2
0
def test_dryrun_stubbedvalue(configure) -> None:
    o = StubbedTask(dryrun=True, stubbedValue="Foo")
    logger = addTestLogger(o)

    o.run()
    assert (
        logger.getvalue()
        == "simpletasks.StubbedTask - INFO - Stubbed\nsimpletasks.StubbedTask - INFO - Stubbed\n"
    )
Esempio n. 3
0
def test_debugging(configure) -> None:
    Task.DEBUGGING = True
    o = FailureTask()
    logger = addTestLogger(o)

    with pytest.raises(RuntimeError) as e:
        o.run()
    assert str(e.value) == "error"
    assert logger.getvalue() == ""
Esempio n. 4
0
def test_nominal(configure) -> None:
    o = NominalTask()
    assert o.loggernamespace == "simpletasks.NominalTask"
    assert o.timestamp == datetime.datetime.now().strftime("%Y-%m-%d")
    assert o.date == datetime.date.today()

    logger = addTestLogger(o)

    o.run()
    assert logger.getvalue() == "simpletasks.NominalTask - INFO - Hello, from NominalTask!\n"
Esempio n. 5
0
def test_failure(configure) -> None:
    o = FailureTask()
    logger = addTestLogger(o)

    with pytest.raises(RuntimeError) as e:
        o.run()
    assert str(e.value) == "error"
    output = logger.getvalue()
    assert output.startswith("simpletasks.FailureTask - CRITICAL - Got exception: RuntimeError error\n")
    assert output.endswith("RuntimeError: error\n")
Esempio n. 6
0
def test_pipeline(configure) -> None:
    o = NominalPipeline()
    logger = addTestLogger(o)

    o.run()
    assert (
        logger.getvalue() ==
        """simpletasks.NominalPipeline.NominalTask - INFO - Hello, from NominalTask!
simpletasks.NominalPipeline.NominalTask - INFO - Called with options={'loggernamespace': 'simpletasks.NominalPipeline.NominalTask'}
simpletasks.NominalPipeline.NominalTask2 - INFO - Hello, from NominalTask2!
simpletasks.NominalPipeline.NominalTask2 - INFO - Called with options={'loggernamespace': 'simpletasks.NominalPipeline.NominalTask2'}
""")
Esempio n. 7
0
def test_orchestrator(configure) -> None:
    o = Orch(show_progress=False, dryrun=True, verbose=True)
    task_logger = addTestLogger(o)

    foo_logger = io.StringIO()
    ch = logging.StreamHandler(foo_logger)
    ch.setLevel(logging.DEBUG)
    ch.setFormatter(
        logging.Formatter("%(name)s - %(levelname)s - %(message)s"))
    logging.getLogger("simpletasks.Foo").addHandler(ch)

    with pytest.raises(RuntimeError) as e:
        o.run()
    assert str(e.value) == "Task failed"

    output = task_logger.getvalue()
    assert "simpletasks.Orch - INFO - Starting task NominalTask" in output
    assert (
        "simpletasks.Orch - DEBUG - Starting task NominalTask using arguments: {'show_progress': False, 'dryrun': True, 'verbose': True, 'loggernamespace': 'simpletasks.Orch.NominalTask'}"
        in output)
    assert (
        "simpletasks.Orch.NominalTask - INFO - Hello, from NominalTask, called with options={'show_progress': False, 'dryrun': True, 'verbose': True, 'loggernamespace': 'simpletasks.Orch.NominalTask'}"
        in output)
    assert "simpletasks.Orch - INFO - Completed task NominalTask: True" in output

    assert "simpletasks.Orch - INFO - Starting task NominalTask2" in output
    assert (
        "simpletasks.Orch - DEBUG - Starting task NominalTask2 using arguments: {'show_progress': True, 'dryrun': True, 'verbose': True, 'loggernamespace': 'simpletasks.Orch.NominalTask2'}"
        in output)
    assert (
        "simpletasks.Orch.NominalTask2 - INFO - Hello, from NominalTask2, called with options={'show_progress': True, 'dryrun': True, 'verbose': True, 'loggernamespace': 'simpletasks.Orch.NominalTask2'}"
        in output)
    assert "simpletasks.Orch - INFO - Completed task NominalTask2: True" in output

    assert "simpletasks.Orch - INFO - Starting task FailureTask" in output
    assert (
        "simpletasks.Orch - DEBUG - Starting task FailureTask using arguments: {'show_progress': False, 'dryrun': True, 'verbose': True, 'loggernamespace': 'simpletasks.Orch.FailureTask'}"
        in output)

    assert "simpletasks.Orch - INFO - Starting task NominalTask3" not in output
    assert "simpletasks.Orch - INFO - Completed task NominalTask3: True" not in output

    assert "simpletasks.Orch - INFO - Starting task NominalTask4" not in output
    assert "simpletasks.Orch.NominalTask4 - INFO - Hello, from NominalTask4!" not in output
    assert "simpletasks.Orch - INFO - Completed task NominalTask4: True" not in output

    assert (
        """simpletasks.Orch.FailureTask - CRITICAL - Got exception: RuntimeError error
Traceback (most recent call last):
""" in output)
    assert "simpletasks.Orch - CRITICAL - Could not run FailureTask: RuntimeError error" in output

    assert foo_logger.getvalue() == ""
Esempio n. 8
0
def test_tempfailureretry(configure) -> None:
    o = TempsFailureRetryTask()
    logger = addTestLogger(o)

    o.run()
    assert (
        logger.getvalue()
        == """simpletasks.TempsFailureRetryTask - WARNING - Failed 1 times (error), retrying in 0 seconds...
simpletasks.TempsFailureRetryTask - WARNING - Failed 2 times (error), retrying in 0 seconds...
simpletasks.TempsFailureRetryTask - WARNING - Failed 3 times (error), retrying in 0 seconds...
simpletasks.TempsFailureRetryTask - INFO - OK!
"""
    )
Esempio n. 9
0
def test_progress_hidden(configure) -> None:
    o = ProgressTask(progress=False)
    logger = addTestLogger(o)

    o.run()
    assert (
        logger.getvalue()
        == """simpletasks.ProgressTask - INFO - Hello, from ProgressTask!
simpletasks.ProgressTask - INFO - loop #1
simpletasks.ProgressTask - INFO - loop #2
simpletasks.ProgressTask - INFO - loop #3
"""
    )
Esempio n. 10
0
def test_failure(configure) -> None:
    o = FailurePipeline()
    logger = addTestLogger(o)

    with pytest.raises(RuntimeError) as e:
        o.run()
    assert str(e.value) == "error"

    output = logger.getvalue()
    assert output.startswith(
        """simpletasks.FailurePipeline.NominalTask - INFO - Hello, from NominalTask!
simpletasks.FailurePipeline.NominalTask - INFO - Called with options={'loggernamespace': 'simpletasks.FailurePipeline.NominalTask'}
simpletasks.FailurePipeline.FailureTask - CRITICAL - Got exception: RuntimeError error
Traceback (most recent call last):
""")
    assert output.endswith("""RuntimeError: error
""")
Esempio n. 11
0
def test_failureretry(configure) -> None:
    o = FailureRetryTask()
    logger = addTestLogger(o)

    with pytest.raises(RuntimeError) as e:
        o.run()
    assert str(e.value) == "error"
    output = logger.getvalue()
    assert output.startswith(
        """simpletasks.FailureRetryTask - WARNING - Failed 1 times (error), retrying in 0 seconds...
simpletasks.FailureRetryTask - WARNING - Failed 2 times (error), retrying in 0 seconds...
simpletasks.FailureRetryTask - WARNING - Failed 3 times (error), retrying in 0 seconds...
simpletasks.FailureRetryTask - WARNING - Failed 4 times (error), retrying in 0 seconds...
simpletasks.FailureRetryTask - WARNING - Failed 5 times (error), retrying in 1 seconds...
simpletasks.FailureRetryTask - WARNING - Too many failures, abandonning
simpletasks.FailureRetryTask - CRITICAL - Got exception: RuntimeError error
"""
    )
    assert output.endswith("RuntimeError: error\n")
Esempio n. 12
0
def test_orchestrator_deadlock(configure) -> None:
    o = OrchDeadlock()
    task_logger = addTestLogger(o)

    o.run()

    output = task_logger.getvalue()
    assert "simpletasks.OrchDeadlock - INFO - Starting task NominalTask" in output
    assert (
        "simpletasks.OrchDeadlock - DEBUG - Starting task NominalTask using arguments: {'loggernamespace': 'simpletasks.OrchDeadlock.NominalTask'}"
        in output)
    assert "simpletasks.OrchDeadlock - INFO - Completed task NominalTask: True" in output

    assert "simpletasks.OrchDeadlock - INFO - Starting task NominalTask2" in output
    assert (
        "simpletasks.OrchDeadlock - DEBUG - Starting task NominalTask2 using arguments: {'loggernamespace': 'simpletasks.OrchDeadlock.NominalTask2'}"
        in output)
    assert "simpletasks.OrchDeadlock - INFO - Completed task NominalTask2: True" in output

    assert "simpletasks.OrchDeadlock - CRITICAL - Done but some tasks remaining: NominalTask4" in output
Esempio n. 13
0
def test_failure_catched(configure) -> None:
    o = FailurePipeline(fail_on_exception=False)
    logger = addTestLogger(o)

    with pytest.raises(RuntimeError) as e:
        o.run()
    assert str(e.value) == "Task failed"

    output = logger.getvalue()
    assert output.startswith(
        """simpletasks.FailurePipeline.NominalTask - INFO - Hello, from NominalTask!
simpletasks.FailurePipeline.NominalTask - INFO - Called with options={'fail_on_exception': False, 'loggernamespace': 'simpletasks.FailurePipeline.NominalTask'}
simpletasks.FailurePipeline.FailureTask - CRITICAL - Got exception: RuntimeError error
Traceback (most recent call last):
""")
    assert ("""RuntimeError: error
simpletasks.FailurePipeline.NominalTask2 - INFO - Hello, from NominalTask2!
simpletasks.FailurePipeline.NominalTask2 - INFO - Called with options={'fail_on_exception': False, 'loggernamespace': 'simpletasks.FailurePipeline.NominalTask2'}
simpletasks.FailurePipeline - CRITICAL - Could not run FailureTask: RuntimeError error
simpletasks.FailurePipeline - CRITICAL - Got exception: RuntimeError Task failed
""" in output)
    assert output.endswith("""RuntimeError: Task failed
""")
Esempio n. 14
0
def test_options(configure) -> None:
    logging.getLogger("myspace").setLevel(logging.INFO)

    o = NominalTask(
        loggernamespace="myspace",
        showprogress=False,
        quick=True,
        force=True,
        verbose=True,
        timestamp="2020-01-01",
        date=datetime.date(2020, 1, 1),
    )
    assert o.loggernamespace == "myspace"
    assert not o.showprogress
    assert o.force
    assert o.verbose
    assert o.timestamp == "2020-01-01"
    assert o.date == datetime.date(2020, 1, 1)

    logger = addTestLogger(o)

    o.run()
    assert logger.getvalue() == "myspace - INFO - Hello, from NominalTask!\n"