From 6bde592070bbb9f77dc02c02a0894fbf2d3e0741 Mon Sep 17 00:00:00 2001 From: msiebeneicher Date: Fri, 7 Oct 2016 16:52:53 +0200 Subject: [PATCH] providing yaml output unit tests --- tests/unit/output/yaml_out_test.py | 55 ++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 tests/unit/output/yaml_out_test.py diff --git a/tests/unit/output/yaml_out_test.py b/tests/unit/output/yaml_out_test.py new file mode 100644 index 0000000000..b8ea055961 --- /dev/null +++ b/tests/unit/output/yaml_out_test.py @@ -0,0 +1,55 @@ +# -*- coding: utf-8 -*- +''' +unittests for yaml outputter +''' + +# Import Python Libs +from __future__ import absolute_import +from StringIO import StringIO +import sys + +# Import Salt Testing Libs +from salttesting import TestCase +from salttesting.helpers import ensure_in_syspath + +ensure_in_syspath('../../') + +# Import Salt Libs +from salt.output import yaml_out as yaml +from salt.log.setup import set_console_handler_stream + +class YamlTestCase(TestCase): + ''' + Test cases for salt.output.json_out + ''' + def setUp(self): + # reset to default behavior + set_console_handler_stream(sys.stderr) + yaml.__opts__ = {} + self.data = {'test': 'two', 'example': 'one'} + + def test_default_output(self): + ret = yaml.output(self.data) + expect = 'example: one\ntest: two\n' + self.assertEqual(expect, ret) + + def test_negative_int_output(self): + yaml.__opts__['output_indent'] = -1 + ret = yaml.output(self.data) + expect = '{example: one, test: two}\n' + self.assertEqual(expect, ret) + + def test_default_outout_with_log_entries(self): + # mock a console log stream + test_stream = StringIO('line1\nline2') + set_console_handler_stream(test_stream) + + yaml.__opts__['output_indent'] = -1 + ret = yaml.output(self.data) + expect = '{example: one, test: two}\n' + self.assertEqual(expect, ret) + + +if __name__ == '__main__': + from integration import run_tests + run_tests(YamlTestCase, needs_daemon=False)