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

Commit

Permalink
#8 refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
staticdev committed May 1, 2020
1 parent 2cc0453 commit 92048ba
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pytest-mock = "^3.0.0"
typeguard = "^2.7.1"

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

[tool.coverage.paths]
source = ["src", "*/site-packages"] # configure source tree layout
Expand Down
11 changes: 7 additions & 4 deletions src/toml_validator/console.py → src/toml_validator/__main__.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
"""Toml Validator CLI."""

"""Command-line interface."""
import click

from . import __version__, validation
from . import validation


@click.command()
@click.argument("filename", type=click.Path(exists=True))
@click.version_option(version=__version__)
@click.version_option()
def main(filename: str) -> None:
"""Makes validations and echos errors if found."""
validation.validate_extension(filename)
Expand All @@ -19,3 +18,7 @@ def main(filename: str) -> None:
click.secho("Error(s) found: {}.".format(errors), fg="red")
else:
click.secho("No problems found parsing file {}!".format(filename), fg="green")


if __name__ == "__main__":
main() # pragma: no cover
12 changes: 6 additions & 6 deletions tests/test_console.py → tests/test_main.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
"""Test cases for the console module."""
"""Test cases for the __main__ module."""
from unittest.mock import Mock

from click.testing import CliRunner
import pytest
from pytest_mock import MockFixture

from toml_validator import console
from toml_validator import __main__


@pytest.fixture
Expand Down Expand Up @@ -36,7 +36,7 @@ def mock_validation_validate_toml_with_error(mocker: MockFixture) -> Mock:


def test_main_without_argument(runner: CliRunner):
result = runner.invoke(console.main)
result = runner.invoke(__main__.main)
assert result.exit_code == 2


Expand All @@ -49,7 +49,7 @@ def test_main_with_argument_success(
with open("file.toml", "w") as f:
f.write("content doesnt matter")

result = runner.invoke(console.main, ["file.toml"])
result = runner.invoke(__main__.main, ["file.toml"])
assert result.output == (
"Reading file file.toml.\n" "No problems found parsing file file.toml!\n"
)
Expand All @@ -65,7 +65,7 @@ def test_main_with_argument_fail(
with open("file.toml", "w") as f:
f.write("content doesnt matter")

result = runner.invoke(console.main, ["file.toml"])
result = runner.invoke(__main__.main, ["file.toml"])
assert result.output == (
"Reading file file.toml.\n" "Error(s) found: |some error description|.\n"
)
Expand All @@ -74,5 +74,5 @@ def test_main_with_argument_fail(

@pytest.mark.e2e
def test_main_without_arguments_in_production_env(runner: CliRunner):
result = runner.invoke(console.main)
result = runner.invoke(__main__.main)
assert result.exit_code == 2

0 comments on commit 92048ba

Please sign in to comment.