Skip to content

Commit

Permalink
[#34] add a third option: neither black nor autopep8
Browse files Browse the repository at this point in the history
Signed-off-by: Bryant Finney <[email protected]>
  • Loading branch information
bryant-finney committed Nov 21, 2021
1 parent d783fef commit 45082ca
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
12 changes: 8 additions & 4 deletions pipenv_setup/setup_updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
from io import BytesIO
from subprocess import PIPE, Popen
from tokenize import OP
from typing import Any, List, Tuple
from types import ModuleType
from typing import Any, List, Optional, Tuple

from vistir.compat import Path

Expand Down Expand Up @@ -149,11 +150,14 @@ def _get_formatting_module(): # type: () -> Optional[ModuleType]
try:
import black
except:
import autopep8

try:
import autopep8
except ImportError:
return None
return autopep8
else:
return black

return black


def format_file(file): # type: (Path) -> None
Expand Down
10 changes: 10 additions & 0 deletions tests/setup_updater_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,13 @@ def test_autopep8(monkeypatch, dummy_import): # type: (MonkeyPatch, Callable) -
is_autopep8 = setup_updater._get_formatting_module()

assert is_autopep8 is autopep8


def test_none(monkeypatch, extra_dummy_import): # type: (MonkeyPatch, Callable) -> None
"""
verify `None` is returned if neither `black` nor `autopep8` is present
"""
patch_import(monkeypatch, extra_dummy_import)
is_none = setup_updater._get_formatting_module()

assert is_none is None

0 comments on commit 45082ca

Please sign in to comment.