1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174
|
From: Emanuele Rocca <ema@debian.org>
Date: Fri, 14 Oct 2022 21:22:50 +0200
Subject: replace nose assert_ with regular assertions or pytest equivalents
--- a/tests/__init__.py
+++ b/tests/__init__.py
@@ -1,17 +1,11 @@
-#!/usr/bin/env python
+def assert_equals(a, b):
+ assert a == b
-import functools
+def assert_equal(a, b):
+ assert a == b
-from nose import SkipTest
+def assert_true(a):
+ assert a is True
-
-def expected_failure(test):
- @functools.wraps(test)
- def inner(*args, **kwargs):
- try:
- test(*args, **kwargs)
- except Exception:
- raise SkipTest
- else:
- raise AssertionError('Failure expected')
- return inner
+def assert_false(a):
+ assert a is False
--- a/tests/test_inputs.py
+++ b/tests/test_inputs.py
@@ -4,10 +4,11 @@ import pytz
import re
#noinspection PyUnresolvedReferences
-from nose.tools import assert_equal, assert_raises # you need it for tests in form of continuations
+from pytest import raises
import six
from flask_restful import inputs
+from tests import assert_equal
def test_reverse_rfc822_datetime():
@@ -119,7 +120,7 @@ def test_regex_bad_input():
num_only = inputs.regex(r'^[0-9]+$')
for value in cases:
- yield assert_raises, ValueError, lambda: num_only(value)
+ yield raises, ValueError, lambda: num_only(value)
def test_regex_good_input():
@@ -137,7 +138,7 @@ def test_regex_good_input():
def test_regex_bad_pattern():
"""Regex error raised immediately when regex input parser is created."""
- assert_raises(re.error, inputs.regex, '[')
+ raises(re.error, inputs.regex, '[')
def test_regex_flags_good_input():
@@ -162,7 +163,7 @@ def test_regex_flags_bad_input():
case_sensitive = inputs.regex(r'^[A-Z]+$')
for value in cases:
- yield assert_raises, ValueError, lambda: case_sensitive(value)
+ yield raises, ValueError, lambda: case_sensitive(value)
class TypesTestCase(unittest.TestCase):
@@ -192,35 +193,35 @@ class TypesTestCase(unittest.TestCase):
assert_equal(inputs.boolean(False), False)
def test_bad_boolean(self):
- assert_raises(ValueError, lambda: inputs.boolean("blah"))
+ raises(ValueError, lambda: inputs.boolean("blah"))
def test_date_later_than_1900(self):
assert_equal(inputs.date("1900-01-01"), datetime(1900, 1, 1))
def test_date_input_error(self):
- assert_raises(ValueError, lambda: inputs.date("2008-13-13"))
+ raises(ValueError, lambda: inputs.date("2008-13-13"))
def test_date_input(self):
assert_equal(inputs.date("2008-08-01"), datetime(2008, 8, 1))
def test_natual_negative(self):
- assert_raises(ValueError, lambda: inputs.natural(-1))
+ raises(ValueError, lambda: inputs.natural(-1))
def test_natural(self):
assert_equal(3, inputs.natural(3))
def test_natual_string(self):
- assert_raises(ValueError, lambda: inputs.natural('foo'))
+ raises(ValueError, lambda: inputs.natural('foo'))
def test_positive(self):
assert_equal(1, inputs.positive(1))
assert_equal(10000, inputs.positive(10000))
def test_positive_zero(self):
- assert_raises(ValueError, lambda: inputs.positive(0))
+ raises(ValueError, lambda: inputs.positive(0))
def test_positive_negative_input(self):
- assert_raises(ValueError, lambda: inputs.positive(-1))
+ raises(ValueError, lambda: inputs.positive(-1))
def test_int_range_good(self):
int_range = inputs.int_range(1, 5)
@@ -232,11 +233,11 @@ class TypesTestCase(unittest.TestCase):
def test_int_range_low(self):
int_range = inputs.int_range(0, 5)
- assert_raises(ValueError, lambda: int_range(-1))
+ raises(ValueError, lambda: int_range(-1))
def test_int_range_high(self):
int_range = inputs.int_range(0, 5)
- assert_raises(ValueError, lambda: int_range(6))
+ raises(ValueError, lambda: int_range(6))
def test_isointerval():
@@ -416,7 +417,7 @@ def test_bad_isointervals():
for bad_interval in bad_intervals:
yield (
- assert_raises,
+ raises,
Exception,
inputs.iso8601interval,
bad_interval,
--- a/tests/test_api_with_blueprint.py
+++ b/tests/test_api_with_blueprint.py
@@ -9,8 +9,7 @@ import flask
import flask_restful
import flask_restful.fields
#noinspection PyUnresolvedReferences
-from nose.tools import assert_true, assert_false # you need it for tests in form of continuations
-
+from tests import assert_true, assert_false
# Add a dummy Resource to verify that the app is properly set.
class HelloWorld(flask_restful.Resource):
--- a/tests/test_fields.py
+++ b/tests/test_fields.py
@@ -9,8 +9,7 @@ from flask_restful import fields
from datetime import datetime, timedelta, tzinfo
from flask import Flask, Blueprint
#noinspection PyUnresolvedReferences
-from nose.tools import assert_equals # you need it for tests in form of continuations
-
+from tests import assert_equals
class Foo(object):
def __init__(self):
--- a/tests/test_api.py
+++ b/tests/test_api.py
@@ -16,7 +16,7 @@ import flask_restful
import flask_restful.fields
from flask_restful import OrderedDict
from json import dumps, loads, JSONEncoder
-from nose.tools import assert_equal # you need it for tests in form of continuations
+from tests import assert_equal
import six
from types import SimpleNamespace
from unittest.mock import patch
|