Skip to content

Commit

Permalink
Add cli application
Browse files Browse the repository at this point in the history
  • Loading branch information
oyvindeide authored and andreas-el committed Sep 13, 2023
1 parent 866bbba commit 5397063
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ jobs:
python-version: "3.11"
- name: Install test requirements
run: pip install -r dev-requirements.txt
- name: Install tdd_workshop
run: pip install .
- name: Check black
run: black --check .
- name: Check typing
Expand Down
5 changes: 4 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@
"Programming Language :: Python :: 3.11",
"Topic :: Learning :: Software Test",
],
entry_points={
"console_scripts": ["treasure-hunt=tdd_workshop.cli:main"],
},
packages=find_packages(where="src", exclude=["tests"]),
package_dir={"": "src"},
install_requires=[],
install_requires=["click"],
test_suite="tests",
)
9 changes: 9 additions & 0 deletions src/tdd_workshop/cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import click
from tdd_workshop.io import read_coordinates # type: ignore


@click.command()
@click.argument("file_name", type=click.Path(exists=True))
def main(file_name: str) -> None:
coordinates = read_coordinates(file_name)
print(f"Read file: {file_name}, coordinates: {coordinates}")
27 changes: 27 additions & 0 deletions tests/unit/test_cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from click.testing import CliRunner

from src.tdd_workshop.cli import main


def test_that_cli_fails_when_file_is_missing():
runner = CliRunner()
result = runner.invoke(main, ["not_a_file"])
assert result.exit_code != 0
assert " Path 'not_a_file' does not exist" in result.output


def test_that_cli_prints_coordinates(monkeypatch, tmp_path):
monkeypatch.chdir(tmp_path)
expected_coordinates_list = [
("2.0", "1.9"),
("2.5", "1.5"),
("3.3", "7.3"),
]
with open("test_input", "w", encoding="utf-8") as fout:
fout.write("\n".join(",".join(coords) for coords in expected_coordinates_list))
runner = CliRunner()
result = runner.invoke(main, ["test_input"])
assert result.exit_code == 0
assert (
"coordinates: [('2.0', '1.9'), ('2.5', '1.5'), ('3.3', '7.3')]" in result.output
)

0 comments on commit 5397063

Please sign in to comment.