1
0
mirror of https://github.com/python-escpos/python-escpos synced 2025-08-24 09:03:34 +00:00

start removal of six and improve type annotation (#607)

* fix unfinished Python2 -> 3 translation
* remove some six usage
* annotate
* fix regression in Six removal
* mypy: self.enf is always defined
* fix return type of cups.py
* Usb idVendor/idProduct are integers
* self.default_args is always defined
* tweak usb_args, PEP589 is better
* lp.py: reassure mypy
* correctly cast call to CashDrawerError()
* update CUPS test
* add missing close() method in metaclass
* document a bug in typeshed
* query_status() returns bytes as seen in constants.py
* remove more SIX usage
* test examples too
* remove type comment where type is annotated
* adapt behavior of cups printer to match other implementations

---------

Co-authored-by: Patrick Kanzler <dev@pkanzler.de>
Co-authored-by: Patrick Kanzler <4189642+patkan@users.noreply.github.com>
This commit is contained in:
Alexandre Detiste
2023-12-16 22:02:24 +01:00
committed by GitHub
parent 06bdb56937
commit 66a2e78e16
31 changed files with 245 additions and 237 deletions

View File

@@ -7,7 +7,6 @@ import os
import shutil
import tempfile
import pytest
from scripttest import TestFileEnvironment as TFE
import escpos
@@ -31,22 +30,19 @@ 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
self.env = TFE(
base_path=TEST_DIR,
cwd=os.getcwd(),
@@ -64,24 +60,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 +85,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 +104,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")),