From 293694c7479405372636c971245adb06cbc78489 Mon Sep 17 00:00:00 2001 From: staticdev Date: Wed, 13 Jan 2021 22:38:38 +0100 Subject: [PATCH 1/5] Update error status code --- .github/workflows/dependabot.yml | 22 ---------------------- noxfile.py | 2 +- src/toml_validator/__main__.py | 11 ++++++++++- tests/test_main.py | 20 ++++++++++++++++++-- 4 files changed, 29 insertions(+), 26 deletions(-) delete mode 100644 .github/workflows/dependabot.yml diff --git a/.github/workflows/dependabot.yml b/.github/workflows/dependabot.yml deleted file mode 100644 index b7789ee..0000000 --- a/.github/workflows/dependabot.yml +++ /dev/null @@ -1,22 +0,0 @@ -name: Dependabot - -on: - pull_request: - branches: - - master - -jobs: - automerge: - name: Merge Dependabot pull request - runs-on: ubuntu-latest - if: github.base_ref == 'master' && github.actor == 'dependabot[bot]' - steps: - - uses: actions/github-script@v3 - with: - github-token: ${{secrets.GITHUB_TOKEN}} - script: | - github.pulls.merge({ - owner: context.repo.owner, - repo: context.repo.repo, - pull_number: context.payload.pull_request.number - }) diff --git a/noxfile.py b/noxfile.py index 8225212..4ba7698 100644 --- a/noxfile.py +++ b/noxfile.py @@ -205,7 +205,7 @@ def safety(session: Session) -> None: """Scan dependencies for insecure packages.""" install(session, "safety") requirements = export_requirements(session, dev=True) - session.run("safety", "check", f"--file={requirements}", "--bare") + session.run("safety", "check", f"--file={requirements}") @nox.session(python=python_versions) diff --git a/src/toml_validator/__main__.py b/src/toml_validator/__main__.py index 63fd9c9..9e311fb 100644 --- a/src/toml_validator/__main__.py +++ b/src/toml_validator/__main__.py @@ -1,5 +1,6 @@ """Command-line interface.""" import click +import sys from . import validation @@ -8,7 +9,14 @@ @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. + + 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") @@ -16,6 +24,7 @@ def main(filename: str) -> None: 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") diff --git a/tests/test_main.py b/tests/test_main.py index d152eb9..8616309 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -60,7 +60,23 @@ 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, @@ -74,7 +90,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 From 422b304659d2712ca5e13c7a02995f95de30c8ea Mon Sep 17 00:00:00 2001 From: staticdev Date: Wed, 13 Jan 2021 22:48:43 +0100 Subject: [PATCH 2/5] Add venv --- .github/workflows/constraints.txt | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/constraints.txt b/.github/workflows/constraints.txt index 0433e96..522aa35 100644 --- a/.github/workflows/constraints.txt +++ b/.github/workflows/constraints.txt @@ -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 \ No newline at end of file From 0695a3c362e74c67fd61f0a1ba5651108665d6d8 Mon Sep 17 00:00:00 2001 From: staticdev Date: Wed, 13 Jan 2021 22:52:39 +0100 Subject: [PATCH 3/5] Fix pre-commit --- .github/workflows/constraints.txt | 2 +- src/toml_validator/__main__.py | 4 ++-- tests/test_main.py | 1 - 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/constraints.txt b/.github/workflows/constraints.txt index 522aa35..188e374 100644 --- a/.github/workflows/constraints.txt +++ b/.github/workflows/constraints.txt @@ -1,4 +1,4 @@ pip==20.2.4 nox==2020.8.22 poetry==1.1.2 -virtualenv==20.2.1 \ No newline at end of file +virtualenv==20.2.1 diff --git a/src/toml_validator/__main__.py b/src/toml_validator/__main__.py index 9e311fb..3243565 100644 --- a/src/toml_validator/__main__.py +++ b/src/toml_validator/__main__.py @@ -10,12 +10,12 @@ @click.version_option() def main(filename: str) -> None: """Makes validations and echos errors if found. - + Return status: * 0: no errors found * 1: incorrect usage * 2: invalid path - * 3: errors found + * 3: errors found """ validation.validate_extension(filename) diff --git a/tests/test_main.py b/tests/test_main.py index 8616309..a058f34 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -75,7 +75,6 @@ def test_main_with_invalid_path( assert result.exit_code == 2 - def test_main_with_errors( runner: click.testing.CliRunner, mock_validation_validate_extension: Mock, From eb945792f009352b53ddee053bf036e0a5442d88 Mon Sep 17 00:00:00 2001 From: staticdev Date: Wed, 13 Jan 2021 23:04:55 +0100 Subject: [PATCH 4/5] Various fixes --- noxfile.py | 2 +- poetry.lock | 38 +++++++++++++++++----------------- pyproject.toml | 2 +- src/toml_validator/__main__.py | 3 +++ 4 files changed, 24 insertions(+), 21 deletions(-) diff --git a/noxfile.py b/noxfile.py index 4ba7698..8225212 100644 --- a/noxfile.py +++ b/noxfile.py @@ -205,7 +205,7 @@ def safety(session: Session) -> None: """Scan dependencies for insecure packages.""" install(session, "safety") requirements = export_requirements(session, dev=True) - session.run("safety", "check", f"--file={requirements}") + session.run("safety", "check", f"--file={requirements}", "--bare") @nox.session(python=python_versions) diff --git a/poetry.lock b/poetry.lock index 8ef49a2..a813970 100644 --- a/poetry.lock +++ b/poetry.lock @@ -399,7 +399,7 @@ python-versions = "*" [[package]] name = "mypy" -version = "0.790" +version = "0.782" description = "Optional static typing for Python" category = "dev" optional = false @@ -513,7 +513,7 @@ toml = "*" [[package]] name = "py" -version = "1.8.2" +version = "1.10.0" description = "library with cross-python path, ini-parsing, io, code, log facilities" category = "dev" optional = false @@ -968,7 +968,7 @@ testing = ["jaraco.itertools", "func-timeout"] [metadata] lock-version = "1.1" python-versions = "^3.7" -content-hash = "6c47512a776572000ba8c1deba5ba1e85e8dba1c8c3b351f890b2c0ffe63de27" +content-hash = "5e9ddd331870620696d35b68caad55733020a1cb913a86ca2be1c4f20a80407d" [metadata.files] alabaster = [ @@ -1193,20 +1193,20 @@ mccabe = [ {file = "mccabe-0.6.1.tar.gz", hash = "sha256:dd8d182285a0fe56bace7f45b5e7d1a6ebcbf524e8f3bd87eb0f125271b8831f"}, ] mypy = [ - {file = "mypy-0.790-cp35-cp35m-macosx_10_6_x86_64.whl", hash = "sha256:bd03b3cf666bff8d710d633d1c56ab7facbdc204d567715cb3b9f85c6e94f669"}, - {file = "mypy-0.790-cp35-cp35m-manylinux1_x86_64.whl", hash = "sha256:2170492030f6faa537647d29945786d297e4862765f0b4ac5930ff62e300d802"}, - {file = "mypy-0.790-cp35-cp35m-win_amd64.whl", hash = "sha256:e86bdace26c5fe9cf8cb735e7cedfe7850ad92b327ac5d797c656717d2ca66de"}, - {file = "mypy-0.790-cp36-cp36m-macosx_10_9_x86_64.whl", hash = "sha256:e97e9c13d67fbe524be17e4d8025d51a7dca38f90de2e462243ab8ed8a9178d1"}, - {file = "mypy-0.790-cp36-cp36m-manylinux1_x86_64.whl", hash = "sha256:0d34d6b122597d48a36d6c59e35341f410d4abfa771d96d04ae2c468dd201abc"}, - {file = "mypy-0.790-cp36-cp36m-win_amd64.whl", hash = "sha256:72060bf64f290fb629bd4a67c707a66fd88ca26e413a91384b18db3876e57ed7"}, - {file = "mypy-0.790-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:eea260feb1830a627fb526d22fbb426b750d9f5a47b624e8d5e7e004359b219c"}, - {file = "mypy-0.790-cp37-cp37m-manylinux1_x86_64.whl", hash = "sha256:c614194e01c85bb2e551c421397e49afb2872c88b5830e3554f0519f9fb1c178"}, - {file = "mypy-0.790-cp37-cp37m-win_amd64.whl", hash = "sha256:0a0d102247c16ce93c97066443d11e2d36e6cc2a32d8ccc1f705268970479324"}, - {file = "mypy-0.790-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:cf4e7bf7f1214826cf7333627cb2547c0db7e3078723227820d0a2490f117a01"}, - {file = "mypy-0.790-cp38-cp38-manylinux1_x86_64.whl", hash = "sha256:af4e9ff1834e565f1baa74ccf7ae2564ae38c8df2a85b057af1dbbc958eb6666"}, - {file = "mypy-0.790-cp38-cp38-win_amd64.whl", hash = "sha256:da56dedcd7cd502ccd3c5dddc656cb36113dd793ad466e894574125945653cea"}, - {file = "mypy-0.790-py3-none-any.whl", hash = "sha256:2842d4fbd1b12ab422346376aad03ff5d0805b706102e475e962370f874a5122"}, - {file = "mypy-0.790.tar.gz", hash = "sha256:2b21ba45ad9ef2e2eb88ce4aeadd0112d0f5026418324176fd494a6824b74975"}, + {file = "mypy-0.782-cp35-cp35m-macosx_10_6_x86_64.whl", hash = "sha256:2c6cde8aa3426c1682d35190b59b71f661237d74b053822ea3d748e2c9578a7c"}, + {file = "mypy-0.782-cp35-cp35m-manylinux1_x86_64.whl", hash = "sha256:9c7a9a7ceb2871ba4bac1cf7217a7dd9ccd44c27c2950edbc6dc08530f32ad4e"}, + {file = "mypy-0.782-cp35-cp35m-win_amd64.whl", hash = "sha256:c05b9e4fb1d8a41d41dec8786c94f3b95d3c5f528298d769eb8e73d293abc48d"}, + {file = "mypy-0.782-cp36-cp36m-macosx_10_6_x86_64.whl", hash = "sha256:6731603dfe0ce4352c555c6284c6db0dc935b685e9ce2e4cf220abe1e14386fd"}, + {file = "mypy-0.782-cp36-cp36m-manylinux1_x86_64.whl", hash = "sha256:f05644db6779387ccdb468cc47a44b4356fc2ffa9287135d05b70a98dc83b89a"}, + {file = "mypy-0.782-cp36-cp36m-win_amd64.whl", hash = "sha256:b7fbfabdbcc78c4f6fc4712544b9b0d6bf171069c6e0e3cb82440dd10ced3406"}, + {file = "mypy-0.782-cp37-cp37m-macosx_10_6_x86_64.whl", hash = "sha256:3fdda71c067d3ddfb21da4b80e2686b71e9e5c72cca65fa216d207a358827f86"}, + {file = "mypy-0.782-cp37-cp37m-manylinux1_x86_64.whl", hash = "sha256:d7df6eddb6054d21ca4d3c6249cae5578cb4602951fd2b6ee2f5510ffb098707"}, + {file = "mypy-0.782-cp37-cp37m-win_amd64.whl", hash = "sha256:a4a2cbcfc4cbf45cd126f531dedda8485671545b43107ded25ce952aac6fb308"}, + {file = "mypy-0.782-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:6bb93479caa6619d21d6e7160c552c1193f6952f0668cdda2f851156e85186fc"}, + {file = "mypy-0.782-cp38-cp38-manylinux1_x86_64.whl", hash = "sha256:81c7908b94239c4010e16642c9102bfc958ab14e36048fa77d0be3289dda76ea"}, + {file = "mypy-0.782-cp38-cp38-win_amd64.whl", hash = "sha256:5dd13ff1f2a97f94540fd37a49e5d255950ebcdf446fb597463a40d0df3fac8b"}, + {file = "mypy-0.782-py3-none-any.whl", hash = "sha256:e0b61738ab504e656d1fe4ff0c0601387a5489ca122d55390ade31f9ca0e252d"}, + {file = "mypy-0.782.tar.gz", hash = "sha256:eff7d4a85e9eea55afa34888dfeaccde99e7520b51f867ac28a48492c0b1130c"}, ] mypy-extensions = [ {file = "mypy_extensions-0.4.3-py2.py3-none-any.whl", hash = "sha256:090fedd75945a69ae91ce1303b5824f428daf5a028d2f6ab8a299250a846f15d"}, @@ -1245,8 +1245,8 @@ pre-commit-hooks = [ {file = "pre_commit_hooks-3.4.0.tar.gz", hash = "sha256:57e377b931aceead550e4a7bdbe8065e79e371e80f593b5b6d1129e63a77154f"}, ] py = [ - {file = "py-1.8.2-py2.py3-none-any.whl", hash = "sha256:a673fa23d7000440cc885c17dbd34fafcb7d7a6e230b29f6766400de36a33c44"}, - {file = "py-1.8.2.tar.gz", hash = "sha256:f3b3a4c36512a4c4f024041ab51866f11761cc169670204b235f6b20523d4e6b"}, + {file = "py-1.10.0-py2.py3-none-any.whl", hash = "sha256:3b80836aa6d1feeaa108e046da6423ab8f6ceda6468545ae8d02d9d58d18818a"}, + {file = "py-1.10.0.tar.gz", hash = "sha256:21b81bda15b66ef5e1a777a21c4dcd9c20ad3efd0b3f817e7a809035269e1bd3"}, ] pycodestyle = [ {file = "pycodestyle-2.6.0-py2.py3-none-any.whl", hash = "sha256:2295e7b2f6b5bd100585ebcb1f616591b652db8a741695b3d8f5d28bdc934367"}, diff --git a/pyproject.toml b/pyproject.toml index 244ae7b..f8604e6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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" @@ -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" diff --git a/src/toml_validator/__main__.py b/src/toml_validator/__main__.py index 3243565..4f75c7b 100644 --- a/src/toml_validator/__main__.py +++ b/src/toml_validator/__main__.py @@ -11,6 +11,9 @@ def main(filename: str) -> None: """Makes validations and echos errors if found. + Args: + filename: name of validated file. + Return status: * 0: no errors found * 1: incorrect usage From 0faaa0d2219939f0ababb5ff61e52306c72ccbcd Mon Sep 17 00:00:00 2001 From: staticdev Date: Wed, 13 Jan 2021 23:07:41 +0100 Subject: [PATCH 5/5] Import order --- src/toml_validator/__main__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/toml_validator/__main__.py b/src/toml_validator/__main__.py index 4f75c7b..30cf868 100644 --- a/src/toml_validator/__main__.py +++ b/src/toml_validator/__main__.py @@ -1,7 +1,8 @@ """Command-line interface.""" -import click import sys +import click + from . import validation