summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2015-04-22 00:21:41 +0200
committerVictor Stinner <victor.stinner@gmail.com>2015-04-22 00:21:41 +0200
commit1dd31fde1a4edc7fd2f66a738125231ba5c176ae (patch)
tree9fb10e56d28570af5cb97ee6cc3cc1fb2ad2058b /tests
parent8d28bef1dc52d1488d5a3cfded02d19aa2fe11fe (diff)
downloadpaste-1dd31fde1a4edc7fd2f66a738125231ba5c176ae.tar.gz
Fix test_config on Python 3
Reset config after each test
Diffstat (limited to 'tests')
-rw-r--r--tests/test_config.py74
1 files changed, 48 insertions, 26 deletions
diff --git a/tests/test_config.py b/tests/test_config.py
index a23238e..8119157 100644
--- a/tests/test_config.py
+++ b/tests/test_config.py
@@ -3,13 +3,24 @@
from nose.tools import assert_raises
from paste.config import CONFIG, ConfigMiddleware
from paste.fixture import TestApp
+import six
test_key = 'test key'
+def reset_config():
+ while True:
+ try:
+ CONFIG._pop_object()
+ except IndexError:
+ break
+
def app_with_config(environ, start_response):
start_response('200 OK', [('Content-type','text/plain')])
- return ['Variable is: %s\n' % CONFIG[test_key],
+ lines = ['Variable is: %s\n' % CONFIG[test_key],
'Variable is (in environ): %s' % environ['paste.config'][test_key]]
+ if six.PY3:
+ lines = [line.encode('utf8') for line in lines]
+ return lines
class NestingAppWithConfig(object):
def __init__(self, app):
@@ -21,43 +32,54 @@ class NestingAppWithConfig(object):
supplement = ['Nesting variable is: %s' % CONFIG[test_key],
'Nesting variable is (in environ): %s' % \
environ['paste.config'][test_key]]
+ if six.PY3:
+ supplement = [line.encode('utf8') for line in supplement]
response.extend(supplement)
return response
def test_request_config():
- config = {test_key: 'test value'}
- app = ConfigMiddleware(app_with_config, config)
- res = TestApp(app).get('/')
- assert 'Variable is: test value' in res
- assert 'Variable is (in environ): test value' in res
+ try:
+ config = {test_key: 'test value'}
+ app = ConfigMiddleware(app_with_config, config)
+ res = TestApp(app).get('/')
+ assert 'Variable is: test value' in res
+ assert 'Variable is (in environ): test value' in res
+ finally:
+ reset_config()
def test_request_config_multi():
- config = {test_key: 'test value'}
- app = ConfigMiddleware(app_with_config, config)
- config = {test_key: 'nesting value'}
- app = ConfigMiddleware(NestingAppWithConfig(app), config)
- res = TestApp(app).get('/')
- assert 'Variable is: test value' in res
- assert 'Variable is (in environ): test value' in res
- assert 'Nesting variable is: nesting value' in res
- print(res)
- assert 'Nesting variable is (in environ): nesting value' in res
+ try:
+ config = {test_key: 'test value'}
+ app = ConfigMiddleware(app_with_config, config)
+ config = {test_key: 'nesting value'}
+ app = ConfigMiddleware(NestingAppWithConfig(app), config)
+ res = TestApp(app).get('/')
+ assert 'Variable is: test value' in res
+ assert 'Variable is (in environ): test value' in res
+ assert 'Nesting variable is: nesting value' in res
+ print(res)
+ assert 'Nesting variable is (in environ): nesting value' in res
+ finally:
+ reset_config()
def test_process_config(request_app=test_request_config):
- process_config = {test_key: 'bar', 'process_var': 'foo'}
- CONFIG.push_process_config(process_config)
+ try:
+ process_config = {test_key: 'bar', 'process_var': 'foo'}
+ CONFIG.push_process_config(process_config)
- assert CONFIG[test_key] == 'bar'
- assert CONFIG['process_var'] == 'foo'
+ assert CONFIG[test_key] == 'bar'
+ assert CONFIG['process_var'] == 'foo'
- request_app()
+ request_app()
- assert CONFIG[test_key] == 'bar'
- assert CONFIG['process_var'] == 'foo'
- CONFIG.pop_process_config()
+ assert CONFIG[test_key] == 'bar'
+ 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)
+ assert_raises(AttributeError, lambda: 'process_var' not in CONFIG)
+ assert_raises(IndexError, CONFIG.pop_process_config)
+ finally:
+ reset_config()
def test_process_config_multi():
test_process_config(test_request_config_multi)