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

Commit 92048ba

Browse files
author
staticdev
committed
#8 refactor
1 parent 2cc0453 commit 92048ba

3 files changed

Lines changed: 14 additions & 11 deletions

File tree

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ pytest-mock = "^3.0.0"
3131
typeguard = "^2.7.1"
3232

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

3636
[tool.coverage.paths]
3737
source = ["src", "*/site-packages"] # configure source tree layout
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
"""Toml Validator CLI."""
2-
1+
"""Command-line interface."""
32
import click
43

5-
from . import __version__, validation
4+
from . import validation
65

76

87
@click.command()
98
@click.argument("filename", type=click.Path(exists=True))
10-
@click.version_option(version=__version__)
9+
@click.version_option()
1110
def main(filename: str) -> None:
1211
"""Makes validations and echos errors if found."""
1312
validation.validate_extension(filename)
@@ -19,3 +18,7 @@ def main(filename: str) -> None:
1918
click.secho("Error(s) found: {}.".format(errors), fg="red")
2019
else:
2120
click.secho("No problems found parsing file {}!".format(filename), fg="green")
21+
22+
23+
if __name__ == "__main__":
24+
main() # pragma: no cover
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
"""Test cases for the console module."""
1+
"""Test cases for the __main__ module."""
22
from unittest.mock import Mock
33

44
from click.testing import CliRunner
55
import pytest
66
from pytest_mock import MockFixture
77

8-
from toml_validator import console
8+
from toml_validator import __main__
99

1010

1111
@pytest.fixture
@@ -36,7 +36,7 @@ def mock_validation_validate_toml_with_error(mocker: MockFixture) -> Mock:
3636

3737

3838
def test_main_without_argument(runner: CliRunner):
39-
result = runner.invoke(console.main)
39+
result = runner.invoke(__main__.main)
4040
assert result.exit_code == 2
4141

4242

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

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

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

7575
@pytest.mark.e2e
7676
def test_main_without_arguments_in_production_env(runner: CliRunner):
77-
result = runner.invoke(console.main)
77+
result = runner.invoke(__main__.main)
7878
assert result.exit_code == 2

0 commit comments

Comments
 (0)