From a535040bfac30766cb475054dac5a6359073e48b Mon Sep 17 00:00:00 2001 From: Claude Paroz Date: Mon, 28 May 2012 11:55:38 +0200 Subject: [PATCH] Used call_command stdout parameter to capture output in staticfiles tests. --- .../staticfiles_tests/tests.py | 30 +++++++------------ 1 file changed, 11 insertions(+), 19 deletions(-) diff --git a/tests/regressiontests/staticfiles_tests/tests.py b/tests/regressiontests/staticfiles_tests/tests.py index 6565a4d786..3711d92448 100644 --- a/tests/regressiontests/staticfiles_tests/tests.py +++ b/tests/regressiontests/staticfiles_tests/tests.py @@ -6,7 +6,7 @@ import posixpath import shutil import sys import tempfile -from StringIO import StringIO +from io import BytesIO from django.template import loader, Context from django.conf import settings @@ -187,30 +187,22 @@ class TestFindStatic(CollectionTestCase, TestDefaults): Test ``findstatic`` management command. """ def _get_file(self, filepath): - _stdout = sys.stdout - sys.stdout = StringIO() - try: - call_command('findstatic', filepath, all=False, verbosity='0') - sys.stdout.seek(0) - lines = [l.strip() for l in sys.stdout.readlines()] - contents = codecs.open( - smart_unicode(lines[1].strip()), "r", "utf-8").read() - finally: - sys.stdout = _stdout + out = BytesIO() + call_command('findstatic', filepath, all=False, verbosity=0, stdout=out) + out.seek(0) + lines = [l.strip() for l in out.readlines()] + contents = codecs.open( + smart_unicode(lines[1].strip()), "r", "utf-8").read() return contents def test_all_files(self): """ Test that findstatic returns all candidate files if run without --first. """ - _stdout = sys.stdout - sys.stdout = StringIO() - try: - call_command('findstatic', 'test/file.txt', verbosity='0') - sys.stdout.seek(0) - lines = [l.strip() for l in sys.stdout.readlines()] - finally: - sys.stdout = _stdout + out = BytesIO() + call_command('findstatic', 'test/file.txt', verbosity=0, stdout=out) + out.seek(0) + lines = [l.strip() for l in out.readlines()] self.assertEqual(len(lines), 3) # three because there is also the "Found here" line self.assertIn('project', lines[1]) self.assertIn('apps', lines[2])