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