mirror of
				https://github.com/python-escpos/python-escpos
				synced 2025-10-23 09:30:00 +00:00 
			
		
		
		
	pyflakes3
This commit is contained in:
		| @@ -1,7 +1,7 @@ | |||||||
| # -*- coding: utf-8 -*- | # -*- coding: utf-8 -*- | ||||||
| """python-escpos enables you to manipulate escpos-printers.""" | """python-escpos enables you to manipulate escpos-printers.""" | ||||||
|  |  | ||||||
| __all__ = ["constants", "escpos", "exceptions", "printer"] | __all__ = ["constants", "escpos", "exceptions", "printer", "__version__"] | ||||||
|  |  | ||||||
| try: | try: | ||||||
|     from .version import version as __version__  # noqa |     from .version import version as __version__  # noqa | ||||||
|   | |||||||
| @@ -4,7 +4,6 @@ This module contains the implementations of abstract base class :py:class:`Confi | |||||||
| """ | """ | ||||||
| import os | import os | ||||||
| import pathlib | import pathlib | ||||||
| from typing import Optional |  | ||||||
|  |  | ||||||
| import appdirs | import appdirs | ||||||
| import yaml | import yaml | ||||||
|   | |||||||
| @@ -11,7 +11,7 @@ except ImportError: | |||||||
|     jaconv = None |     jaconv = None | ||||||
|  |  | ||||||
|  |  | ||||||
| def encode_katakana(text): | def encode_katakana(text: str) -> bytes: | ||||||
|     """I don't think this quite works yet.""" |     """I don't think this quite works yet.""" | ||||||
|     encoded = [] |     encoded = [] | ||||||
|     for char in text: |     for char in text: | ||||||
|   | |||||||
| @@ -7,7 +7,6 @@ import os | |||||||
| import shutil | import shutil | ||||||
| import tempfile | import tempfile | ||||||
|  |  | ||||||
| import pytest |  | ||||||
| from scripttest import TestFileEnvironment as TFE | from scripttest import TestFileEnvironment as TFE | ||||||
|  |  | ||||||
| import escpos | import escpos | ||||||
| @@ -31,18 +30,18 @@ class TestCLI: | |||||||
|     """Contains setups, teardowns, and tests for CLI""" |     """Contains setups, teardowns, and tests for CLI""" | ||||||
|  |  | ||||||
|     @classmethod |     @classmethod | ||||||
|     def setup_class(cls): |     def setup_class(cls) -> None: | ||||||
|         """Create a config file to read from""" |         """Create a config file to read from""" | ||||||
|         with open(CONFIGFILE, "w") as config: |         with open(CONFIGFILE, "w") as config: | ||||||
|             config.write(CONFIG_YAML) |             config.write(CONFIG_YAML) | ||||||
|  |  | ||||||
|     @classmethod |     @classmethod | ||||||
|     def teardown_class(cls): |     def teardown_class(cls) -> None: | ||||||
|         """Remove config file""" |         """Remove config file""" | ||||||
|         os.remove(CONFIGFILE) |         os.remove(CONFIGFILE) | ||||||
|         shutil.rmtree(TEST_DIR) |         shutil.rmtree(TEST_DIR) | ||||||
|  |  | ||||||
|     def setup_method(self): |     def setup_method(self) -> None: | ||||||
|         """Create a file to print to and set up env""" |         """Create a file to print to and set up env""" | ||||||
|         self.env = None |         self.env = None | ||||||
|         self.default_args = None |         self.default_args = None | ||||||
| @@ -64,24 +63,24 @@ class TestCLI: | |||||||
|         finally: |         finally: | ||||||
|             fhandle.close() |             fhandle.close() | ||||||
|  |  | ||||||
|     def teardown_method(self): |     def teardown_method(self) -> None: | ||||||
|         """Destroy printer file and env""" |         """Destroy printer file and env""" | ||||||
|         os.remove(DEVFILE) |         os.remove(DEVFILE) | ||||||
|         self.env.clear() |         self.env.clear() | ||||||
|  |  | ||||||
|     def test_cli_help(self): |     def test_cli_help(self) -> None: | ||||||
|         """Test getting help from cli""" |         """Test getting help from cli""" | ||||||
|         result = self.env.run("python-escpos", "-h") |         result = self.env.run("python-escpos", "-h") | ||||||
|         assert not result.stderr |         assert not result.stderr | ||||||
|         assert "usage" in result.stdout |         assert "usage" in result.stdout | ||||||
|  |  | ||||||
|     def test_cli_version(self): |     def test_cli_version(self) -> None: | ||||||
|         """Test the version string""" |         """Test the version string""" | ||||||
|         result = self.env.run("python-escpos", "version") |         result = self.env.run("python-escpos", "version") | ||||||
|         assert not result.stderr |         assert not result.stderr | ||||||
|         assert escpos.__version__ == result.stdout.strip() |         assert escpos.__version__ == result.stdout.strip() | ||||||
|  |  | ||||||
|     def test_cli_version_extended(self): |     def test_cli_version_extended(self) -> None: | ||||||
|         """Test the extended version information""" |         """Test the extended version information""" | ||||||
|         result = self.env.run("python-escpos", "version_extended") |         result = self.env.run("python-escpos", "version_extended") | ||||||
|         assert not result.stderr |         assert not result.stderr | ||||||
| @@ -89,7 +88,7 @@ class TestCLI: | |||||||
|         # test that additional information on e.g. Serial is printed |         # test that additional information on e.g. Serial is printed | ||||||
|         assert "Serial" in result.stdout |         assert "Serial" in result.stdout | ||||||
|  |  | ||||||
|     def test_cli_text(self): |     def test_cli_text(self) -> None: | ||||||
|         """Make sure text returns what we sent it""" |         """Make sure text returns what we sent it""" | ||||||
|         test_text = "this is some text" |         test_text = "this is some text" | ||||||
|         result = self.env.run( |         result = self.env.run( | ||||||
| @@ -108,7 +107,7 @@ class TestCLI: | |||||||
|             result.files_updated[DEVFILE_NAME].bytes == "\x1bt\x00" + test_text + "\n" |             result.files_updated[DEVFILE_NAME].bytes == "\x1bt\x00" + test_text + "\n" | ||||||
|         ) |         ) | ||||||
|  |  | ||||||
|     def test_cli_text_invalid_args(self): |     def test_cli_text_invalid_args(self) -> None: | ||||||
|         """Test a failure to send valid arguments""" |         """Test a failure to send valid arguments""" | ||||||
|         result = self.env.run( |         result = self.env.run( | ||||||
|             *(self.default_args + ("text", "--invalid-param", "some data")), |             *(self.default_args + ("text", "--invalid-param", "some data")), | ||||||
|   | |||||||
| @@ -10,8 +10,7 @@ | |||||||
|  |  | ||||||
| import hypothesis.strategies as st | import hypothesis.strategies as st | ||||||
| import mock | import mock | ||||||
| import pytest | from hypothesis import given | ||||||
| from hypothesis import assume, given |  | ||||||
|  |  | ||||||
| from escpos.printer import Dummy | from escpos.printer import Dummy | ||||||
|  |  | ||||||
| @@ -21,7 +20,7 @@ def get_printer(): | |||||||
|  |  | ||||||
|  |  | ||||||
| @given(text=st.text()) | @given(text=st.text()) | ||||||
| def test_text(text): | def test_text(text: str) -> None: | ||||||
|     """Test that text() calls the MagicEncode object.""" |     """Test that text() calls the MagicEncode object.""" | ||||||
|     instance = get_printer() |     instance = get_printer() | ||||||
|     instance.magic.write = mock.Mock() |     instance.magic.write = mock.Mock() | ||||||
| @@ -29,7 +28,7 @@ def test_text(text): | |||||||
|     instance.magic.write.assert_called_with(text) |     instance.magic.write.assert_called_with(text) | ||||||
|  |  | ||||||
|  |  | ||||||
| def test_block_text(): | def test_block_text() -> None: | ||||||
|     printer = get_printer() |     printer = get_printer() | ||||||
|     printer.block_text( |     printer.block_text( | ||||||
|         "All the presidents men were eating falafel for breakfast.", font="a" |         "All the presidents men were eating falafel for breakfast.", font="a" | ||||||
| @@ -39,25 +38,25 @@ def test_block_text(): | |||||||
|     ) |     ) | ||||||
|  |  | ||||||
|  |  | ||||||
| def test_textln(): | def test_textln() -> None: | ||||||
|     printer = get_printer() |     printer = get_printer() | ||||||
|     printer.textln("hello, world") |     printer.textln("hello, world") | ||||||
|     assert printer.output == b"hello, world\n" |     assert printer.output == b"hello, world\n" | ||||||
|  |  | ||||||
|  |  | ||||||
| def test_textln_empty(): | def test_textln_empty() -> None: | ||||||
|     printer = get_printer() |     printer = get_printer() | ||||||
|     printer.textln() |     printer.textln() | ||||||
|     assert printer.output == b"\n" |     assert printer.output == b"\n" | ||||||
|  |  | ||||||
|  |  | ||||||
| def test_ln(): | def test_ln() -> None: | ||||||
|     printer = get_printer() |     printer = get_printer() | ||||||
|     printer.ln() |     printer.ln() | ||||||
|     assert printer.output == b"\n" |     assert printer.output == b"\n" | ||||||
|  |  | ||||||
|  |  | ||||||
| def test_multiple_ln(): | def test_multiple_ln() -> None: | ||||||
|     printer = get_printer() |     printer = get_printer() | ||||||
|     printer.ln(3) |     printer.ln(3) | ||||||
|     assert printer.output == b"\n\n\n" |     assert printer.output == b"\n\n\n" | ||||||
|   | |||||||
| @@ -13,7 +13,7 @@ import hypothesis.strategies as st | |||||||
| import pytest | import pytest | ||||||
| from hypothesis import example, given | from hypothesis import example, given | ||||||
|  |  | ||||||
| from escpos.exceptions import CharCodeError, Error | from escpos.exceptions import Error | ||||||
| from escpos.katakana import encode_katakana | from escpos.katakana import encode_katakana | ||||||
| from escpos.magicencode import Encoder, MagicEncode | from escpos.magicencode import Encoder, MagicEncode | ||||||
|  |  | ||||||
| @@ -23,23 +23,23 @@ class TestEncoder: | |||||||
|     Tests the single encoders. |     Tests the single encoders. | ||||||
|     """ |     """ | ||||||
|  |  | ||||||
|     def test_can_encode(self): |     def test_can_encode(self) -> None: | ||||||
|         assert not Encoder({"CP437": 1}).can_encode("CP437", "€") |         assert not Encoder({"CP437": 1}).can_encode("CP437", "€") | ||||||
|         assert Encoder({"CP437": 1}).can_encode("CP437", "á") |         assert Encoder({"CP437": 1}).can_encode("CP437", "á") | ||||||
|         assert not Encoder({"foobar": 1}).can_encode("foobar", "a") |         assert not Encoder({"foobar": 1}).can_encode("foobar", "a") | ||||||
|  |  | ||||||
|     def test_find_suitable_encoding(self): |     def test_find_suitable_encoding(self) -> None: | ||||||
|         assert not Encoder({"CP437": 1}).find_suitable_encoding("€") |         assert not Encoder({"CP437": 1}).find_suitable_encoding("€") | ||||||
|         assert Encoder({"CP858": 1}).find_suitable_encoding("€") == "CP858" |         assert Encoder({"CP858": 1}).find_suitable_encoding("€") == "CP858" | ||||||
|  |  | ||||||
|     def test_find_suitable_encoding_unnecessary_codepage_swap(self): |     def test_find_suitable_encoding_unnecessary_codepage_swap(self) -> None: | ||||||
|         enc = Encoder({"CP857": 1, "CP437": 2, "CP1252": 3, "CP852": 4, "CP858": 5}) |         enc = Encoder({"CP857": 1, "CP437": 2, "CP1252": 3, "CP852": 4, "CP858": 5}) | ||||||
|         # desired behavior would be that the encoder always stays in the lower |         # desired behavior would be that the encoder always stays in the lower | ||||||
|         # available codepages if possible |         # available codepages if possible | ||||||
|         for character in ("Á", "É", "Í", "Ó", "Ú"): |         for character in ("Á", "É", "Í", "Ó", "Ú"): | ||||||
|             assert enc.find_suitable_encoding(character) == "CP857" |             assert enc.find_suitable_encoding(character) == "CP857" | ||||||
|  |  | ||||||
|     def test_get_encoding(self): |     def test_get_encoding(self) -> None: | ||||||
|         with pytest.raises(ValueError): |         with pytest.raises(ValueError): | ||||||
|             Encoder({}).get_encoding_name("latin1") |             Encoder({}).get_encoding_name("latin1") | ||||||
|  |  | ||||||
| @@ -122,9 +122,9 @@ class TestKatakana: | |||||||
|     @example("カタカナ") |     @example("カタカナ") | ||||||
|     @example("あいうえお") |     @example("あいうえお") | ||||||
|     @example("ハンカクカタカナ") |     @example("ハンカクカタカナ") | ||||||
|     def test_accept(self, text): |     def test_accept(self, text: str) -> None: | ||||||
|         encode_katakana(text) |         encode_katakana(text) | ||||||
|  |  | ||||||
|     def test_result(self): |     def test_result(self) -> None: | ||||||
|         assert encode_katakana("カタカナ") == b"\xb6\xc0\xb6\xc5" |         assert encode_katakana("カタカナ") == b"\xb6\xc0\xb6\xc5" | ||||||
|         assert encode_katakana("あいうえお") == b"\xb1\xb2\xb3\xb4\xb5" |         assert encode_katakana("あいうえお") == b"\xb1\xb2\xb3\xb4\xb5" | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Alexandre Detiste
					Alexandre Detiste