Skip to content

Commit

Permalink
flake8 tidy
Browse files Browse the repository at this point in the history
  • Loading branch information
SmileyChris committed Mar 11, 2022
1 parent 192b693 commit 57a2819
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 13 deletions.
6 changes: 3 additions & 3 deletions qrcode/console_scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
When stdout is a tty the QR Code is printed to the terminal and when stdout is
a pipe to a file an image is written. The default image format is PNG.
"""
from ctypes import cast
import optparse
import os
import sys
Expand Down Expand Up @@ -124,10 +123,11 @@ def raise_error(msg: str) -> NoReturn:
)
if opts.factory_drawer:
if not aliases:
raise_error(f"The selected factory has no drawer aliases.")
raise_error("The selected factory has no drawer aliases.")
if opts.factory_drawer not in aliases:
raise_error(
f"{opts.factory_drawer} factory drawer not found. Expected {commas(aliases)}"
f"{opts.factory_drawer} factory drawer not found."
f" Expected {commas(aliases)}"
)
drawer_cls, drawer_kwargs = aliases[opts.factory_drawer]
kwargs["module_drawer"] = drawer_cls(**drawer_kwargs)
Expand Down
8 changes: 6 additions & 2 deletions qrcode/image/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,18 @@ def __init__(
eye_drawer: Union[QRModuleDrawer, str, None] = None,
**kwargs,
):
self.module_drawer = self.get_drawer(module_drawer) or self.get_default_module_drawer()
self.module_drawer = (
self.get_drawer(module_drawer) or self.get_default_module_drawer()
)
# The eye drawer can be overridden by another module drawer as well,
# but you have to be more careful with these in order to make the QR
# code still parseable
self.eye_drawer = self.get_drawer(eye_drawer) or self.get_default_eye_drawer()
super().__init__(*args, **kwargs)

def get_drawer(self, drawer: Union[QRModuleDrawer, str, None]) -> Optional[QRModuleDrawer]:
def get_drawer(
self, drawer: Union[QRModuleDrawer, str, None]
) -> Optional[QRModuleDrawer]:
if not isinstance(drawer, str):
return drawer
drawer_cls, kwargs = self.drawer_aliases[drawer]
Expand Down
4 changes: 3 additions & 1 deletion qrcode/image/styles/moduledrawers/pil.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,9 @@ def setup_corners(self):
self.SE_ROUND = self.NW_ROUND.transpose(Image.ROTATE_180)
self.NE_ROUND = self.NW_ROUND.transpose(Image.FLIP_LEFT_RIGHT)

def drawrect(self, box: List[List[int]], is_active: "Union[bool, ActiveWithNeighbors]"):
def drawrect(
self, box: List[List[int]], is_active: "Union[bool, ActiveWithNeighbors]"
):
if not is_active:
return
# find rounded edges
Expand Down
4 changes: 1 addition & 3 deletions qrcode/tests/test_qrcode.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import io
import os
import sys
import unittest
import warnings
from tempfile import mkdtemp
Expand All @@ -23,7 +22,7 @@
from qrcode.image.pil import Image as pil_Image
from qrcode.image.styledpil import StyledPilImage
from qrcode.image.styles import colormasks
except:
except ImportError:
pil_Image = None

UNICODE_TEXT = "\u03b1\u03b2\u03b3"
Expand Down Expand Up @@ -422,7 +421,6 @@ def test_qrdata_repr(self):

def test_print_ascii_stdout(self):
qr = qrcode.QRCode()
stdout_encoding = sys.stdout.encoding
with mock.patch("sys.stdout") as fake_stdout:
fake_stdout.isatty.return_value = None
self.assertRaises(OSError, qr.print_ascii, tty=True)
Expand Down
10 changes: 6 additions & 4 deletions qrcode/tests/test_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from tempfile import mkdtemp
from unittest import mock

from qrcode.console_scripts import main, commas
from qrcode.console_scripts import commas, main

try:
from PIL import Image
Expand Down Expand Up @@ -90,7 +90,9 @@ def test_output(self):
def test_factory_drawer_none(self, mock_stderr):
with self.assertRaises(SystemExit):
main("testtext --factory pil --factory-drawer nope".split())
self.assertIn("The selected factory has no drawer aliases", mock_stderr.getvalue())
self.assertIn(
"The selected factory has no drawer aliases", mock_stderr.getvalue()
)

@mock.patch("sys.stderr", new_callable=io.StringIO)
def test_factory_drawer_bad(self, mock_stderr):
Expand All @@ -104,7 +106,7 @@ def test_factory_drawer(self, mock_stderr):

def test_commas(self):
self.assertEqual(commas([]), "")
self.assertEqual(commas(['A']), "A")
self.assertEqual(commas('AB'), "A or B")
self.assertEqual(commas(["A"]), "A")
self.assertEqual(commas("AB"), "A or B")
self.assertEqual(commas("ABC"), "A, B or C")
self.assertEqual(commas("ABC", joiner="and"), "A, B and C")

0 comments on commit 57a2819

Please sign in to comment.