Skip to content

Commit

Permalink
Rename with tests flag
Browse files Browse the repository at this point in the history
  • Loading branch information
iadrich committed Jan 17, 2024
1 parent 870baf8 commit c9e1246
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 33 deletions.
23 changes: 12 additions & 11 deletions sayn/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def __init__(
full_load=False,
start_dt=None,
end_dt=None,
run_tests=False,
with_tests=False,
fail_fast=False,
):
super().__init__()
Expand Down Expand Up @@ -70,8 +70,8 @@ def __init__(
if upstream_prod is not None:
self.run_arguments.upstream_prod = upstream_prod

if run_tests is not None:
self.run_arguments.run_tests = run_tests
if with_tests is not None:
self.run_arguments.with_tests = with_tests

if fail_fast is not None:
self.run_arguments.fail_fast = fail_fast
Expand Down Expand Up @@ -125,11 +125,11 @@ def parser_process(value, state):
"--debug", "-d", is_flag=True, default=False, help="Include debug messages"
)

click_include_tests = click.option(
"--run-tests",
click_with_tests = click.option(
"--with-tests",
is_flag=True,
default=False,
help="Include Tests in task execution - after task run.",
help="Include Tests in task execution.",
)

click_fail_fast = click.option(
Expand Down Expand Up @@ -212,6 +212,7 @@ def init(sayn_project_name):


@cli.command(help="Compile sql tasks.")
@click_with_tests
@click_run_options
def compile(
debug,
Expand All @@ -222,7 +223,7 @@ def compile(
full_load,
start_dt,
end_dt,
run_tests,
with_tests,
fail_fast,
):

Expand All @@ -238,7 +239,7 @@ def compile(
full_load,
start_dt,
end_dt,
run_tests,
with_tests,
fail_fast,
)

Expand All @@ -250,7 +251,7 @@ def compile(


@cli.command(help="Run SAYN tasks.")
@click_include_tests
@click_with_tests
@click_run_options
def run(
debug,
Expand All @@ -261,7 +262,7 @@ def run(
full_load,
start_dt,
end_dt,
run_tests,
with_tests,
fail_fast,
):

Expand All @@ -277,7 +278,7 @@ def run(
full_load,
start_dt,
end_dt,
run_tests,
with_tests,
fail_fast,
)

Expand Down
7 changes: 5 additions & 2 deletions sayn/core/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class Folders:
command: Command = Command.UNDEFINED
upstream_prod: bool = False
is_prod: bool = False
run_tests: bool = False
with_tests: bool = False
fail_fast: bool = False

include: Set[str]
Expand Down Expand Up @@ -177,7 +177,10 @@ def start_app(self):

# Set the tasks for the project and call their config method

if self.run_arguments.command != Command.TEST:
if (
self.run_arguments.command != Command.TEST
and not self.run_arguments.with_tests
):
tasks_dict = {k: v for k, v in tasks_dict.items() if v["type"] != "test"}

self.check_abort(self.set_tasks(tasks_dict))
Expand Down
2 changes: 1 addition & 1 deletion sayn/tasks/copy.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ def config(self, **config): # noqa: C901
return result

if (
self.run_arguments["command"] == "test" or self.run_arguments["run_tests"]
self.run_arguments["command"] == "test" or self.run_arguments["with_tests"]
) and len(self.columns["columns"]) > 0:
result = self.target_db._construct_tests(
self.columns["columns"], self.table, self.schema
Expand Down
2 changes: 1 addition & 1 deletion sayn/tasks/sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ def def_out(obj, level=None):
self.ddl = result.value

if (
self.run_arguments["command"] == "test" or self.run_arguments["run_tests"]
self.run_arguments["command"] == "test" or self.run_arguments["with_tests"]
) and len(self.ddl["columns"]) != 0:
result = self.target_db._construct_tests(
self.ddl["columns"], self.table, self.schema
Expand Down
6 changes: 3 additions & 3 deletions sayn/tasks/task_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def __init__(

self.run_arguments = {
"debug": run_arguments.debug,
"run_tests": run_arguments.run_tests,
"with_tests": run_arguments.with_tests,
"full_load": run_arguments.full_load,
"start_dt": run_arguments.start_dt,
"end_dt": run_arguments.end_dt,
Expand Down Expand Up @@ -382,11 +382,11 @@ def execute_task(self, command):
try:
if command == "run":
result = self.runner.run()
if self.run_arguments["run_tests"] and self.has_tests():
if self.run_arguments["with_tests"] and self.has_tests():
result = self.runner.test()
elif command == "compile":
result = self.runner.compile()
if self.run_arguments["run_tests"] and self.has_tests():
if self.run_arguments["with_tests"] and self.has_tests():
result = self.runner.test()
else:
result = self.runner.test()
Expand Down
3 changes: 3 additions & 0 deletions sayn/tasks/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ def setup(self):
self.test_query += " LIMIT 5\n"
return Ok()

def run(self):
return self.test()

def test(self):
step_queries = {
"Write Test Query": self.test_query,
Expand Down
2 changes: 1 addition & 1 deletion tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def simulate_task(

run_arguments = {
"debug": obj_run_arguments.debug,
"run_tests": obj_run_arguments.run_tests,
"with_tests": obj_run_arguments.with_tests,
"full_load": obj_run_arguments.full_load,
"start_dt": obj_run_arguments.start_dt,
"end_dt": obj_run_arguments.end_dt,
Expand Down
28 changes: 14 additions & 14 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ def cli():


@cli.command()
@tcli.click_include_tests
@tcli.click_with_tests
@tcli.click_run_options
def run(
debug,
run_tests,
with_tests,
fail_fast,
tasks,
exclude,
Expand All @@ -41,7 +41,7 @@ def run(
return {
"command": "run",
"debug": debug,
"run_tests": run_tests,
"with_tests": with_tests,
"include": tasks,
"exclude": exclude,
"profile": profile,
Expand Down Expand Up @@ -100,7 +100,7 @@ def test_simple_run():
assert output == {
"command": "run",
"debug": False,
"run_tests": False,
"with_tests": False,
"fail_fast": False,
"include": [],
"exclude": [],
Expand Down Expand Up @@ -133,7 +133,7 @@ def test_run_one_task():
assert output == {
"command": "run",
"debug": False,
"run_tests": False,
"with_tests": False,
"fail_fast": False,
"include": ["something"],
"exclude": [],
Expand All @@ -150,7 +150,7 @@ def test_run_two_tasks_old():
assert output == {
"command": "run",
"debug": False,
"run_tests": False,
"with_tests": False,
"fail_fast": False,
"include": ["something", "somethingelse"],
"exclude": [],
Expand All @@ -167,7 +167,7 @@ def test_run_two_tasks_new():
assert output == {
"command": "run",
"debug": False,
"run_tests": False,
"with_tests": False,
"fail_fast": False,
"include": ["something", "somethingelse"],
"exclude": [],
Expand Down Expand Up @@ -232,7 +232,7 @@ def test_run_debug():
assert output == {
"command": "run",
"debug": True,
"run_tests": False,
"with_tests": False,
"fail_fast": False,
"include": ["something"],
"exclude": [],
Expand Down Expand Up @@ -265,7 +265,7 @@ def test_run_debug_multitasks():
assert output == {
"command": "run",
"debug": True,
"run_tests": False,
"with_tests": False,
"fail_fast": False,
"include": ["something", "somethingelse", "somesomeelse"],
"exclude": [],
Expand Down Expand Up @@ -299,7 +299,7 @@ def test_run_fail_fast():
"command": "run",
"debug": False,
"fail_fast": True,
"run_tests": False,
"with_tests": False,
"include": ["something"],
"exclude": [],
"profile": None,
Expand Down Expand Up @@ -348,7 +348,7 @@ def test_run_fail_fast_multitasks():
"command": "run",
"debug": False,
"fail_fast": True,
"run_tests": False,
"with_tests": False,
"include": ["something", "somethingelse", "somesomeelse"],
"exclude": [],
"profile": None,
Expand All @@ -364,7 +364,7 @@ def test_run_full():
assert output == {
"command": "run",
"debug": False,
"run_tests": False,
"with_tests": False,
"fail_fast": False,
"include": ["something"],
"exclude": [],
Expand Down Expand Up @@ -397,7 +397,7 @@ def test_run_exclude():
assert output == {
"command": "run",
"debug": False,
"run_tests": False,
"with_tests": False,
"fail_fast": False,
"include": [],
"exclude": ["something"],
Expand Down Expand Up @@ -430,7 +430,7 @@ def test_run_include_exclude():
assert output == {
"command": "run",
"debug": False,
"run_tests": False,
"with_tests": False,
"fail_fast": False,
"include": ["somethingelse"],
"exclude": ["something"],
Expand Down

0 comments on commit c9e1246

Please sign in to comment.