diff options
author | Ryan Petrello <lists@ryanpetrello.com> | 2012-03-15 13:10:57 -0700 |
---|---|---|
committer | Ryan Petrello <lists@ryanpetrello.com> | 2012-03-15 14:55:49 -0700 |
commit | 34b02a253dec84b13317497c5e8d291ba1a9ef63 (patch) | |
tree | 6f1af1f9a4db85d70fba36084ead33b5ea92a5c6 /pecan/tests | |
parent | 4cf5895ba5ac8bbc8d064a6928fd43322f5a77c8 (diff) | |
download | pecan-34b02a253dec84b13317497c5e8d291ba1a9ef63.tar.gz |
Silencing warnings and stdout writes in our test suite.
Diffstat (limited to 'pecan/tests')
-rw-r--r-- | pecan/tests/test_base.py | 28 | ||||
-rw-r--r-- | pecan/tests/test_rest.py | 29 | ||||
-rw-r--r-- | pecan/tests/test_scaffolds.py | 14 |
3 files changed, 48 insertions, 23 deletions
diff --git a/pecan/tests/test_base.py b/pecan/tests/test_base.py index 3911d36..4eb22e3 100644 --- a/pecan/tests/test_base.py +++ b/pecan/tests/test_base.py @@ -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) diff --git a/pecan/tests/test_rest.py b/pecan/tests/test_rest.py index 86e56ea..4935c00 100644 --- a/pecan/tests/test_rest.py +++ b/pecan/tests/test_rest.py @@ -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): diff --git a/pecan/tests/test_scaffolds.py b/pecan/tests/test_scaffolds.py index aa2e7bb..5698de7 100644 --- a/pecan/tests/test_scaffolds.py +++ b/pecan/tests/test_scaffolds.py @@ -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( |