Clean up tests and migrate (#540)
* migrate * abstract base class test * remove assert_equal in test_cli * remove nose from test_cli * remove nose dependencies * use tempfile * configure coverage * flag python version in name * enable comment * drop EOL py37
This commit is contained in:
parent
31daabcbea
commit
4c2dcdfac6
|
@ -15,7 +15,7 @@ jobs:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11']
|
python-version: ['3.8', '3.9', '3.10', '3.11']
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
|
@ -41,3 +41,13 @@ jobs:
|
||||||
tox
|
tox
|
||||||
env:
|
env:
|
||||||
ESCPOS_CAPABILITIES_FILE: /home/runner/work/python-escpos/python-escpos/capabilities-data/dist/capabilities.json
|
ESCPOS_CAPABILITIES_FILE: /home/runner/work/python-escpos/python-escpos/capabilities-data/dist/capabilities.json
|
||||||
|
- name: Upload coverage to Codecov
|
||||||
|
uses: codecov/codecov-action@v3
|
||||||
|
with:
|
||||||
|
directory: ./coverage/reports/
|
||||||
|
env_vars: OS,PYTHON
|
||||||
|
fail_ci_if_error: true
|
||||||
|
files: ./coverage.xml,!./cache
|
||||||
|
flags: unittests
|
||||||
|
name: coverage-tox-${{ matrix.python-version }}
|
||||||
|
verbose: true
|
|
@ -22,6 +22,7 @@ dist/
|
||||||
src/escpos/version.py
|
src/escpos/version.py
|
||||||
.hypothesis
|
.hypothesis
|
||||||
.pytest_cache/
|
.pytest_cache/
|
||||||
|
coverage.xml
|
||||||
|
|
||||||
# pyenv
|
# pyenv
|
||||||
.python-version
|
.python-version
|
||||||
|
@ -40,3 +41,4 @@ test/test-cli-output/
|
||||||
!.vscode/tasks.json
|
!.vscode/tasks.json
|
||||||
!.vscode/launch.json
|
!.vscode/launch.json
|
||||||
!.vscode/extensions.json
|
!.vscode/extensions.json
|
||||||
|
|
||||||
|
|
|
@ -52,7 +52,6 @@ We use basically standard rst-docstrings for Sphinx.
|
||||||
Test
|
Test
|
||||||
^^^^
|
^^^^
|
||||||
Try to write tests whenever possible. Our goal for the future is 100% coverage.
|
Try to write tests whenever possible. Our goal for the future is 100% coverage.
|
||||||
We are currently using `nose` but might change in the future.
|
|
||||||
You can copy the structure from other testcases. Please remember to adapt the docstrings.
|
You can copy the structure from other testcases. Please remember to adapt the docstrings.
|
||||||
|
|
||||||
Further reading
|
Further reading
|
||||||
|
|
|
@ -8,5 +8,10 @@ coverage:
|
||||||
changes: off
|
changes: off
|
||||||
range: "60...100"
|
range: "60...100"
|
||||||
|
|
||||||
comment: off
|
comment:
|
||||||
|
layout: " diff, flags, files"
|
||||||
|
behavior: default
|
||||||
|
require_changes: false # if true: only post the comment if coverage changes
|
||||||
|
require_base: false # [true :: must have a base report to post]
|
||||||
|
require_head: true # [true :: must have a head report to post]
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@ description = Python library to manipulate ESC/POS Printers
|
||||||
long_description = file: README.rst
|
long_description = file: README.rst
|
||||||
license = MIT
|
license = MIT
|
||||||
license_file = LICENSE
|
license_file = LICENSE
|
||||||
author = Manuel F Martinez and others
|
author = python-escpos developers
|
||||||
author_email = dev@pkanzler.de
|
author_email = dev@pkanzler.de
|
||||||
maintainer = Patrick Kanzler
|
maintainer = Patrick Kanzler
|
||||||
maintainer_email = dev@pkanzler.de
|
maintainer_email = dev@pkanzler.de
|
||||||
|
@ -18,7 +18,6 @@ classifiers =
|
||||||
Operating System :: OS Independent
|
Operating System :: OS Independent
|
||||||
Programming Language :: Python
|
Programming Language :: Python
|
||||||
Programming Language :: Python :: 3
|
Programming Language :: Python :: 3
|
||||||
Programming Language :: Python :: 3.7
|
|
||||||
Programming Language :: Python :: 3.8
|
Programming Language :: Python :: 3.8
|
||||||
Programming Language :: Python :: 3.9
|
Programming Language :: Python :: 3.9
|
||||||
Programming Language :: Python :: 3.10
|
Programming Language :: Python :: 3.10
|
||||||
|
@ -56,17 +55,12 @@ tests_require =
|
||||||
pytest!=3.2.0,!=3.3.0
|
pytest!=3.2.0,!=3.3.0
|
||||||
pytest-cov
|
pytest-cov
|
||||||
pytest-mock
|
pytest-mock
|
||||||
nose
|
|
||||||
scripttest
|
scripttest
|
||||||
mock
|
mock
|
||||||
hypothesis>4
|
hypothesis>4
|
||||||
flake8
|
flake8
|
||||||
sphinxcontrib-spelling>=7.2.0
|
sphinxcontrib-spelling>=7.2.0
|
||||||
|
|
||||||
[nosetests]
|
|
||||||
verbosity=3
|
|
||||||
with-doctest=1
|
|
||||||
|
|
||||||
[flake8]
|
[flake8]
|
||||||
exclude = .git,.tox,.github,.eggs,__pycache__,doc/conf.py,build,dist,capabilities-data,test,src/escpos/constants.py
|
exclude = .git,.tox,.github,.eggs,__pycache__,doc/conf.py,build,dist,capabilities-data,test,src/escpos/constants.py
|
||||||
max-line-length = 120
|
max-line-length = 120
|
||||||
|
|
|
@ -7,17 +7,16 @@
|
||||||
:license: MIT
|
:license: MIT
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import pytest
|
||||||
from nose.tools import raises
|
|
||||||
|
|
||||||
import escpos.escpos as escpos
|
import escpos.escpos as escpos
|
||||||
from abc import ABCMeta
|
from abc import ABCMeta
|
||||||
|
|
||||||
|
|
||||||
@raises(TypeError)
|
|
||||||
def test_abstract_base_class_raises():
|
def test_abstract_base_class_raises():
|
||||||
"""test whether the abstract base class raises an exception for ESC/POS"""
|
"""test whether the abstract base class raises an exception for ESC/POS"""
|
||||||
escpos.Escpos() # This call should raise TypeError because of abstractmethod _raw()
|
with pytest.raises(TypeError):
|
||||||
|
# This call should raise TypeError because of abstractmethod _raw()
|
||||||
|
escpos.Escpos()
|
||||||
|
|
||||||
|
|
||||||
def test_abstract_base_class():
|
def test_abstract_base_class():
|
||||||
|
|
|
@ -4,26 +4,25 @@
|
||||||
|
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import pytest
|
||||||
from scripttest import TestFileEnvironment
|
from scripttest import TestFileEnvironment as TFE
|
||||||
from nose.tools import assert_equal, nottest
|
import tempfile
|
||||||
|
import shutil
|
||||||
import escpos
|
import escpos
|
||||||
|
|
||||||
TEST_DIR = os.path.abspath("test/test-cli-output")
|
TEST_DIR = tempfile.mkdtemp() + "/cli-test"
|
||||||
|
|
||||||
DEVFILE_NAME = "testfile"
|
DEVFILE_NAME = "testfile"
|
||||||
|
|
||||||
DEVFILE = os.path.join(TEST_DIR, DEVFILE_NAME)
|
DEVFILE = os.path.join(TEST_DIR, DEVFILE_NAME)
|
||||||
CONFIGFILE = "testconfig.yaml"
|
CONFIGFILE = "testconfig.yaml"
|
||||||
CONFIG_YAML = """
|
CONFIG_YAML = f"""
|
||||||
---
|
---
|
||||||
|
|
||||||
printer:
|
printer:
|
||||||
type: file
|
type: file
|
||||||
devfile: {testfile}
|
devfile: {DEVFILE}
|
||||||
""".format(
|
"""
|
||||||
testfile=DEVFILE,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class TestCLI:
|
class TestCLI:
|
||||||
|
@ -39,13 +38,14 @@ class TestCLI:
|
||||||
def teardown_class(cls):
|
def teardown_class(cls):
|
||||||
"""Remove config file"""
|
"""Remove config file"""
|
||||||
os.remove(CONFIGFILE)
|
os.remove(CONFIGFILE)
|
||||||
|
shutil.rmtree(TEST_DIR)
|
||||||
|
|
||||||
def setup_method(self):
|
def setup_method(self):
|
||||||
"""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
|
||||||
|
|
||||||
self.env = TestFileEnvironment(
|
self.env = TFE(
|
||||||
base_path=TEST_DIR,
|
base_path=TEST_DIR,
|
||||||
cwd=os.getcwd(),
|
cwd=os.getcwd(),
|
||||||
)
|
)
|
||||||
|
@ -77,9 +77,11 @@ class TestCLI:
|
||||||
"""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_equal(escpos.__version__, result.stdout.strip())
|
assert escpos.__version__ == result.stdout.strip()
|
||||||
|
|
||||||
@nottest # disable this test as it is not that easy anymore to predict the outcome of this call
|
@pytest.mark.skip(
|
||||||
|
reason="disable this test as it is not that easy anymore to predict the outcome of this call"
|
||||||
|
)
|
||||||
def test_cli_text(self):
|
def test_cli_text(self):
|
||||||
"""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"
|
||||||
|
@ -95,15 +97,15 @@ class TestCLI:
|
||||||
)
|
)
|
||||||
assert not result.stderr
|
assert not result.stderr
|
||||||
assert DEVFILE_NAME in result.files_updated.keys()
|
assert DEVFILE_NAME in result.files_updated.keys()
|
||||||
assert_equals(result.files_updated[DEVFILE_NAME].bytes, test_text + "\n")
|
assert result.files_updated[DEVFILE_NAME].bytes == test_text + "\n"
|
||||||
|
|
||||||
def test_cli_text_inavlid_args(self):
|
def test_cli_text_invalid_args(self):
|
||||||
"""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")),
|
||||||
expect_error=True,
|
expect_error=True,
|
||||||
expect_stderr=True
|
expect_stderr=True,
|
||||||
)
|
)
|
||||||
assert_equal(result.returncode, 2)
|
assert result.returncode == 2
|
||||||
assert "error:" in result.stderr
|
assert "error:" in result.stderr
|
||||||
assert not result.files_updated
|
assert not result.files_updated
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
from nose.tools import assert_raises
|
|
||||||
from escpos.printer import Dummy
|
from escpos.printer import Dummy
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,6 @@
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
from nose.tools import raises
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
import escpos.printer as printer
|
import escpos.printer as printer
|
||||||
|
@ -66,24 +65,24 @@ def test_model():
|
||||||
assert instance.output == expected
|
assert instance.output == expected
|
||||||
|
|
||||||
|
|
||||||
@raises(ValueError)
|
|
||||||
def test_invalid_ec():
|
def test_invalid_ec():
|
||||||
"""Test invalid QR error correction"""
|
"""Test invalid QR error correction"""
|
||||||
instance = printer.Dummy()
|
instance = printer.Dummy()
|
||||||
|
with pytest.raises(ValueError):
|
||||||
instance.qr("1234", native=True, ec=-1)
|
instance.qr("1234", native=True, ec=-1)
|
||||||
|
|
||||||
|
|
||||||
@raises(ValueError)
|
|
||||||
def test_invalid_size():
|
def test_invalid_size():
|
||||||
"""Test invalid QR size"""
|
"""Test invalid QR size"""
|
||||||
instance = printer.Dummy()
|
instance = printer.Dummy()
|
||||||
|
with pytest.raises(ValueError):
|
||||||
instance.qr("1234", native=True, size=0)
|
instance.qr("1234", native=True, size=0)
|
||||||
|
|
||||||
|
|
||||||
@raises(ValueError)
|
|
||||||
def test_invalid_model():
|
def test_invalid_model():
|
||||||
"""Test invalid QR model"""
|
"""Test invalid QR model"""
|
||||||
instance = printer.Dummy()
|
instance = printer.Dummy()
|
||||||
|
with pytest.raises(ValueError):
|
||||||
instance.qr("1234", native=True, model="Hello")
|
instance.qr("1234", native=True, model="Hello")
|
||||||
|
|
||||||
|
|
||||||
|
@ -103,10 +102,10 @@ def test_image():
|
||||||
assert instance.output == expected
|
assert instance.output == expected
|
||||||
|
|
||||||
|
|
||||||
@raises(ValueError)
|
|
||||||
def test_image_invalid_model():
|
def test_image_invalid_model():
|
||||||
"""Test unsupported QR model as image"""
|
"""Test unsupported QR model as image"""
|
||||||
instance = printer.Dummy()
|
instance = printer.Dummy()
|
||||||
|
with pytest.raises(ValueError):
|
||||||
instance.qr("1234", native=False, model=QR_MODEL_1)
|
instance.qr("1234", native=False, model=QR_MODEL_1)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
from nose.tools import assert_raises
|
import pytest
|
||||||
from escpos.printer import Dummy
|
from escpos.printer import Dummy
|
||||||
|
|
||||||
|
|
||||||
|
@ -16,11 +16,11 @@ def test_line_spacing_rest():
|
||||||
|
|
||||||
def test_line_spacing_error_handling():
|
def test_line_spacing_error_handling():
|
||||||
printer = Dummy()
|
printer = Dummy()
|
||||||
with assert_raises(ValueError):
|
with pytest.raises(ValueError):
|
||||||
printer.line_spacing(99, divisor=44)
|
printer.line_spacing(99, divisor=44)
|
||||||
with assert_raises(ValueError):
|
with pytest.raises(ValueError):
|
||||||
printer.line_spacing(divisor=80, spacing=86)
|
printer.line_spacing(divisor=80, spacing=86)
|
||||||
with assert_raises(ValueError):
|
with pytest.raises(ValueError):
|
||||||
printer.line_spacing(divisor=360, spacing=256)
|
printer.line_spacing(divisor=360, spacing=256)
|
||||||
with assert_raises(ValueError):
|
with pytest.raises(ValueError):
|
||||||
printer.line_spacing(divisor=180, spacing=256)
|
printer.line_spacing(divisor=180, spacing=256)
|
||||||
|
|
|
@ -10,7 +10,6 @@
|
||||||
|
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from nose.tools import raises, assert_raises
|
|
||||||
from hypothesis import given, example
|
from hypothesis import given, example
|
||||||
import hypothesis.strategies as st
|
import hypothesis.strategies as st
|
||||||
from escpos.magicencode import MagicEncode, Encoder
|
from escpos.magicencode import MagicEncode, Encoder
|
||||||
|
@ -32,8 +31,8 @@ class TestEncoder:
|
||||||
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"
|
||||||
|
|
||||||
@raises(ValueError)
|
|
||||||
def test_get_encoding(self):
|
def test_get_encoding(self):
|
||||||
|
with pytest.raises(ValueError):
|
||||||
Encoder({}).get_encoding_name("latin1")
|
Encoder({}).get_encoding_name("latin1")
|
||||||
|
|
||||||
|
|
||||||
|
|
8
tox.ini
8
tox.ini
|
@ -1,5 +1,5 @@
|
||||||
[tox]
|
[tox]
|
||||||
envlist = py37, py38, py39, py310, py311, docs, flake8
|
envlist = py38, py39, py310, py311, docs, flake8
|
||||||
|
|
||||||
[gh-actions]
|
[gh-actions]
|
||||||
python =
|
python =
|
||||||
|
@ -10,10 +10,10 @@ python =
|
||||||
3.9: py39
|
3.9: py39
|
||||||
3.10: py310
|
3.10: py310
|
||||||
3.11: py311
|
3.11: py311
|
||||||
|
3.12: py312
|
||||||
|
|
||||||
[testenv]
|
[testenv]
|
||||||
deps = nose
|
deps = jaconv
|
||||||
jaconv
|
|
||||||
coverage
|
coverage
|
||||||
scripttest
|
scripttest
|
||||||
mock
|
mock
|
||||||
|
@ -22,7 +22,7 @@ deps = nose
|
||||||
pytest-mock
|
pytest-mock
|
||||||
hypothesis>4
|
hypothesis>4
|
||||||
python-barcode
|
python-barcode
|
||||||
commands = pytest --cov escpos
|
commands = pytest --cov escpos --cov-report=xml
|
||||||
passenv = ESCPOS_CAPABILITIES_PICKLE_DIR, ESCPOS_CAPABILITIES_FILE, CI, TRAVIS, TRAVIS_*, APPVEYOR, APPVEYOR_*, CODECOV_*
|
passenv = ESCPOS_CAPABILITIES_PICKLE_DIR, ESCPOS_CAPABILITIES_FILE, CI, TRAVIS, TRAVIS_*, APPVEYOR, APPVEYOR_*, CODECOV_*
|
||||||
|
|
||||||
[testenv:docs]
|
[testenv:docs]
|
||||||
|
|
Loading…
Reference in New Issue