# -*- coding: utf-8 -*-
"""
Test general output functionality.

Without much stress on the format itself.
"""
import logging
import tempfile
import unittest2 as unittest
import yaml
logging.basicConfig(level=logging.DEBUG)

OUT = """---
bill-to:
  address:
    lines: "458 Walkman Dr.\\nSuite #292\\n"
comments: Late afternoon is best. Backup contact is Nancy Billsmer @ 338-4338\n
...
"""

IN = {
  'bill-to': {
    'address': {
      'lines': "458 Walkman Dr.\nSuite #292\n",
    },
  },
  'comments': "Late afternoon is best. Backup contact is Nancy Billsmer @ 338-4338\n"
}

class TestOuptut(unittest.TestCase):
    def setUp(self):
        """
        Transform expected list into string which we actually use.
        """
        self._expected = yaml.safe_load(OUT)


    def test_file_output(self):
        """
        Test output to a file.
        """
        outf = tempfile.TemporaryFile()
        yaml.safe_dump(IN, outf)
        outf.seek(0)
        got_str = outf.read()
        outf.close()
        got = yaml.safe_load(got_str)
        self.assertEqual(self._expected, got, "Result matches")

if __name__ == "__main__":
    unittest.main()
