Blob Blame History Raw
From 2eae1cd98ae518a7eb6d72bdf95e56baa36e1d05 Mon Sep 17 00:00:00 2001
From: "Ankur Sinha (Ankur Sinha Gmail)" <sanjay.ankur@gmail.com>
Date: Tue, 6 Jul 2021 13:45:03 +0100
Subject: [PATCH 1/3] feat: replace nose with pytest

Nose is deprecated. The nose website says:

https://nose.readthedocs.io/en/latest/

"Nose has been in maintenance mode for the past several years and will
likely cease without a new person/team to take over maintainership. New
projects should consider using Nose2, py.test, or just plain
unittest/unittest2."

Deprecation of nose in Fedora:
https://fedoraproject.org/wiki/Changes/DeprecateNose
---
 gitlab-ci-test.sh                  | 4 ++--
 meta.yaml                          | 4 ++--
 requirements.txt                   | 5 +++--
 tests/helper_functions/__init__.py | 9 ++++-----
 tests/test_pymatreader.py          | 6 +++---
 tox.ini                            | 5 +++--
 tox_ci.ini                         | 5 +++--
 7 files changed, 20 insertions(+), 18 deletions(-)

diff --git a/gitlab-ci-test.sh b/gitlab-ci-test.sh
index 094761e..68cc759 100644
--- a/gitlab-ci-test.sh
+++ b/gitlab-ci-test.sh
@@ -3,6 +3,6 @@ cd $CI_PROJECT_DIR
 apt-get update
 apt-get install -y libhdf5-dev
 pip install -U -r requirements.txt
-nosetests --with-coverage --cover-package=pymatreader && \
+pytest --cov=pymatreader && \
 tox -c tox_ci.ini && \
-codecov
\ No newline at end of file
+codecov
diff --git a/meta.yaml b/meta.yaml
index b887810..f009533 100644
--- a/meta.yaml
+++ b/meta.yaml
@@ -33,9 +33,9 @@ test:
   source_files:
     - tests
   requires:
-    - nose
+    - pytest pytest-cov
   commands:
-    - nosetests tests
+    - pytest
 
 about:
   home: {{ data.url }}
diff --git a/requirements.txt b/requirements.txt
index cf965a5..33370b9 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -1,7 +1,8 @@
 h5py
 scipy
 numpy
-nose
+pytest
+pytest-cov
 xmltodict
 sphinx
 sphinx-autobuild
@@ -12,4 +13,4 @@ twine
 wheel
 coverage
 flake8
-codecov
\ No newline at end of file
+codecov
diff --git a/tests/helper_functions/__init__.py b/tests/helper_functions/__init__.py
index 3a50ea4..9ef10a7 100644
--- a/tests/helper_functions/__init__.py
+++ b/tests/helper_functions/__init__.py
@@ -29,7 +29,6 @@ import string
 
 import numpy
 import xmltodict
-from nose.tools import assert_almost_equal, assert_equal
 import types
 
 
@@ -57,24 +56,24 @@ def assertDeepAlmostEqual(expected, actual, *args, **kwargs):
 
     try:
         if isinstance(expected, (int, float, complex)):
-            assert_almost_equal(expected, actual, *args, **kwargs)
+            numpy.testing.assert_almost_equal(expected, actual, *args, **kwargs)
         elif isinstance(expected, (list, tuple, numpy.ndarray, types.GeneratorType)):
             if isinstance(expected, types.GeneratorType):
                 expected = list(expected)
                 actual = list(actual)
 
-            assert_equal(len(expected), len(actual))
+            assert len(expected) == len(actual)
             for index in range(len(expected)):
                 v1, v2 = expected[index], actual[index]
                 assertDeepAlmostEqual(v1, v2,
                                       __trace=repr(index), *args, **kwargs)
         elif isinstance(expected, dict):
-            assert_equal(set(expected), set(actual))
+            assert set(expected) == set(actual)
             for key in expected:
                 assertDeepAlmostEqual(expected[key], actual[key],
                                       __trace=repr(key), *args, **kwargs)
         else:
-            assert_equal(expected, actual)
+            assert expected == actual
     except AssertionError as exc:
         exc.__dict__.setdefault('traces', []).append(trace)
         if is_root:
diff --git a/tests/test_pymatreader.py b/tests/test_pymatreader.py
index 91b4318..c92414a 100644
--- a/tests/test_pymatreader.py
+++ b/tests/test_pymatreader.py
@@ -28,7 +28,7 @@
 import os.path
 from unittest import TestCase
 
-from nose.tools import raises
+import pytest
 
 from pymatreader import read_mat
 from .helper_functions import assertDeepAlmostEqual, sanitize_dict, \
@@ -201,9 +201,9 @@ def test_raw_old_eeglab_event_type():
     first_event.latency
 
 
-@raises(IOError)
 def test_file_does_not_exist():
-    read_mat(os.path.join(test_data_folder, invalid_fname))
+    with pytest.raises(IOError):
+        read_mat(os.path.join(test_data_folder, invalid_fname))
 
 
 def test_files_with_unsupported_classesv7():
diff --git a/tox.ini b/tox.ini
index 25cb508..71680b0 100644
--- a/tox.ini
+++ b/tox.ini
@@ -7,6 +7,7 @@
 envlist = py37, py38, py39
 
 [testenv]
-commands = nosetests
+commands = pytest
 deps =
-    nose
+    pytest
+    pytest-cov
diff --git a/tox_ci.ini b/tox_ci.ini
index 3ddd816..6fdcfd2 100644
--- a/tox_ci.ini
+++ b/tox_ci.ini
@@ -1,4 +1,5 @@
 [testenv]
-commands = nosetests
+commands = pytest
 deps =
-    nose
\ No newline at end of file
+    pytest
+    pytest-cov
-- 
2.31.1