aboutsummaryrefslogtreecommitdiffstats
path: root/test/test_output.py
diff options
context:
space:
mode:
Diffstat (limited to 'test/test_output.py')
-rw-r--r--test/test_output.py90
1 files changed, 20 insertions, 70 deletions
diff --git a/test/test_output.py b/test/test_output.py
index 3762408..db4bf4b 100644
--- a/test/test_output.py
+++ b/test/test_output.py
@@ -5,100 +5,50 @@ 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
-OUT = """---
-bill-to:
- address:
- city: Royal Oak
- lines: "458 Walkman Dr.\\nSuite #292\\n"
- postal: 48046
- state: MI
- family: Dumars
- given: Chris
-comments: Late afternoon is best. Backup contact is Nancy Billsmer @ 338-4338
-date: 2001-01-23
-invoice: 34843
-product:
- -
- description: Basketball
- price: 450.00
- quantity: 4
- sku: BL394D
- -
- description: Super Hoop
- price: 2392.00
- quantity: 1
- sku: BL4438H
-tax: 251.42
-total: 4443.52
-...
-"""
+from test.test_output_data import data
-IN = {
- 'bill-to': {
- 'given': 'Chris',
- 'address': {
- 'city': 'Royal Oak',
- 'postal': 48046,
- 'lines': "458 Walkman Dr.\nSuite #292\n",
- 'state': 'MI'
- },
- 'family': 'Dumars'
- },
- 'invoice': 34843,
- 'date': '2001-01-23',
- 'tax': 251.42,
- 'product': [
- {
- 'sku': 'BL394D',
- 'quantity': 4,
- 'price': 450.00,
- 'description': 'Basketball'
- },
- {
- 'sku': 'BL4438H',
- 'quantity': 1,
- 'price': 2392.00,
- 'description': 'Super Hoop'
- }
- ],
- 'comments': "Late afternoon is best. Backup contact is Nancy Billsmer @ 338-4338",
- 'total': 4443.52
-}
+logging.basicConfig(format='%(levelname)s:%(funcName)s:%(message)s',
+ stream=sys.stdout, level=logging.DEBUG)
+log = logging.getLogger('test')
-class TestOuptut(unittest.TestCase):
- def setUp(self):
- """
- Transform expected list into string which we actually use.
- """
- self._expected = yaml.safe_load(OUT)
+@ddt.ddt
+class TestOutput(unittest.TestCase):
- def test_file_output(self):
+ @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(IN, outf)
+ 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, self._expected, "Result matches")
+ self.assertEqual(got, expected, "Result matches")
- def test_string_output(self):
+ @ddt.data(data)
+ def test_string_output(self, test_data):
"""
Test output to a string.
"""
- got_str = yamlish.dumps(IN)
+ expected = yaml.safe_load(test_data[0])
+ got_str = yamlish.dumps(test_data[1])
got = yaml.load(got_str)
- self.assertEqual(got, self._expected, "Result matches")
+ self.assertEqual(got, expected, "Result matches")
if __name__ == "__main__":
unittest.main()