Skip to content

Commit

Permalink
Update test_black.shhh_click test for click 8+ (#2993)
Browse files Browse the repository at this point in the history
The 8.0.x series renamed its "die on LANG=C" function and the 8.1.x
series straight up deleted it.

Unfortunately this makes this test type check cleanly hard, so we'll
just lint with click 8.1+ (the pre-commit hook configuration was changed
mostly to just evict any now unsupported mypy environments)
  • Loading branch information
ichard26 committed Apr 5, 2022
1 parent 24c708e commit fa5fd26
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ repos:
- types-PyYAML
- tomli >= 0.2.6, < 2.0.0
- types-typed-ast >= 1.4.1
- click >= 8.0.0
- click >= 8.1.0
- platformdirs >= 2.1.0

- repo: https://github.com/pre-commit/mirrors-prettier
Expand Down
10 changes: 6 additions & 4 deletions tests/test_black.py
Original file line number Diff line number Diff line change
Expand Up @@ -1256,23 +1256,25 @@ def test_assert_equivalent_different_asts(self) -> None:

def test_shhh_click(self) -> None:
try:
from click import _unicodefun
from click import _unicodefun # type: ignore
except ImportError:
self.skipTest("Incompatible Click version")
if not hasattr(_unicodefun, "_verify_python3_env"):

if not hasattr(_unicodefun, "_verify_python_env"):
self.skipTest("Incompatible Click version")

# First, let's see if Click is crashing with a preferred ASCII charset.
with patch("locale.getpreferredencoding") as gpe:
gpe.return_value = "ASCII"
with self.assertRaises(RuntimeError):
_unicodefun._verify_python3_env() # type: ignore
_unicodefun._verify_python_env()
# Now, let's silence Click...
black.patch_click()
# ...and confirm it's silent.
with patch("locale.getpreferredencoding") as gpe:
gpe.return_value = "ASCII"
try:
_unicodefun._verify_python3_env() # type: ignore
_unicodefun._verify_python_env()
except RuntimeError as re:
self.fail(f"`patch_click()` failed, exception still raised: {re}")

Expand Down

0 comments on commit fa5fd26

Please sign in to comment.