Skip to content

Commit

Permalink
chore: Pass test suite
Browse files Browse the repository at this point in the history
  • Loading branch information
lewisjared committed Nov 6, 2024
1 parent 80376f0 commit 92cbc39
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/ref-celery/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ ref-celery = "ref_celery.cli:app"

[tool.uv]
dev-dependencies = [

"pytest-mock>=3.14.0",
]

[tool.uv.sources]
Expand Down
8 changes: 5 additions & 3 deletions packages/ref-celery/src/ref_celery/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,15 @@ def start_worker(
try:
imp = importlib.import_module(package.replace("-", "_")) # type: ignore
except ModuleNotFoundError:
raise ValueError(f"Package '{package}' not found")
typer.echo(f"Package '{package}' not found")
raise typer.Abort()

# Get the provider from the package
try:
provider = imp.provider
except AttributeError:
raise ValueError("The package must define a 'provider' variable")
typer.echo("The package must define a 'provider' variable")
raise typer.Abort()

# Wrap each metrics in the provider with a celery tasks
register_celery_tasks(celery_app, provider)
Expand All @@ -49,5 +51,5 @@ def start_worker(
celery_app.worker_main(argv=argv)


if __name__ == "__main__":
if __name__ == "__main__": # pragma: no cover
app()
33 changes: 33 additions & 0 deletions packages/ref-celery/tests/test_cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from ref_celery.cli import app
from typer.testing import CliRunner

runner = CliRunner()


def test_cli_help():
result = runner.invoke(app, ["--help"])
assert result.exit_code == 0


def test_cli_spawns_worker(mocker):
mock_app = mocker.patch("ref_celery.cli.create_celery_app")
result = runner.invoke(app, ["--package", "ref-metrics-example"])
assert result.exit_code == 0

mock_app().worker_main.assert_called_once()


def test_cli_wrong_package():
result = runner.invoke(app, ["--package", "missing"])
assert result.exit_code == 1

print(result.output)
assert "Package 'missing' not found" in result.output


def test_cli_missing_provider():
result = runner.invoke(app, ["--package", "pandas"])
assert result.exit_code == 1

print(result.output)
assert "The package must define a 'provider' variable" in result.output
1 change: 1 addition & 0 deletions packages/ref-celery/tests/test_tasks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# TODO: add tests for executing tasks
20 changes: 20 additions & 0 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 92cbc39

Please sign in to comment.