Used call_command stdout parameter to capture output in staticfiles tests.
This commit is contained in:
parent
a768b1d94a
commit
a535040bfa
|
@ -6,7 +6,7 @@ import posixpath
|
||||||
import shutil
|
import shutil
|
||||||
import sys
|
import sys
|
||||||
import tempfile
|
import tempfile
|
||||||
from StringIO import StringIO
|
from io import BytesIO
|
||||||
|
|
||||||
from django.template import loader, Context
|
from django.template import loader, Context
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
@ -187,30 +187,22 @@ class TestFindStatic(CollectionTestCase, TestDefaults):
|
||||||
Test ``findstatic`` management command.
|
Test ``findstatic`` management command.
|
||||||
"""
|
"""
|
||||||
def _get_file(self, filepath):
|
def _get_file(self, filepath):
|
||||||
_stdout = sys.stdout
|
out = BytesIO()
|
||||||
sys.stdout = StringIO()
|
call_command('findstatic', filepath, all=False, verbosity=0, stdout=out)
|
||||||
try:
|
out.seek(0)
|
||||||
call_command('findstatic', filepath, all=False, verbosity='0')
|
lines = [l.strip() for l in out.readlines()]
|
||||||
sys.stdout.seek(0)
|
contents = codecs.open(
|
||||||
lines = [l.strip() for l in sys.stdout.readlines()]
|
smart_unicode(lines[1].strip()), "r", "utf-8").read()
|
||||||
contents = codecs.open(
|
|
||||||
smart_unicode(lines[1].strip()), "r", "utf-8").read()
|
|
||||||
finally:
|
|
||||||
sys.stdout = _stdout
|
|
||||||
return contents
|
return contents
|
||||||
|
|
||||||
def test_all_files(self):
|
def test_all_files(self):
|
||||||
"""
|
"""
|
||||||
Test that findstatic returns all candidate files if run without --first.
|
Test that findstatic returns all candidate files if run without --first.
|
||||||
"""
|
"""
|
||||||
_stdout = sys.stdout
|
out = BytesIO()
|
||||||
sys.stdout = StringIO()
|
call_command('findstatic', 'test/file.txt', verbosity=0, stdout=out)
|
||||||
try:
|
out.seek(0)
|
||||||
call_command('findstatic', 'test/file.txt', verbosity='0')
|
lines = [l.strip() for l in out.readlines()]
|
||||||
sys.stdout.seek(0)
|
|
||||||
lines = [l.strip() for l in sys.stdout.readlines()]
|
|
||||||
finally:
|
|
||||||
sys.stdout = _stdout
|
|
||||||
self.assertEqual(len(lines), 3) # three because there is also the "Found <file> here" line
|
self.assertEqual(len(lines), 3) # three because there is also the "Found <file> here" line
|
||||||
self.assertIn('project', lines[1])
|
self.assertIn('project', lines[1])
|
||||||
self.assertIn('apps', lines[2])
|
self.assertIn('apps', lines[2])
|
||||||
|
|
Loading…
Reference in New Issue