Table and Json formatters can write output to a file now.

Signed-off-by: Oleg Plakhotniuk <olegus8@gmail.com>

closes #1412
This commit is contained in:
Oleg Plakhotniuk 2014-06-20 15:31:44 -05:00 committed by Laurent Bachelier
commit 8875fad439
4 changed files with 39 additions and 8 deletions

View file

@ -229,3 +229,20 @@ class PrettyFormatter(IFormatter):
def get_description(self, obj):
return None
def formatter_test_output(Formatter, obj):
"""
Formats an object and returns output as a string.
For test purposes only.
"""
from tempfile import mkstemp
from os import remove
_, name = mkstemp()
fmt = Formatter()
fmt.outfile = name
fmt.format(obj)
fmt.flush()
with open(name) as f:
res = f.read()
remove(name)
return res