Silencing warnings and stdout writes in our test suite.
This commit is contained in:
@@ -31,10 +31,10 @@ class PecanScaffold(object):
|
||||
def normalize_pkg_name(self, dest):
|
||||
return _bad_chars_re.sub('', dest.lower())
|
||||
|
||||
def copy_to(self, dest):
|
||||
def copy_to(self, dest, **kw):
|
||||
output_dir = self.normalize_output_dir(dest)
|
||||
pkg_name = self.normalize_pkg_name(dest)
|
||||
copy_dir(self._scaffold_dir, output_dir, {'package': pkg_name})
|
||||
copy_dir(self._scaffold_dir, output_dir, {'package': pkg_name}, **kw)
|
||||
|
||||
|
||||
class BaseScaffold(PecanScaffold):
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
import sys
|
||||
import warnings
|
||||
from paste.translogger import TransLogger
|
||||
from webtest import TestApp
|
||||
|
||||
if sys.version_info < (2, 7):
|
||||
import unittest2 as unittest
|
||||
else:
|
||||
import unittest
|
||||
import unittest # noqa
|
||||
|
||||
from pecan import (
|
||||
Pecan, expose, request, response, redirect, abort, make_app,
|
||||
@@ -172,9 +173,11 @@ class TestLookups(unittest.TestCase):
|
||||
def _lookup(self, someID):
|
||||
return 'Bad arg spec'
|
||||
|
||||
app = TestApp(Pecan(RootController()))
|
||||
r = app.get('/foo/bar', expect_errors=True)
|
||||
assert r.status_int == 404
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter("ignore")
|
||||
app = TestApp(Pecan(RootController()))
|
||||
r = app.get('/foo/bar', expect_errors=True)
|
||||
assert r.status_int == 404
|
||||
|
||||
|
||||
class TestControllerArguments(unittest.TestCase):
|
||||
@@ -409,7 +412,10 @@ class TestControllerArguments(unittest.TestCase):
|
||||
assert r.body == 'optional: 7'
|
||||
|
||||
def test_optional_arg_with_multiple_url_encoded_dictionary_kwargs(self):
|
||||
r = self.app_.post('/optional', {'id': 'Some%20Number', 'dummy': 'dummy'})
|
||||
r = self.app_.post('/optional', {
|
||||
'id': 'Some%20Number',
|
||||
'dummy': 'dummy'
|
||||
})
|
||||
assert r.status_int == 200
|
||||
assert r.body == 'optional: Some%20Number'
|
||||
|
||||
@@ -572,7 +578,9 @@ class TestControllerArguments(unittest.TestCase):
|
||||
assert r.body == 'variable_kwargs: dummy=dummy, id=2'
|
||||
|
||||
def test_multiple_variable_kwargs_with_explicit_encoded_kwargs(self):
|
||||
r = self.app_.get('/variable_kwargs?id=Two%21&dummy=This%20is%20a%20test')
|
||||
r = self.app_.get(
|
||||
'/variable_kwargs?id=Two%21&dummy=This%20is%20a%20test'
|
||||
)
|
||||
assert r.status_int == 200
|
||||
assert r.body == 'variable_kwargs: dummy=This is a test, id=Two!'
|
||||
|
||||
@@ -895,8 +903,10 @@ class TestFileTypeExtensions(unittest.TestCase):
|
||||
assert r.status_int == 200
|
||||
assert r.body == '/'
|
||||
|
||||
r = app.get('/index.txt', expect_errors=True)
|
||||
assert r.status_int == 404
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter("ignore")
|
||||
r = app.get('/index.txt', expect_errors=True)
|
||||
assert r.status_int == 404
|
||||
|
||||
|
||||
class TestCanonicalRouting(unittest.TestCase):
|
||||
@@ -964,7 +974,7 @@ class TestCanonicalRouting(unittest.TestCase):
|
||||
|
||||
def test_posts_fail(self):
|
||||
try:
|
||||
r = self.app_.post('/sub', dict(foo=1))
|
||||
self.app_.post('/sub', dict(foo=1))
|
||||
raise Exception("Post should fail")
|
||||
except Exception, e:
|
||||
assert isinstance(e, RuntimeError)
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
from pecan import abort, expose, make_app, request, response
|
||||
from pecan import abort, expose, make_app, response
|
||||
from pecan.rest import RestController
|
||||
from unittest import TestCase
|
||||
from webtest import TestApp
|
||||
import warnings
|
||||
try:
|
||||
from simplejson import dumps, loads
|
||||
except:
|
||||
@@ -208,21 +209,27 @@ class TestRestController(TestCase):
|
||||
assert r.body == 'OPTIONS'
|
||||
|
||||
# test the "other" custom action
|
||||
r = app.request('/things/other', method='MISC', status=405)
|
||||
assert r.status_int == 405
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter("ignore")
|
||||
r = app.request('/things/other', method='MISC', status=405)
|
||||
assert r.status_int == 405
|
||||
|
||||
# test the "other" custom action with the _method parameter
|
||||
r = app.post('/things/other', {'_method': 'MISC'}, status=405)
|
||||
assert r.status_int == 405
|
||||
|
||||
# test the "others" custom action
|
||||
r = app.request('/things/others/', method='MISC')
|
||||
assert r.status_int == 200
|
||||
assert r.body == 'OTHERS'
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter("ignore")
|
||||
r = app.request('/things/others/', method='MISC')
|
||||
assert r.status_int == 200
|
||||
assert r.body == 'OTHERS'
|
||||
|
||||
# test the "others" custom action missing trailing slash
|
||||
r = app.request('/things/others', method='MISC', status=302)
|
||||
assert r.status_int == 302
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter("ignore")
|
||||
r = app.request('/things/others', method='MISC', status=302)
|
||||
assert r.status_int == 302
|
||||
|
||||
# test the "others" custom action with the _method parameter
|
||||
r = app.get('/things/others/?_method=MISC')
|
||||
@@ -609,8 +616,10 @@ class TestRestController(TestCase):
|
||||
assert r.status_int == 404
|
||||
|
||||
# test "RESET" custom action
|
||||
r = app.request('/things', method='RESET', status=404)
|
||||
assert r.status_int == 404
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter("ignore")
|
||||
r = app.request('/things', method='RESET', status=404)
|
||||
assert r.status_int == 404
|
||||
|
||||
def test_custom_delete(self):
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ import pkg_resources
|
||||
import httplib
|
||||
import urllib2
|
||||
import time
|
||||
from cStringIO import StringIO
|
||||
import pecan
|
||||
|
||||
if sys.version_info < (2, 7):
|
||||
@@ -44,9 +45,13 @@ class TestScaffoldUtils(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.scaffold_destination = tempfile.mkdtemp()
|
||||
self.out = sys.stdout
|
||||
|
||||
sys.stdout = StringIO()
|
||||
|
||||
def tearDown(self):
|
||||
shutil.rmtree(self.scaffold_destination)
|
||||
sys.stdout = self.out
|
||||
|
||||
def test_copy_dir(self):
|
||||
from pecan.scaffolds import PecanScaffold
|
||||
@@ -59,7 +64,7 @@ class TestScaffoldUtils(unittest.TestCase):
|
||||
SimpleScaffold().copy_to(os.path.join(
|
||||
self.scaffold_destination,
|
||||
'someapp'
|
||||
))
|
||||
), out_=StringIO())
|
||||
|
||||
assert os.path.isfile(os.path.join(
|
||||
self.scaffold_destination, 'someapp', 'foo'
|
||||
@@ -76,7 +81,6 @@ class TestScaffoldUtils(unittest.TestCase):
|
||||
|
||||
def test_destination_directory_levels_deep(self):
|
||||
from pecan.scaffolds import copy_dir
|
||||
from cStringIO import StringIO
|
||||
f = StringIO()
|
||||
copy_dir(('pecan', os.path.join(
|
||||
'tests', 'scaffold_fixtures', 'simple'
|
||||
@@ -120,7 +124,8 @@ class TestScaffoldUtils(unittest.TestCase):
|
||||
os.path.join(
|
||||
self.scaffold_destination, 'someapp'
|
||||
),
|
||||
{'package': 'thingy'}
|
||||
{'package': 'thingy'},
|
||||
out_=StringIO()
|
||||
)
|
||||
|
||||
assert os.path.isfile(os.path.join(
|
||||
@@ -144,7 +149,8 @@ class TestScaffoldUtils(unittest.TestCase):
|
||||
os.path.join(
|
||||
self.scaffold_destination, 'someapp'
|
||||
),
|
||||
{'package': 'thingy'}
|
||||
{'package': 'thingy'},
|
||||
out_=StringIO()
|
||||
)
|
||||
|
||||
assert os.path.isfile(os.path.join(
|
||||
|
||||
Reference in New Issue
Block a user