Repository: python-escpos/python-escpos (language: python)

Issue:
add codecov action to pythonpackage.yml
https://github.com/codecov/codecov-action


Discussion / hints:

Fix patch:
diff --git a/.github/workflows/pythonpackage.yml b/.github/workflows/pythonpackage.yml
index 3351f5e9..ec332953 100644
--- a/.github/workflows/pythonpackage.yml
+++ b/.github/workflows/pythonpackage.yml
@@ -15,7 +15,7 @@ jobs:
     runs-on: ubuntu-latest
     strategy:
       matrix:
-        python-version: ['3.7', '3.8', '3.9', '3.10', '3.11']
+        python-version: ['3.8', '3.9', '3.10', '3.11']
 
     steps:
     - uses: actions/checkout@v3
@@ -41,3 +41,13 @@ jobs:
         tox
       env:
         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
\ No newline at end of file
diff --git a/.gitignore b/.gitignore
index 22c4005c..b89c3eea 100644
--- a/.gitignore
+++ b/.gitignore
@@ -22,6 +22,7 @@ dist/
 src/escpos/version.py
 .hypothesis
 .pytest_cache/
+coverage.xml
 
 # pyenv
 .python-version
@@ -40,3 +41,4 @@ test/test-cli-output/
 !.vscode/tasks.json
 !.vscode/launch.json
 !.vscode/extensions.json
+
diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst
index 3c918c7e..0df6e306 100644
--- a/CONTRIBUTING.rst
+++ b/CONTRIBUTING.rst
@@ -52,7 +52,6 @@ We use basically standard rst-docstrings for Sphinx.
 Test
 ^^^^
 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.
 
 Further reading
diff --git a/codecov.yml b/codecov.yml
index e236e8c6..141dd44a 100644
--- a/codecov.yml
+++ b/codecov.yml
@@ -8,5 +8,10 @@ coverage:
     changes: off
   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]
 
diff --git a/setup.cfg b/setup.cfg
index 1722cbf5..4d8c4dc0 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -5,7 +5,7 @@ description = Python library to manipulate ESC/POS Printers
 long_description = file: README.rst
 license = MIT
 license_file = LICENSE
-author = Manuel F Martinez and others
+author = python-escpos developers
 author_email = dev@pkanzler.de
 maintainer = Patrick Kanzler
 maintainer_email = dev@pkanzler.de
@@ -18,7 +18,6 @@ classifiers =
     Operating System :: OS Independent
     Programming Language :: Python
     Programming Language :: Python :: 3
-    Programming Language :: Python :: 3.7
     Programming Language :: Python :: 3.8
     Programming Language :: Python :: 3.9
     Programming Language :: Python :: 3.10
@@ -56,17 +55,12 @@ tests_require =
     pytest!=3.2.0,!=3.3.0
     pytest-cov
     pytest-mock
-    nose
     scripttest
     mock
     hypothesis>4
     flake8
     sphinxcontrib-spelling>=7.2.0
 
-[nosetests]
-verbosity=3
-with-doctest=1
-
 [flake8]
 exclude = .git,.tox,.github,.eggs,__pycache__,doc/conf.py,build,dist,capabilities-data,test,src/escpos/constants.py
 max-line-length = 120
diff --git a/tox.ini b/tox.ini
index 1adcd453..97849d07 100644
--- a/tox.ini
+++ b/tox.ini
@@ -1,5 +1,5 @@
 [tox]
-envlist = py37, py38, py39, py310, py311, docs, flake8
+envlist = py38, py39, py310, py311, docs, flake8
 
 [gh-actions]
 python =
@@ -10,10 +10,10 @@ python =
     3.9: py39
     3.10: py310
     3.11: py311
+    3.12: py312
 
 [testenv]
-deps = nose
-       jaconv
+deps = jaconv
        coverage
        scripttest
        mock
@@ -22,7 +22,7 @@ deps = nose
        pytest-mock
        hypothesis>4
        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_*
 
 [testenv:docs]


Test patch:
diff --git a/test/test_abstract_base_class.py b/test/test_abstract_base_class.py
index 46f215b7..2e235fda 100644
--- a/test/test_abstract_base_class.py
+++ b/test/test_abstract_base_class.py
@@ -7,17 +7,16 @@
 :license: MIT
 """
 
-
-from nose.tools import raises
-
+import pytest
 import escpos.escpos as escpos
 from abc import ABCMeta
 
 
-@raises(TypeError)
 def test_abstract_base_class_raises():
     """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():
diff --git a/test/test_cli.py b/test/test_cli.py
index fc6e02ee..ae763cb7 100644
--- a/test/test_cli.py
+++ b/test/test_cli.py
@@ -4,26 +4,25 @@
 
 
 import os
-import sys
-from scripttest import TestFileEnvironment
-from nose.tools import assert_equal, nottest
+import pytest
+from scripttest import TestFileEnvironment as TFE
+import tempfile
+import shutil
 import escpos
 
-TEST_DIR = os.path.abspath("test/test-cli-output")
+TEST_DIR = tempfile.mkdtemp() + "/cli-test"
 
 DEVFILE_NAME = "testfile"
 
 DEVFILE = os.path.join(TEST_DIR, DEVFILE_NAME)
 CONFIGFILE = "testconfig.yaml"
-CONFIG_YAML = """
+CONFIG_YAML = f"""
 ---
 
 printer:
     type: file
-    devfile: {testfile}
-""".format(
-    testfile=DEVFILE,
-)
+    devfile: {DEVFILE}
+"""
 
 
 class TestCLI:
@@ -39,13 +38,14 @@ def setup_class(cls):
     def teardown_class(cls):
         """Remove config file"""
         os.remove(CONFIGFILE)
+        shutil.rmtree(TEST_DIR)
 
     def setup_method(self):
         """Create a file to print to and set up env"""
         self.env = None
         self.default_args = None
 
-        self.env = TestFileEnvironment(
+        self.env = TFE(
             base_path=TEST_DIR,
             cwd=os.getcwd(),
         )
@@ -77,9 +77,11 @@ def test_cli_version(self):
         """Test the version string"""
         result = self.env.run("python-escpos", "version")
         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):
         """Make sure text returns what we sent it"""
         test_text = "this is some text"
@@ -95,15 +97,15 @@ def test_cli_text(self):
         )
         assert not result.stderr
         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"""
         result = self.env.run(
             *(self.default_args + ("text", "--invalid-param", "some data")),
             expect_error=True,
-            expect_stderr=True
+            expect_stderr=True,
         )
-        assert_equal(result.returncode, 2)
+        assert result.returncode == 2
         assert "error:" in result.stderr
         assert not result.files_updated
diff --git a/test/test_function_dummy_clear.py b/test/test_function_dummy_clear.py
index 142a0a8c..40ca9d40 100644
--- a/test/test_function_dummy_clear.py
+++ b/test/test_function_dummy_clear.py
@@ -1,4 +1,3 @@
-from nose.tools import assert_raises
 from escpos.printer import Dummy
 
 
diff --git a/test/test_function_qr_native.py b/test/test_function_qr_native.py
index 8dfed74f..876b38db 100644
--- a/test/test_function_qr_native.py
+++ b/test/test_function_qr_native.py
@@ -8,7 +8,6 @@
 """
 
 
-from nose.tools import raises
 import pytest
 
 import escpos.printer as printer
@@ -66,25 +65,25 @@ def test_model():
     assert instance.output == expected
 
 
-@raises(ValueError)
 def test_invalid_ec():
     """Test invalid QR error correction"""
     instance = printer.Dummy()
-    instance.qr("1234", native=True, ec=-1)
+    with pytest.raises(ValueError):
+        instance.qr("1234", native=True, ec=-1)
 
 
-@raises(ValueError)
 def test_invalid_size():
     """Test invalid QR size"""
     instance = printer.Dummy()
-    instance.qr("1234", native=True, size=0)
+    with pytest.raises(ValueError):
+        instance.qr("1234", native=True, size=0)
 
 
-@raises(ValueError)
 def test_invalid_model():
     """Test invalid QR model"""
     instance = printer.Dummy()
-    instance.qr("1234", native=True, model="Hello")
+    with pytest.raises(ValueError):
+        instance.qr("1234", native=True, model="Hello")
 
 
 @pytest.mark.skip("this test has to be debugged")
@@ -103,11 +102,11 @@ def test_image():
     assert instance.output == expected
 
 
-@raises(ValueError)
 def test_image_invalid_model():
     """Test unsupported QR model as image"""
     instance = printer.Dummy()
-    instance.qr("1234", native=False, model=QR_MODEL_1)
+    with pytest.raises(ValueError):
+        instance.qr("1234", native=False, model=QR_MODEL_1)
 
 
 @pytest.fixture
diff --git a/test/test_functions.py b/test/test_functions.py
index 1b58ca58..d98336e5 100644
--- a/test/test_functions.py
+++ b/test/test_functions.py
@@ -1,4 +1,4 @@
-from nose.tools import assert_raises
+import pytest
 from escpos.printer import Dummy
 
 
@@ -16,11 +16,11 @@ def test_line_spacing_rest():
 
 def test_line_spacing_error_handling():
     printer = Dummy()
-    with assert_raises(ValueError):
+    with pytest.raises(ValueError):
         printer.line_spacing(99, divisor=44)
-    with assert_raises(ValueError):
+    with pytest.raises(ValueError):
         printer.line_spacing(divisor=80, spacing=86)
-    with assert_raises(ValueError):
+    with pytest.raises(ValueError):
         printer.line_spacing(divisor=360, spacing=256)
-    with assert_raises(ValueError):
+    with pytest.raises(ValueError):
         printer.line_spacing(divisor=180, spacing=256)
diff --git a/test/test_magicencode.py b/test/test_magicencode.py
index 5debbbef..c2e89d13 100644
--- a/test/test_magicencode.py
+++ b/test/test_magicencode.py
@@ -10,7 +10,6 @@
 
 
 import pytest
-from nose.tools import raises, assert_raises
 from hypothesis import given, example
 import hypothesis.strategies as st
 from escpos.magicencode import MagicEncode, Encoder
@@ -32,9 +31,9 @@ def test_find_suitable_encoding(self):
         assert not Encoder({"CP437": 1}).find_suitable_encoding("€")
         assert Encoder({"CP858": 1}).find_suitable_encoding("€") == "CP858"
 
-    @raises(ValueError)
     def test_get_encoding(self):
-        Encoder({}).get_encoding_name("latin1")
+        with pytest.raises(ValueError):
+            Encoder({}).get_encoding_name("latin1")
 
 
 class TestMagicEncode: