From 700f71dd5fd5e0443aef4631f8d6496f030368c7 Mon Sep 17 00:00:00 2001 From: Erik Johnson Date: Wed, 28 Mar 2018 09:55:35 -0500 Subject: [PATCH] Add test case for serializer_opts --- tests/unit/states/test_file.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tests/unit/states/test_file.py b/tests/unit/states/test_file.py index 6e3b419620..d5226f19ae 100644 --- a/tests/unit/states/test_file.py +++ b/tests/unit/states/test_file.py @@ -21,6 +21,7 @@ from tests.support.unit import skipIf, TestCase from tests.support.mock import ( NO_MOCK, NO_MOCK_REASON, + Mock, MagicMock, call, mock_open, @@ -84,6 +85,20 @@ class TestFileState(TestCase, LoaderModuleMockMixin): filestate.serialize('/tmp', dataset, formatter="python") self.assertEqual(returner.returned, pprint.pformat(dataset) + '\n') + mock_serializer = Mock(return_value='') + with patch.dict(filestate.__serializers__, + {'json.serialize': mock_serializer}): + filestate.serialize( + '/tmp', + dataset, + formatter='json', + serializer_opts=[{'indent': 8}]) + mock_serializer.assert_called_with( + dataset, + indent=8, + separators=(',', ': '), + sort_keys=True) + def test_contents_and_contents_pillar(self): def returner(contents, *args, **kwargs): returner.returned = contents