Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Remove resolve_path from state click.Path, modify defer_state test to
test
  • Loading branch information
gshank committed May 26, 2023
commit 05d298b7624d363138ed64cad6edd6f507a0447e
2 changes: 1 addition & 1 deletion core/dbt/cli/params.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@
dir_okay=True,
file_okay=False,
readable=True,
resolve_path=True,
resolve_path=False,
path_type=Path,
),
)
Expand Down
32 changes: 19 additions & 13 deletions tests/functional/defer_state/test_defer_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,15 @@ def profiles_config_update(self, dbt_profile_target, unique_schema, other_schema
outputs["otherschema"]["schema"] = other_schema
return {"test": {"outputs": outputs, "target": "default"}}

def copy_state(self):
if not os.path.exists("state"):
os.makedirs("state")
shutil.copyfile("target/manifest.json", "state/manifest.json")
def copy_state(self, project_root):
state_path = os.path.join(project_root, "state")
if not os.path.exists(state_path):
os.makedirs(state_path)
shutil.copyfile(
f"{project_root}/target/manifest.json", f"{project_root}/state/manifest.json"
)

def run_and_save_state(self):
def run_and_save_state(self, project_root):
results = run_dbt(["seed"])
assert len(results) == 1
assert not any(r.node.deferred for r in results)
Expand All @@ -93,7 +96,7 @@ def run_and_save_state(self):
assert len(results) == 2

# copy files
self.copy_state()
self.copy_state(project_root)


class TestDeferStateUnsupportedCommands(BaseDeferState):
Expand All @@ -110,21 +113,24 @@ def test_no_state(self, project):

class TestRunCompileState(BaseDeferState):
def test_run_and_compile_defer(self, project):
self.run_and_save_state()
self.run_and_save_state(project.project_root)

# defer test, it succeeds
# Change directory to ensure that state directory is underneath
# project directory.
os.chdir(project.profiles_dir)
results = run_dbt(["compile", "--state", "state", "--defer"])
assert len(results.results) == 6
assert results.results[0].node.name == "seed"


class TestSnapshotState(BaseDeferState):
def test_snapshot_state_defer(self, project):
self.run_and_save_state()
self.run_and_save_state(project.project_root)
# snapshot succeeds without --defer
run_dbt(["snapshot"])
# copy files
self.copy_state()
self.copy_state(project.project_root)
# defer test, it succeeds
run_dbt(["snapshot", "--state", "state", "--defer"])
# favor_state test, it succeeds
Expand All @@ -134,7 +140,7 @@ def test_snapshot_state_defer(self, project):
class TestRunDeferState(BaseDeferState):
def test_run_and_defer(self, project, unique_schema, other_schema):
project.create_test_schema(other_schema)
self.run_and_save_state()
self.run_and_save_state(project.project_root)

# test tests first, because run will change things
# no state, wrong schema, failure.
Expand Down Expand Up @@ -186,7 +192,7 @@ def test_run_and_defer(self, project, unique_schema, other_schema):

class TestRunDeferStateChangedModel(BaseDeferState):
def test_run_defer_state_changed_model(self, project):
self.run_and_save_state()
self.run_and_save_state(project.project_root)

# change "view_model"
write_file(changed_view_model_sql, "models", "view_model.sql")
Expand Down Expand Up @@ -215,7 +221,7 @@ def test_run_defer_state_changed_model(self, project):
class TestRunDeferStateIFFNotExists(BaseDeferState):
def test_run_defer_iff_not_exists(self, project, unique_schema, other_schema):
project.create_test_schema(other_schema)
self.run_and_save_state()
self.run_and_save_state(project.project_root)

results = run_dbt(["seed", "--target", "otherschema"])
assert len(results) == 1
Expand All @@ -238,7 +244,7 @@ def test_run_defer_iff_not_exists(self, project, unique_schema, other_schema):
class TestDeferStateDeletedUpstream(BaseDeferState):
def test_run_defer_deleted_upstream(self, project, unique_schema, other_schema):
project.create_test_schema(other_schema)
self.run_and_save_state()
self.run_and_save_state(project.project_root)

# remove "ephemeral_model" + change "table_model"
rm_file("models", "ephemeral_model.sql")
Expand Down