blob: db4bf4bea840b019f288c9e37a9c9736347605e1 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
# -*- coding: utf-8 -*-
"""
Test general output functionality.
Without much stress on the format itself.
"""
from __future__ import absolute_import, print_function, unicode_literals
import ddt
import yamlish
import yaml
import logging
import tempfile
import unittest
import sys
from pprint import pformat
from test.test_output_data import data
logging.basicConfig(format='%(levelname)s:%(funcName)s:%(message)s',
stream=sys.stdout, level=logging.DEBUG)
log = logging.getLogger('test')
@ddt.ddt
class TestOutput(unittest.TestCase):
@ddt.data(data)
def test_file_output(self, test_data):
"""
Test output to a file.
"""
log.debug('test_data:\n%s', pformat(test_data))
expected = yaml.safe_load(test_data[0])
outf = tempfile.TemporaryFile()
yamlish.dump(test_data[1], outf)
outf.seek(0)
got_str = outf.read()
outf.close()
logging.debug("got_str = %s", got_str)
got = yaml.safe_load(got_str)
self.assertEqual(got, expected, "Result matches")
@ddt.data(data)
def test_string_output(self, test_data):
"""
Test output to a string.
"""
expected = yaml.safe_load(test_data[0])
got_str = yamlish.dumps(test_data[1])
got = yaml.load(got_str)
self.assertEqual(got, expected, "Result matches")
if __name__ == "__main__":
unittest.main()
|