From 2d2b4430ffd6844c99b7773bb2dc81c3bc8cc1c8 Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Mon, 6 Dec 2021 23:20:18 +0100 Subject: [PATCH] Add initial cli test --- .gitignore | 2 +- pyproject.toml | 1 + src/habitmove/cli.py | 5 ----- tests/__init__.py | 0 tests/test_cli.py | 10 ++++++++++ 5 files changed, 12 insertions(+), 6 deletions(-) create mode 100644 tests/__init__.py create mode 100644 tests/test_cli.py diff --git a/.gitignore b/.gitignore index 6fe089d..7397c55 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ -testdata/ +data/ output.db # Created by https://www.toptal.com/developers/gitignore/api/vim,linux,python,pandas diff --git a/pyproject.toml b/pyproject.toml index 47a9483..a7b28dc 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -13,6 +13,7 @@ python = "^3.9" click = "^8.0" [tool.poetry.dev-dependencies] +pytest = "^6.2" [tool.poetry.scripts] habitmove = "habitmove.cli:main" diff --git a/src/habitmove/cli.py b/src/habitmove/cli.py index acc2a66..489cb8a 100755 --- a/src/habitmove/cli.py +++ b/src/habitmove/cli.py @@ -9,9 +9,6 @@ import click from . import __version__ -import sys - - def migrate(data: NomieImport): db = schema.migrate("output.db") if not db: @@ -32,8 +29,6 @@ def migrate(data: NomieImport): @click.version_option(version=__version__) @click.argument("inputfile") def main(inputfile): - # TODO test and error gracefully for no input given - # file = sys.argv[1] data = nomie.get_data(inputfile) migrate(data) diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/test_cli.py b/tests/test_cli.py new file mode 100644 index 0000000..ffd50e3 --- /dev/null +++ b/tests/test_cli.py @@ -0,0 +1,10 @@ +import click.testing + +from habitmove import cli + + +def test_cli_fails_without_file(): + runner = click.testing.CliRunner() + result = runner.invoke(cli.main) + assert result.exit_code == 2 + assert "Missing argument" in result.output