Ticket #236: failing_test.py

File failing_test.py, 1.2 KB (added by Matěj Cepl <mcepl@…>, 2 years ago)

simple test case

Line 
1# -*- coding: utf-8 -*-
2"""
3Test general output functionality.
4
5Without much stress on the format itself.
6"""
7import logging
8import tempfile
9import unittest
10import yaml
11logging.basicConfig(level=logging.DEBUG)
12
13OUT = """---
14bill-to:
15  address:
16    lines: "458 Walkman Dr.\nSuite #292\n"
17comments: Late afternoon is best. Backup contact is Nancy Billsmer @ 338-4338\n
18...
19"""
20
21IN = {
22  'bill-to': {
23    'address': {
24      'lines': "458 Walkman Dr.\nSuite #292\n",
25    },
26  },
27  'comments': "Late afternoon is best. Backup contact is Nancy Billsmer @ 338-4338\n"
28}
29
30class TestOuptut(unittest.TestCase):
31    def setUp(self):
32        """
33        Transform expected list into string which we actually use.
34        """
35        self._expected = yaml.safe_load(OUT)
36
37
38    def test_file_output(self):
39        """
40        Test output to a file.
41        """
42        outf = tempfile.TemporaryFile()
43        yaml.safe_dump(IN, outf)
44        outf.seek(0)
45        got_str = outf.read()
46        outf.close()
47        got = yaml.safe_load(got_str)
48        self.assertEqual(self._expected, got, """Result matches
49              expected = %s
50
51              observed = %s
52              """ % (self._expected, got))
53
54if __name__ == "__main__":
55    unittest.main()