diff options
author | Matěj Cepl <mcepl@redhat.com> | 2012-02-27 01:29:51 +0100 |
---|---|---|
committer | Matěj Cepl <mcepl@redhat.com> | 2012-02-27 01:29:51 +0100 |
commit | a9adb2cae3d62d95a1fdc57d7137dca5e5b9ada9 (patch) | |
tree | 276d08dae23004b2ac245dd6613f105a330ab4e6 /test/test_output.py | |
parent | d44a43f33fa88821b32ab4c505f4cb1b77c15adc (diff) | |
download | yamlish-a9adb2cae3d62d95a1fdc57d7137dca5e5b9ada9.tar.gz |
Reorganization of writer interface.
Also:
* changed license to MIT/X11
* cleanup of some PyLint warnings (mostly missing docstrings)
* make _YamlishLoader a little bit cleaner (don't copy whole SafeLoader
__init__, just subclass it cleanly).
Diffstat (limited to 'test/test_output.py')
-rw-r--r-- | test/test_output.py | 46 |
1 files changed, 38 insertions, 8 deletions
diff --git a/test/test_output.py b/test/test_output.py index ea8d841..cebd66d 100644 --- a/test/test_output.py +++ b/test/test_output.py @@ -1,9 +1,14 @@ # -*- coding: utf-8 -*- +""" +Test general output functionality. + +Without much stress on the format itself. +""" from __future__ import absolute_import, print_function, unicode_literals +from StringIO import StringIO import re import unittest import yamlish -import yaml OUT = [ "---", @@ -89,15 +94,40 @@ destination = [ ] class TestOuptut(unittest.TestCase): - def test_output(self): - for dest in destination: - name = dest['name'] + def setUp(self): + """ + Transform expected list into string which we actually use. + """ + self._expected = "" + for line in OUT: + self._expected += "%s\n" % line + + + def test_file_output(self): + """ + Test output to a file. + """ + outf = StringIO() + yamlish.dump(IN, outf) + outf.seek(0) + got = outf.read() + outf.close() + self.assertEqual(got, self._expected, """Result matches + expected = %s - yaml.dump(IN, dest) - got = dest['normalise']() + observed = %s + """ % (self._expected, got)) - self.assertEqual(got, OUT, """%s: Result matches + def test_string_output(self): + """ + Test output to a string. + """ + got = yamlish.dumps(IN) + self.assertEqual(got, self._expected, """Result matches expected = %s observed = %s - """ % (name, OUT, got)) + """ % (self._expected, got)) + +if __name__ == "__main__": + unittest.main() |