diff --git a/README.md b/README.md index 7d23b7b..234c3f6 100644 --- a/README.md +++ b/README.md @@ -272,7 +272,7 @@ Usage: ./cli.py format-file [OPTIONS] FILE_PATH │ in .editorconfig │ │ [default: 119] │ │ --darker-prefixes TEXT Apply prefixes via autopep8 before calling darker. │ -│ [default: E302,E303,E305,W391] │ +│ [default: E301,E302,E303,E305,W391] │ │ --help Show this message and exit. │ ╰──────────────────────────────────────────────────────────────────────────────────────────────────╯ ``` diff --git a/manageprojects/constants.py b/manageprojects/constants.py index 17d2923..a541791 100644 --- a/manageprojects/constants.py +++ b/manageprojects/constants.py @@ -16,6 +16,7 @@ FORMAT_PY_FILE_DARKER_PRE_FIXES = ','.join( sorted( [ + 'E301', # expected 1 blank line 'E302', # expected 2 blank lines 'E303', # too many blank lines 'W391', # blank line at end of file diff --git a/manageprojects/test_utils/click_cli_utils.py b/manageprojects/test_utils/click_cli_utils.py index 437fcf2..14c17ce 100644 --- a/manageprojects/test_utils/click_cli_utils.py +++ b/manageprojects/test_utils/click_cli_utils.py @@ -4,7 +4,7 @@ import rich_click from bx_py_utils.path import assert_is_file from bx_py_utils.test_utils.context_managers import MassContextManager -from click.testing import CliRunner +from click.testing import CliRunner, Result from manageprojects.utilities.subprocess_utils import verbose_check_output @@ -30,6 +30,11 @@ class ForceRichTerminalWidth(MassContextManager): ) +class ClickInvokeCliException(Exception): + def __init__(self, result: Result): + self.result = result + + def invoke_click(cli, *args, expected_stderr='', expected_exit_code=0, strip=True, **kwargs): assert isinstance(cli, click.Command) @@ -37,7 +42,10 @@ def invoke_click(cli, *args, expected_stderr='', expected_exit_code=0, strip=Tru with ForceRichTerminalWidth(): runner = CliRunner(mix_stderr=False) - result = runner.invoke(cli=cli, args=args, **kwargs, color=False) + result: Result = runner.invoke(cli=cli, args=args, **kwargs, color=False) + + if result.exception: + raise ClickInvokeCliException(result) from result.exception stdout = result.stdout stderr = result.stderr diff --git a/manageprojects/tests/test_click_cli_utils.py b/manageprojects/tests/test_click_cli_utils.py new file mode 100644 index 0000000..8727ae5 --- /dev/null +++ b/manageprojects/tests/test_click_cli_utils.py @@ -0,0 +1,20 @@ +from unittest.mock import patch + +from click.testing import Result + +from manageprojects.cli import cli_app +from manageprojects.cli.cli_app import cli +from manageprojects.test_utils.click_cli_utils import ClickInvokeCliException, invoke_click +from manageprojects.tests.base import BaseTestCase + + +class CliTestCase(BaseTestCase): + def test_invoke_click(self): + with patch.object(cli_app, 'verbose_check_call', side_effect=RuntimeError('Bam!')): + with self.assertRaises(ClickInvokeCliException) as cm: + invoke_click(cli, 'install') + + self.assertIsInstance(cm.exception, ClickInvokeCliException) + self.assertIsInstance(cm.exception.result, Result) + self.assertIsInstance(cm.exception.result.exception, RuntimeError) + self.assertEqual(cm.exception.result.exception.args, ('Bam!',)) diff --git a/pyproject.toml b/pyproject.toml index 5cf0ede..9404f24 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "manageprojects" -version = "0.9.1" +version = "0.9.2" description = "Manage Python / Django projects" readme = "README.md" authors = [ diff --git a/requirements.dev.txt b/requirements.dev.txt index c21e4f1..002918d 100644 --- a/requirements.dev.txt +++ b/requirements.dev.txt @@ -411,7 +411,8 @@ keyring==23.13.1 \ --hash=sha256:ba2e15a9b35e21908d0aaf4e0a47acc52d6ae33444df0da2b49d41a46ef6d678 # via twine markdown-it-py==2.2.0 \ - --hash=sha256:5a35f8d1870171d9acc47b99612dc146129b631baf04970128b568f190d0cc30 + --hash=sha256:5a35f8d1870171d9acc47b99612dc146129b631baf04970128b568f190d0cc30 \ + --hash=sha256:7c9a5e412688bc771c67432cbfebcdd686c93ce6484913dccf06cb5a0bea35a1 # via rich markupsafe==2.1.2 \ --hash=sha256:0576fe974b40a400449768941d5d0858cc624e3249dfd1e0c33674e5c7ca7aed \ @@ -594,9 +595,9 @@ python-dateutil==2.8.2 \ --hash=sha256:0123cacc1627ae19ddf3c27a5de5bd67ee4586fbdd6440d9748f8abb483d3e86 \ --hash=sha256:961d03dc3453ebbc59dbdea9e4e11c5651520a876d0f4db161e8674aae935da9 # via arrow -python-slugify==8.0.0 \ - --hash=sha256:51f217508df20a6c166c7821683384b998560adcf8f19a6c2ca8b460528ccd9c \ - --hash=sha256:f1da83f3c7ab839b3f84543470cd95bdb5a81f1a0b80fed502f78b7dca256062 +python-slugify==8.0.1 \ + --hash=sha256:70ca6ea68fe63ecc8fa4fcf00ae651fc8a5d02d93dcd12ae6d4fc7ca46c4d395 \ + --hash=sha256:ce0d46ddb668b3be82f4ed5e503dbc33dd815d83e2eb6824211310d3fb172a27 # via cookiecutter pyupgrade==3.3.1 \ --hash=sha256:3b93641963df022d605c78aeae4b5956a5296ea24701eafaef9c487527b77e60 \ @@ -793,9 +794,9 @@ wheel==0.38.4 \ --hash=sha256:965f5259b566725405b05e7cf774052044b1ed30119b5d586b2703aafe8719ac \ --hash=sha256:b60533f3f5d530e971d6737ca6d58681ee434818fab630c83a734bb10c083ce8 # via pip-tools -zipp==3.14.0 \ - --hash=sha256:188834565033387710d046e3fe96acfc9b5e86cbca7f39ff69cf21a4128198b7 \ - --hash=sha256:9e5421e176ef5ab4c0ad896624e87a7b2f07aca746c9b2aa305952800cb8eecb +zipp==3.15.0 \ + --hash=sha256:112929ad649da941c23de50f356a2b5570c954b65150642bccdd66bf194d224b \ + --hash=sha256:48904fc76a60e542af151aded95726c1a5c34ed43ab4134b597665c86d7ad556 # via importlib-metadata # The following packages are considered to be unsafe in a requirements file: diff --git a/requirements.txt b/requirements.txt index 07ff4e0..cba8511 100644 --- a/requirements.txt +++ b/requirements.txt @@ -192,7 +192,8 @@ jinja2-time==0.2.0 \ --hash=sha256:d3eab6605e3ec8b7a0863df09cc1d23714908fa61aa6986a845c20ba488b4efa # via cookiecutter markdown-it-py==2.2.0 \ - --hash=sha256:5a35f8d1870171d9acc47b99612dc146129b631baf04970128b568f190d0cc30 + --hash=sha256:5a35f8d1870171d9acc47b99612dc146129b631baf04970128b568f190d0cc30 \ + --hash=sha256:7c9a5e412688bc771c67432cbfebcdd686c93ce6484913dccf06cb5a0bea35a1 # via rich markupsafe==2.1.2 \ --hash=sha256:0576fe974b40a400449768941d5d0858cc624e3249dfd1e0c33674e5c7ca7aed \ @@ -327,9 +328,9 @@ python-dateutil==2.8.2 \ --hash=sha256:0123cacc1627ae19ddf3c27a5de5bd67ee4586fbdd6440d9748f8abb483d3e86 \ --hash=sha256:961d03dc3453ebbc59dbdea9e4e11c5651520a876d0f4db161e8674aae935da9 # via arrow -python-slugify==8.0.0 \ - --hash=sha256:51f217508df20a6c166c7821683384b998560adcf8f19a6c2ca8b460528ccd9c \ - --hash=sha256:f1da83f3c7ab839b3f84543470cd95bdb5a81f1a0b80fed502f78b7dca256062 +python-slugify==8.0.1 \ + --hash=sha256:70ca6ea68fe63ecc8fa4fcf00ae651fc8a5d02d93dcd12ae6d4fc7ca46c4d395 \ + --hash=sha256:ce0d46ddb668b3be82f4ed5e503dbc33dd815d83e2eb6824211310d3fb172a27 # via cookiecutter pyupgrade==3.3.1 \ --hash=sha256:3b93641963df022d605c78aeae4b5956a5296ea24701eafaef9c487527b77e60 \