-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
866bbba
commit 5397063
Showing
4 changed files
with
42 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) |