Skip to content
This repository was archived by the owner on Feb 17, 2021. It is now read-only.

Commit 1705923

Browse files
author
Thiago C. D'Ávila
authored
Merge pull request #256 from staticdev/update-error-status-code
Update error status code
2 parents fb16bee + 0faaa0d commit 1705923

6 files changed

Lines changed: 55 additions & 48 deletions

File tree

.github/workflows/constraints.txt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
pip==20.3.3
2-
nox==2020.12.31
3-
poetry==1.1.4
1+
pip==20.2.4
2+
nox==2020.8.22
3+
poetry==1.1.2
4+
virtualenv==20.2.1

.github/workflows/dependabot.yml

Lines changed: 0 additions & 22 deletions
This file was deleted.

poetry.lock

Lines changed: 19 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ flake8 = "^3.8.4"
2525
flake8-bandit = "^2.1.2"
2626
flake8-bugbear = "^20.11.1"
2727
safety = "^1.10.2"
28-
mypy = "^0.790"
2928
pytest-mock = "^3.5.1"
3029
typeguard = "^2.10.0"
3130
pre-commit = "^2.9.3"
@@ -39,6 +38,7 @@ flake8-rst-docstrings = "^0.0.14"
3938
pep8-naming = "^0.11.1"
4039
pre-commit-hooks = "^3.4.0"
4140
reorder-python-imports = "^2.3.6"
41+
mypy = "0.782"
4242

4343
[tool.poetry.scripts]
4444
toml-validator = "toml_validator.__main__:main"

src/toml_validator/__main__.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
"""Command-line interface."""
2+
import sys
3+
24
import click
35

46
from . import validation
@@ -8,14 +10,25 @@
810
@click.argument("filename", type=click.Path(exists=True))
911
@click.version_option()
1012
def main(filename: str) -> None:
11-
"""Makes validations and echos errors if found."""
13+
"""Makes validations and echos errors if found.
14+
15+
Args:
16+
filename: name of validated file.
17+
18+
Return status:
19+
* 0: no errors found
20+
* 1: incorrect usage
21+
* 2: invalid path
22+
* 3: errors found
23+
"""
1224
validation.validate_extension(filename)
1325

1426
click.secho("Reading file {}.".format(filename), fg="blue")
1527

1628
errors = validation.validate_toml(filename)
1729
if errors:
1830
click.secho("Error(s) found: {}.".format(errors), fg="red")
31+
sys.exit(3)
1932
else:
2033
click.secho("No problems found parsing file {}!".format(filename), fg="green")
2134

tests/test_main.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,22 @@ def test_main_with_argument_success(
6060
assert result.exit_code == 0
6161

6262

63-
def test_main_with_argument_fail(
63+
def test_main_with_invalid_path(
64+
runner: click.testing.CliRunner,
65+
mock_validation_validate_extension: Mock,
66+
mock_validation_validate_toml_with_error: Mock,
67+
) -> None:
68+
"""It outputs error."""
69+
with runner.isolated_filesystem():
70+
with open("file.toml", "w") as f:
71+
f.write("content doesnt matter")
72+
73+
result = runner.invoke(__main__.main, ["file.to"])
74+
assert result.output.startswith("Usage:")
75+
assert result.exit_code == 2
76+
77+
78+
def test_main_with_errors(
6479
runner: click.testing.CliRunner,
6580
mock_validation_validate_extension: Mock,
6681
mock_validation_validate_toml_with_error: Mock,
@@ -74,7 +89,7 @@ def test_main_with_argument_fail(
7489
assert result.output == (
7590
"Reading file file.toml.\n" "Error(s) found: |some error description|.\n"
7691
)
77-
assert result.exit_code == 0
92+
assert result.exit_code == 3
7893

7994

8095
@pytest.mark.e2e

0 commit comments

Comments
 (0)