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

Commit

Permalink
Merge pull request #256 from staticdev/update-error-status-code
Browse files Browse the repository at this point in the history
Update error status code
  • Loading branch information
Thiago C. D'Ávila authored Jan 13, 2021
2 parents fb16bee + 0faaa0d commit 1705923
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 48 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/constraints.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pip==20.3.3
nox==2020.12.31
poetry==1.1.4
pip==20.2.4
nox==2020.8.22
poetry==1.1.2
virtualenv==20.2.1
22 changes: 0 additions & 22 deletions .github/workflows/dependabot.yml

This file was deleted.

38 changes: 19 additions & 19 deletions poetry.lock

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

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ flake8 = "^3.8.4"
flake8-bandit = "^2.1.2"
flake8-bugbear = "^20.11.1"
safety = "^1.10.2"
mypy = "^0.790"
pytest-mock = "^3.5.1"
typeguard = "^2.10.0"
pre-commit = "^2.9.3"
Expand All @@ -39,6 +38,7 @@ flake8-rst-docstrings = "^0.0.14"
pep8-naming = "^0.11.1"
pre-commit-hooks = "^3.4.0"
reorder-python-imports = "^2.3.6"
mypy = "0.782"

[tool.poetry.scripts]
toml-validator = "toml_validator.__main__:main"
Expand Down
15 changes: 14 additions & 1 deletion src/toml_validator/__main__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
"""Command-line interface."""
import sys

import click

from . import validation
Expand All @@ -8,14 +10,25 @@
@click.argument("filename", type=click.Path(exists=True))
@click.version_option()
def main(filename: str) -> None:
"""Makes validations and echos errors if found."""
"""Makes validations and echos errors if found.
Args:
filename: name of validated file.
Return status:
* 0: no errors found
* 1: incorrect usage
* 2: invalid path
* 3: errors found
"""
validation.validate_extension(filename)

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

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

Expand Down
19 changes: 17 additions & 2 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,22 @@ def test_main_with_argument_success(
assert result.exit_code == 0


def test_main_with_argument_fail(
def test_main_with_invalid_path(
runner: click.testing.CliRunner,
mock_validation_validate_extension: Mock,
mock_validation_validate_toml_with_error: Mock,
) -> None:
"""It outputs error."""
with runner.isolated_filesystem():
with open("file.toml", "w") as f:
f.write("content doesnt matter")

result = runner.invoke(__main__.main, ["file.to"])
assert result.output.startswith("Usage:")
assert result.exit_code == 2


def test_main_with_errors(
runner: click.testing.CliRunner,
mock_validation_validate_extension: Mock,
mock_validation_validate_toml_with_error: Mock,
Expand All @@ -74,7 +89,7 @@ def test_main_with_argument_fail(
assert result.output == (
"Reading file file.toml.\n" "Error(s) found: |some error description|.\n"
)
assert result.exit_code == 0
assert result.exit_code == 3


@pytest.mark.e2e
Expand Down

0 comments on commit 1705923

Please sign in to comment.