From 0604a3a5fd1a64098cbdaf44bbb76b805c5233c0 Mon Sep 17 00:00:00 2001 From: Marc Abramowitz Date: Tue, 8 Mar 2016 12:13:35 -0800 Subject: Switch from nose to pytest --- tests/test_cgiapp.py | 6 ++++-- tests/test_config.py | 10 ++++++---- tests/test_exceptions/test_httpexceptions.py | 10 ++++++---- tests/test_multidict.py | 8 ++++---- tests/test_registry.py | 5 +++-- tests/test_wsgilib.py | 29 +++++++++------------------- 6 files changed, 32 insertions(+), 36 deletions(-) (limited to 'tests') diff --git a/tests/test_cgiapp.py b/tests/test_cgiapp.py index 900e83e..bfa04d5 100644 --- a/tests/test_cgiapp.py +++ b/tests/test_cgiapp.py @@ -1,6 +1,8 @@ import os import sys -from nose.tools import assert_raises + +import pytest + from paste.cgiapp import CGIApplication, CGIError from paste.fixture import * @@ -48,7 +50,7 @@ if sys.platform != 'win32' and not sys.platform.startswith('java'): def test_error(): app = TestApp(CGIApplication({}, script='error.cgi', path=[data_dir])) - assert_raises(CGIError, app.get, '', status=500) + pytest.raises(CGIError, app.get, '', status=500) def test_stderr(): app = TestApp(CGIApplication({}, script='stderr.cgi', path=[data_dir])) diff --git a/tests/test_config.py b/tests/test_config.py index 8119157..bc3dcf0 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -1,9 +1,11 @@ # (c) 2007 Philip Jenvey; written for Paste (http://pythonpaste.org) # Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php -from nose.tools import assert_raises + +import pytest +import six + from paste.config import CONFIG, ConfigMiddleware from paste.fixture import TestApp -import six test_key = 'test key' @@ -76,8 +78,8 @@ def test_process_config(request_app=test_request_config): assert CONFIG['process_var'] == 'foo' CONFIG.pop_process_config() - assert_raises(AttributeError, lambda: 'process_var' not in CONFIG) - assert_raises(IndexError, CONFIG.pop_process_config) + pytest.raises(AttributeError, lambda: 'process_var' not in CONFIG) + pytest.raises(IndexError, CONFIG.pop_process_config) finally: reset_config() diff --git a/tests/test_exceptions/test_httpexceptions.py b/tests/test_exceptions/test_httpexceptions.py index 24e00dd..708de0e 100644 --- a/tests/test_exceptions/test_httpexceptions.py +++ b/tests/test_exceptions/test_httpexceptions.py @@ -6,16 +6,18 @@ WSGI Exception Middleware Regression Test Suite """ -from nose.tools import assert_raises + +import pytest +import six + from paste.httpexceptions import * from paste.response import header_value -import six def test_HTTPMove(): """ make sure that location is a mandatory attribute of Redirects """ - assert_raises(AssertionError, HTTPFound) - assert_raises(AssertionError, HTTPTemporaryRedirect, + pytest.raises(AssertionError, HTTPFound) + pytest.raises(AssertionError, HTTPTemporaryRedirect, headers=[('l0cation','/bing')]) assert isinstance(HTTPMovedPermanently("This is a message", headers=[('Location','/bing')]) diff --git a/tests/test_multidict.py b/tests/test_multidict.py index 50a746f..a33c13b 100644 --- a/tests/test_multidict.py +++ b/tests/test_multidict.py @@ -2,11 +2,11 @@ # (c) 2007 Ian Bicking and Philip Jenvey; written for Paste (http://pythonpaste.org) # Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php import cgi + +import pytest import six from six.moves import StringIO -from nose.tools import assert_raises - from paste.util.multidict import MultiDict, UnicodeMultiDict def test_dict(): @@ -21,7 +21,7 @@ def test_dict(): assert d.items() == [('a', 1), ('c', 3), ('b', 4)] d.add('b', 5) - assert_raises(KeyError, d.getone, "b") + pytest.raises(KeyError, d.getone, "b") assert d.getall('b') == [4, 5] assert d.items() == [('a', 1), ('c', 3), ('b', 4), ('b', 5)] @@ -94,7 +94,7 @@ def _test_unicode_dict(decode_param_names=False): list(map(assert_unicode_item, d.items())) d.add(k('b'), b'5 test') - assert_raises(KeyError, d.getone, k("b")) + pytest.raises(KeyError, d.getone, k("b")) assert d.getall(k('b')) == [u'4 test', u'5 test'] map(assert_unicode, d.getall('b')) assert d.items() == [(k('a'), u'a test'), (k('c'), u'3 test'), (k('b'), u'4 test'), diff --git a/tests/test_registry.py b/tests/test_registry.py index 23cd9b6..e0794dc 100644 --- a/tests/test_registry.py +++ b/tests/test_registry.py @@ -1,7 +1,8 @@ # (c) 2005 Ben Bangert # This module is part of the Python Paste Project and is released under # the MIT License: http://www.opensource.org/licenses/mit-license.php -from nose.tools import assert_raises + +import pytest from paste.fixture import * from paste.registry import * @@ -122,7 +123,7 @@ def test_solo_registry(): def test_registry_no_object_error(): app = TestApp(simpleapp_withregistry) - assert_raises(TypeError, app.get, '/') + pytest.raises(TypeError, app.get, '/') def test_with_default_object(): app = TestApp(simpleapp_withregistry_default) diff --git a/tests/test_wsgilib.py b/tests/test_wsgilib.py index 72573cf..e6514ef 100644 --- a/tests/test_wsgilib.py +++ b/tests/test_wsgilib.py @@ -1,3 +1,5 @@ +import pytest + from paste.wsgilib import add_close @@ -18,35 +20,22 @@ def close_func(): close_func_called = True -def test_add_close_bytes(): - global close_func_called - - close_func_called = False - lst = [] - app_iterable = app_iterable_func_bytes() - - obj = add_close(app_iterable, close_func) - for x in obj: - lst.append(x) - obj.close() - - assert lst == [b'a', b'b', b'c'] - assert close_func_called - assert obj._closed - - -def test_add_close_unicode(): +@pytest.mark.parametrize("app_iterable_func,expected", [ + (app_iterable_func_bytes, [b'a', b'b', b'c']), + (app_iterable_func_unicode, ['a', 'b', 'c']), +]) +def test_add_close(app_iterable_func, expected): global close_func_called close_func_called = False lst = [] - app_iterable = app_iterable_func_unicode() + app_iterable = app_iterable_func() obj = add_close(app_iterable, close_func) for x in obj: lst.append(x) obj.close() - assert lst == ['a', 'b', 'c'] + assert lst == expected assert close_func_called assert obj._closed -- cgit v1.2.1