test_dicttrim.py 956 B

1234567891011121314151617181920212223242526272829303132333435
  1. # -*- coding: utf-8 -*-
  2. # Import python libs
  3. from __future__ import absolute_import, print_function, unicode_literals
  4. # Import Salt Testing libs
  5. from tests.support.unit import TestCase
  6. # Import Salt libs
  7. import salt.utils.dicttrim as dicttrimmer
  8. import logging
  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)