コード例 #1
0
async def test_sync_main_runs_fully(tmpdir, should_verify_task):
    """``sync_main`` runs fully.

    """
    work_dir = str(tmpdir)
    config = {
        "work_dir":
        work_dir,
        "schema_file":
        os.path.join(os.path.dirname(__file__), "data", "basic_schema.json"),
    }
    with open(os.path.join(config["work_dir"], "task.json"), "w") as fh:
        fh.write(
            json.dumps({
                "this_is_a_task": True,
                "payload": {
                    "payload_required_property": "..."
                },
            }))
    async_main_calls = []
    run_until_complete_calls = []

    async def async_main(*args):
        async_main_calls.append(args)

    def count_run_until_complete(arg1):
        run_until_complete_calls.append(arg1)

    fake_loop = mock.MagicMock()
    fake_loop.run_until_complete = count_run_until_complete

    def loop_function():
        return fake_loop

    kwargs = {"loop_function": loop_function}

    if not should_verify_task:
        kwargs["should_verify_task"] = False

    config_path = os.path.join(tmpdir, "config.json")
    with open(config_path, "w") as fh:
        json.dump(config, fh)

    kwargs["config_path"] = config_path
    client.sync_main(async_main, **kwargs)

    for i in run_until_complete_calls:
        await i  # suppress coroutine not awaited warning
    assert len(
        run_until_complete_calls) == 1  # run_until_complete was called once
    assert len(async_main_calls) == 1  # async_main was called once
コード例 #2
0
def main(config_path=None):
    sync_main(async_main,
              config_path=config_path,
              default_config=get_default_config(),
              should_verify_task=False)
コード例 #3
0
def main():
    """Start signing script."""
    return sync_main(async_main, default_config=get_default_config())