test_dicttrim.py 955 B

12345678910111213141516171819202122232425262728293031323334
  1. # -*- coding: utf-8 -*-
  2. # Import python libs
  3. from __future__ import absolute_import, print_function, unicode_literals
  4. import logging
  5. # Import Salt libs
  6. import salt.utils.dicttrim as dicttrimmer
  7. # Import Salt Testing libs
  8. from tests.support.unit import TestCase
  9. log = logging.getLogger(__name__)
  10. class DictTrimTestCase(TestCase):
  11. def setUp(self):
  12. self.old_dict = {"a": "b", "c": "x" * 10000}
  13. self.new_dict = {"a": "b", "c": "VALUE_TRIMMED"}
  14. def test_trim_dict(self):
  15. ret = dicttrimmer.trim_dict(self.old_dict, 1000)
  16. self.assertEqual(ret, self.new_dict)
  17. class RecursiveDictTrimTestCase(TestCase):
  18. def setUp(self):
  19. self.old_dict = {"a": {"b": 1, "c": 2, "e": "x" * 10000, "f": "3"}}
  20. self.new_dict = {"a": {"b": 1, "c": 2, "e": "VALUE_TRIMMED", "f": "3"}}
  21. def test_trim_dict(self):
  22. ret = dicttrimmer.trim_dict(self.old_dict, 1000)
  23. self.assertEqual(ret, self.new_dict)