From c9e12461de16bd9245c1afe309968ae5fe952334 Mon Sep 17 00:00:00 2001 From: Adrian Macias <56698+iadrich@users.noreply.github.com> Date: Wed, 17 Jan 2024 19:02:57 +0000 Subject: [PATCH] Rename with tests flag --- sayn/cli.py | 23 ++++++++++++----------- sayn/core/app.py | 7 +++++-- sayn/tasks/copy.py | 2 +- sayn/tasks/sql.py | 2 +- sayn/tasks/task_wrapper.py | 6 +++--- sayn/tasks/test.py | 3 +++ tests/__init__.py | 2 +- tests/test_cli.py | 28 ++++++++++++++-------------- 8 files changed, 40 insertions(+), 33 deletions(-) diff --git a/sayn/cli.py b/sayn/cli.py index 7437cabe..1bc75e69 100644 --- a/sayn/cli.py +++ b/sayn/cli.py @@ -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__() @@ -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 @@ -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( @@ -212,6 +212,7 @@ def init(sayn_project_name): @cli.command(help="Compile sql tasks.") +@click_with_tests @click_run_options def compile( debug, @@ -222,7 +223,7 @@ def compile( full_load, start_dt, end_dt, - run_tests, + with_tests, fail_fast, ): @@ -238,7 +239,7 @@ def compile( full_load, start_dt, end_dt, - run_tests, + with_tests, fail_fast, ) @@ -250,7 +251,7 @@ def compile( @cli.command(help="Run SAYN tasks.") -@click_include_tests +@click_with_tests @click_run_options def run( debug, @@ -261,7 +262,7 @@ def run( full_load, start_dt, end_dt, - run_tests, + with_tests, fail_fast, ): @@ -277,7 +278,7 @@ def run( full_load, start_dt, end_dt, - run_tests, + with_tests, fail_fast, ) diff --git a/sayn/core/app.py b/sayn/core/app.py index 00c46791..78fb5925 100644 --- a/sayn/core/app.py +++ b/sayn/core/app.py @@ -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] @@ -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)) diff --git a/sayn/tasks/copy.py b/sayn/tasks/copy.py index 570d129f..5064a669 100644 --- a/sayn/tasks/copy.py +++ b/sayn/tasks/copy.py @@ -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 diff --git a/sayn/tasks/sql.py b/sayn/tasks/sql.py index b9085cc2..ec41ccaa 100644 --- a/sayn/tasks/sql.py +++ b/sayn/tasks/sql.py @@ -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 diff --git a/sayn/tasks/task_wrapper.py b/sayn/tasks/task_wrapper.py index 24c8b2cc..8639dbb6 100644 --- a/sayn/tasks/task_wrapper.py +++ b/sayn/tasks/task_wrapper.py @@ -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, @@ -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() diff --git a/sayn/tasks/test.py b/sayn/tasks/test.py index 9f68c18a..ace1445f 100644 --- a/sayn/tasks/test.py +++ b/sayn/tasks/test.py @@ -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, diff --git a/tests/__init__.py b/tests/__init__.py index 929cfa25..b18b8179 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -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, diff --git a/tests/test_cli.py b/tests/test_cli.py index 452c1803..16c70594 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -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, @@ -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, @@ -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": [], @@ -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": [], @@ -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": [], @@ -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": [], @@ -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": [], @@ -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": [], @@ -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, @@ -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, @@ -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": [], @@ -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"], @@ -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"],