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:
parent
36a4b78e67
commit
8875fad439
4 changed files with 39 additions and 8 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue