Skip to content

Commit

Permalink
shipit
Browse files Browse the repository at this point in the history
  • Loading branch information
dave-connors-3 committed Jul 7, 2023
1 parent 538f7fd commit 65a351d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
24 changes: 16 additions & 8 deletions dbt_meshify/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@
logger.add(sys.stdout, format=log_format)


class FatalMeshifyException(click.ClickException):
def __init__(self, message):
super().__init__(message)

def show(self):
logger.error(self.message)
if self.__cause__ is not None:
logger.exception(self.__cause__)


# define cli group
@click.group()
def cli():
Expand Down Expand Up @@ -96,8 +106,7 @@ def split(project_name, select, exclude, project_path, selector, create_path):
subproject_creator.initialize()
logger.success(f"Successfully created subproject {subproject.name}")
except Exception as e:
logger.error(f"Error creating subproject {subproject.name}")
logger.exception(e)
raise FatalMeshifyException(f"Error creating subproject {subproject.name}")


@operation.command(name="add-contract")
Expand Down Expand Up @@ -134,8 +143,7 @@ def add_contract(select, exclude, project_path, selector, public_only=False):
meshify_constructor.add_model_contract()
logger.success(f"Successfully added contract to model: {model_unique_id}")
except Exception as e:
logger.error(f"Error adding contract to model: {model_unique_id}")
logger.exception(e)
raise FatalMeshifyException(f"Error adding contract to model: {model_unique_id}")


@operation.command(name="add-version")
Expand Down Expand Up @@ -168,8 +176,9 @@ def add_version(select, exclude, project_path, selector, prerelease, defined_in)
meshify_constructor.add_model_version(prerelease=prerelease, defined_in=defined_in)
logger.success(f"Successfully added version to model: {model_unique_id}")
except Exception as e:
logger.error(f"Error adding version to model: {model_unique_id}")
logger.exception(e)
raise FatalMeshifyException(
f"Error adding version to model: {model_unique_id}"
) from e


@operation.command(name="create-group")
Expand Down Expand Up @@ -230,8 +239,7 @@ def create_group(
)
logger.success(f"Successfully created group: {name}")
except Exception as e:
logger.error(f"Error creating group: {name}")
logger.exception(e)
raise FatalMeshifyException(f"Error creating group: {name}")


@cli.command(name="group")
Expand Down
7 changes: 2 additions & 5 deletions tests/integration/test_version_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,17 +123,16 @@ def test_add_version_to_yml(start_yml, end_yml, start_files, expected_files, com


@pytest.mark.parametrize(
"start_yml,start_files,command_options",
"start_yml,start_files",
[
(
model_yml_string_version,
["shared_model.sql"],
[],
),
],
ids=["1"],
)
def test_add_version_to_invalid_yml(start_yml, start_files, command_options):
def test_add_version_to_invalid_yml(start_yml, start_files):
yml_file = proj_path / "models" / "_models.yml"
reset_model_files(start_files)
yml_file.parent.mkdir(parents=True, exist_ok=True)
Expand All @@ -146,10 +145,8 @@ def test_add_version_to_invalid_yml(start_yml, start_files, command_options):
with open(yml_file, "w+") as f:
yaml.safe_dump(start_yml_content, f, sort_keys=False)
base_command = ["--select", "shared_model", "--project-path", proj_path_string]
base_command.extend(command_options)
result = runner.invoke(add_version, base_command, catch_exceptions=True)
assert result.exit_code == 1
assert "Version not an integer" in str(result.exception)
# reset the read path to the default in the logic
yml_file.unlink()
reset_model_files(["shared_model.sql"])

0 comments on commit 65a351d

Please sign in to comment.