From 78a0bcdf7ca6734e4467669787574abedf092641 Mon Sep 17 00:00:00 2001 From: Joscha Schmiedt <joscha@schmiedt.dev> Date: Fri, 29 Mar 2024 21:32:17 +0100 Subject: [PATCH] Remove nose dependency from testing Only nose.tools was used, which can easily be replaced with one-liners and pytest.raises --- tox.ini | 1 - unittests/test_concrete_property.py | 13 +++++++--- unittests/test_connection.py | 39 +++++++++++++++++------------ unittests/test_connection_utils.py | 15 ++++++++--- unittests/test_file.py | 11 +++----- unittests/test_record_type.py | 12 +++------ 6 files changed, 53 insertions(+), 38 deletions(-) diff --git a/tox.ini b/tox.ini index 9a862f69..b87f6e81 100644 --- a/tox.ini +++ b/tox.ini @@ -4,7 +4,6 @@ skip_missing_interpreters = true [testenv] deps = . - pynose pytest pytest-cov mypy diff --git a/unittests/test_concrete_property.py b/unittests/test_concrete_property.py index e70668f0..6a55dcf9 100644 --- a/unittests/test_concrete_property.py +++ b/unittests/test_concrete_property.py @@ -28,9 +28,16 @@ from linkahead import configure_connection from linkahead.common.models import _ConcreteProperty from linkahead.connection.mockup import MockUpServerConnection # pylint: disable=missing-docstring -from nose.tools import assert_equal as eq -from nose.tools import assert_is_not_none as there -from nose.tools import assert_true as tru +def eq(a,b): + assert a == b + +def there(a): + assert a is not None + +def tru(a): + assert a + +from pytest import raises def setup_module(): diff --git a/unittests/test_connection.py b/unittests/test_connection.py index ca36a716..a4903fb3 100644 --- a/unittests/test_connection.py +++ b/unittests/test_connection.py @@ -39,11 +39,17 @@ from linkahead.connection.mockup import (MockUpResponse, MockUpServerConnection, from linkahead.connection.utils import make_uri_path, quote, urlencode from linkahead.exceptions import (ConfigurationError, LoginFailedError, LinkAheadConnectionError) -from nose.tools import assert_equal as eq -from nose.tools import assert_false as falz -from nose.tools import assert_is_not_none as there -from nose.tools import assert_raises as raiz -from nose.tools import assert_true as tru + + +def eq(a,b): + assert a == b + +def there(a): + assert a is not None + +def tru(a): + assert a + from pytest import raises @@ -74,11 +80,11 @@ def test_urlencode(): eq(urlencode({'key1': 'val1'}), 'key1=val1') eq(urlencode({'keynoval': None}), 'keynoval=') eq(urlencode({'kèy': 'välüe'}), 'k%C3%A8y=v%C3%A4l%C3%BCe') - with raiz(AttributeError): + with raises(AttributeError) as exc_info: urlencode({bytes('asdf', 'utf-8'): 'asdf'}) - with raiz(AttributeError): + with raises(AttributeError) as exc_info: urlencode({'asdf': bytes('asdf', 'utf-8')}) - with raiz(AttributeError): + with raises(AttributeError) as exc_info: urlencode({None: 'asdf'}) @@ -138,10 +144,11 @@ def test_configure_connection_bad_url(): def test_connection_interface(): - with raiz(TypeError) as cm: + + with raises(TypeError) as cm: CaosDBServerConnection() - tru(cm.exception.args[0].startswith( - "Can't instantiate abstract class CaosDBServerConnection")) + + assert "Can't instantiate abstract class CaosDBServerConnection" in str(cm.value) tru(hasattr(CaosDBServerConnection, "request")) tru(hasattr(CaosDBServerConnection.request, "__call__")) @@ -151,10 +158,10 @@ def test_connection_interface(): def test_use_mockup_implementation(): - with raiz(RuntimeError) as rerr: + with raises(RuntimeError) as rerr: execute_query("FIND Something") - print(rerr.exception.args[0]) - eq(rerr.exception.args[0], + print(str(rerr.value)) + eq(str(rerr.value), "No response for this request - GET: Entity?query=FIND%20Something") @@ -219,9 +226,9 @@ def test_resources_list(): def test_request_basics(): connection = test_init_connection() tru(hasattr(connection, "request")) - with raiz(RuntimeError) as cm: + with raises(RuntimeError) as cm: connection.request(method="GET", path="asdf") - eq(cm.exception.args[0], "No response for this request - GET: asdf") + eq(str(cm.value), "No response for this request - GET: asdf") connection = test_resources_list() there(connection.request(method="GET", path="asdf")) diff --git a/unittests/test_connection_utils.py b/unittests/test_connection_utils.py index 6a95fffa..4f114783 100644 --- a/unittests/test_connection_utils.py +++ b/unittests/test_connection_utils.py @@ -25,9 +25,18 @@ # pylint: disable=missing-docstring from __future__ import unicode_literals, print_function from pytest import raises -from nose.tools import (assert_equal as eq, assert_raises as raiz, assert_true - as tru, assert_is_not_none as there, assert_false as - falz) + +def eq(a,b): + assert a == b + +def there(a): + assert a is not None + +def tru(a): + assert a + +from pytest import raises + from linkahead.exceptions import ConfigurationError, LoginFailedError from linkahead.connection.utils import parse_auth_token, auth_token_to_cookie from linkahead.connection.connection import ( diff --git a/unittests/test_file.py b/unittests/test_file.py index dd974cb1..c1093cdd 100644 --- a/unittests/test_file.py +++ b/unittests/test_file.py @@ -25,13 +25,10 @@ from linkahead import File, Record, configure_connection from linkahead.connection.mockup import MockUpServerConnection # pylint: disable=missing-docstring -from nose.tools import assert_equal as eq -from nose.tools import assert_is_not_none as there -from nose.tools import assert_true as tru def setup_module(): - there(File) + assert File is not None configure_connection(url="unittests", username="testuser", password_method="plain", password="testpassword", timeout=200, @@ -39,12 +36,12 @@ def setup_module(): def hat(obj, attr): - tru(hasattr(obj, attr)) + assert hasattr(obj, attr) def test_is_record(): file_ = File() - tru(isinstance(file_, Record)) + assert isinstance(file_, Record) def test_instance_variable(): @@ -57,4 +54,4 @@ def test_instance_variable(): def test_role(): file_ = File() - eq(file_.role, "File") + assert file_.role == "File" diff --git a/unittests/test_record_type.py b/unittests/test_record_type.py index 594f9c64..87a3d229 100644 --- a/unittests/test_record_type.py +++ b/unittests/test_record_type.py @@ -25,13 +25,9 @@ from linkahead import Entity, RecordType, configure_connection from linkahead.connection.mockup import MockUpServerConnection # pylint: disable=missing-docstring -from nose.tools import assert_equal as eq -from nose.tools import assert_is_not_none as there -from nose.tools import assert_true as tru - def setup_module(): - there(RecordType) + assert RecordType is not None configure_connection(url="unittests", username="testuser", password_method="plain", password="testpassword", timeout=200, @@ -39,14 +35,14 @@ def setup_module(): def hat(obj, attr): - tru(hasattr(obj, attr)) + assert hasattr(obj, attr) def test_is_entity(): recty = RecordType() - tru(isinstance(recty, Entity)) + assert isinstance(recty, Entity) def test_role(): recty = RecordType() - eq(recty.role, "RecordType") + assert recty.role == "RecordType" -- GitLab