Beispiel #1
0
def semantic_operation(
    flow: Flow,
    upstream_repos: Dict[str, str] = None,
    versions_to_retain=1,
) -> Iterator["SemanticOperation"]:
    workspaces = checkout(upstream_repos=upstream_repos, )

    op = SemanticOperation(workspaces=workspaces)

    yield op

    repo_tags = sematic_bump(workspaces=workspaces, )

    committed_repo_uris = commit(
        workspaces=workspaces,
        upstream_tasks=flow.terminal_tasks(),
    )

    tagged_repo_uris = push(
        sgr_tags=repo_tags,
        workspaces=workspaces,
        upstream_tasks=[committed_repo_uris],
    )
    cleanup = sematic_cleanup(
        retain=versions_to_retain,
        repo_uris=tagged_repo_uris,
    )

    op.commit = committed_repo_uris
    op.push = tagged_repo_uris
    op.cleanup = cleanup
flow.add_edge(upstream_task=e, downstream_task=t, key="x")
flow.add_edge(upstream_task=t, downstream_task=l, key="x")

state = flow.run()

# Testing state

assert state.is_successful
assert state.result[e].is_successful
assert state.result[t].is_successful
assert state.result[l].is_successful

# Testing results

assert state.result[e].result == 10
assert state.result[t].result == 20
assert state.result[l].result == None

# Flow composition

assert e in flow.tasks
assert t in flow.tasks
assert l in flow.tasks
assert len(flow.tasks) == 3

assert flow.root_tasks() == set([e])
assert flow.terminal_tasks() == set([l])

assert len(flow.edges) == 2
assert Edge(upstream_task=e, downstream_task=t, key="x") in flow.edges
assert Edge(upstream_task=t, downstream_task=l, key="x") in flow.edges