at master 5.3 kB view raw
1diff --git a/tests/test_inputs.py b/tests/test_inputs.py 2index 7c30d45..645b728 100644 3--- a/tests/test_inputs.py 4+++ b/tests/test_inputs.py 5@@ -5,6 +5,7 @@ import re 6 7 #noinspection PyUnresolvedReferences 8 import six 9+import pytest 10 11 from flask_restful import inputs 12 13@@ -17,7 +18,7 @@ def test_reverse_rfc822_datetime(): 14 ] 15 16 for date_string, expected in dates: 17- yield assert_equal, inputs.datetime_from_rfc822(date_string), expected 18+ assert inputs.datetime_from_rfc822(date_string) == expected 19 20 21 def test_reverse_iso8601_datetime(): 22@@ -29,7 +30,7 @@ def test_reverse_iso8601_datetime(): 23 ] 24 25 for date_string, expected in dates: 26- yield assert_equal, inputs.datetime_from_iso8601(date_string), expected 27+ assert inputs.datetime_from_iso8601(date_string) == expected 28 29 30 def test_urls(): 31@@ -53,7 +54,7 @@ def test_urls(): 32 ] 33 34 for value in urls: 35- yield assert_equal, inputs.url(value), value 36+ assert inputs.url(value) == value 37 38 39 def check_bad_url_raises(value): 40@@ -118,7 +119,8 @@ def test_regex_bad_input(): 41 num_only = inputs.regex(r'^[0-9]+$') 42 43 for value in cases: 44- yield assert_raises, ValueError, lambda: num_only(value) 45+ with pytest.raises(ValueError): 46+ num_only(value) 47 48 49 def test_regex_good_input(): 50@@ -131,12 +133,13 @@ def test_regex_good_input(): 51 num_only = inputs.regex(r'^[0-9]+$') 52 53 for value in cases: 54- yield assert_equal, num_only(value), value 55+ assert num_only(value) == value 56 57 58 def test_regex_bad_pattern(): 59 """Regex error raised immediately when regex input parser is created.""" 60- assert_raises(re.error, inputs.regex, '[') 61+ with pytest.raises(re.error): 62+ inputs.regex('[') 63 64 65 def test_regex_flags_good_input(): 66@@ -149,7 +152,7 @@ def test_regex_flags_good_input(): 67 case_insensitive = inputs.regex(r'^[A-Z]+$', re.IGNORECASE) 68 69 for value in cases: 70- yield assert_equal, case_insensitive(value), value 71+ assert case_insensitive(value) == value 72 73 74 def test_regex_flags_bad_input(): 75@@ -161,7 +164,8 @@ def test_regex_flags_bad_input(): 76 case_sensitive = inputs.regex(r'^[A-Z]+$') 77 78 for value in cases: 79- yield assert_raises, ValueError, lambda: case_sensitive(value) 80+ with pytest.raises(ValueError): 81+ case_sensitive(value) 82 83 84 class TypesTestCase(unittest.TestCase): 85@@ -191,35 +195,41 @@ class TypesTestCase(unittest.TestCase): 86 assert inputs.boolean(False) == False 87 88 def test_bad_boolean(self): 89- assert_raises(ValueError, lambda: inputs.boolean("blah")) 90+ with pytest.raises(ValueError): 91+ inputs.boolean("blah") 92 93 def test_date_later_than_1900(self): 94 assert inputs.date("1900-01-01") == datetime(1900, 1, 1) 95 96 def test_date_input_error(self): 97- assert_raises(ValueError, lambda: inputs.date("2008-13-13")) 98+ with pytest.raises(ValueError): 99+ inputs.date("2008-13-13") 100 101 def test_date_input(self): 102 assert inputs.date("2008-08-01") == datetime(2008, 8, 1) 103 104 def test_natual_negative(self): 105- assert_raises(ValueError, lambda: inputs.natural(-1)) 106+ with pytest.raises(ValueError): 107+ inputs.natural(-1) 108 109 def test_natural(self): 110 assert 3 == inputs.natural(3) 111 112 def test_natual_string(self): 113- assert_raises(ValueError, lambda: inputs.natural('foo')) 114+ with pytest.raises(ValueError): 115+ inputs.natural('foo') 116 117 def test_positive(self): 118 assert 1 == inputs.positive(1) 119 assert 10000 == inputs.positive(10000) 120 121 def test_positive_zero(self): 122- assert_raises(ValueError, lambda: inputs.positive(0)) 123+ with pytest.raises(ValueError): 124+ inputs.positive(0) 125 126 def test_positive_negative_input(self): 127- assert_raises(ValueError, lambda: inputs.positive(-1)) 128+ with pytest.raises(ValueError): 129+ inputs.positive(-1) 130 131 def test_int_range_good(self): 132 int_range = inputs.int_range(1, 5) 133@@ -231,11 +241,13 @@ class TypesTestCase(unittest.TestCase): 134 135 def test_int_range_low(self): 136 int_range = inputs.int_range(0, 5) 137- assert_raises(ValueError, lambda: int_range(-1)) 138+ with pytest.raises(ValueError): 139+ int_range(-1) 140 141 def test_int_range_high(self): 142 int_range = inputs.int_range(0, 5) 143- assert_raises(ValueError, lambda: int_range(6)) 144+ with pytest.raises(ValueError): 145+ int_range(6) 146 147 148 def test_isointerval(): 149@@ -389,7 +401,7 @@ def test_isointerval(): 150 ] 151 152 for value, expected in intervals: 153- yield assert_equal, inputs.iso8601interval(value), expected 154+ assert inputs.iso8601interval(value) == expected 155 156 157 def test_invalid_isointerval_error(): 158@@ -413,12 +425,9 @@ def test_bad_isointervals(): 159 ] 160 161 for bad_interval in bad_intervals: 162- yield ( 163- assert_raises, 164- Exception, 165- inputs.iso8601interval, 166- bad_interval, 167- ) 168+ with pytest.raises(Exception): 169+ inputs.iso8601interval(bad_interval) 170+ 171 172 if __name__ == '__main__': 173 unittest.main()