1
0

test_table_out.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. # -*- coding: utf-8 -*-
  2. '''
  3. unittests for table outputter
  4. '''
  5. # Import Python Libs
  6. from __future__ import absolute_import, print_function, unicode_literals
  7. # Import Salt Testing Libs
  8. from tests.support.mixins import LoaderModuleMockMixin
  9. from tests.support.unit import TestCase
  10. # Import Salt Libs
  11. import salt.output.table_out as table_out
  12. import salt.utils.stringutils
  13. class TableTestCase(TestCase, LoaderModuleMockMixin):
  14. '''
  15. Test cases for salt.output.table_out
  16. '''
  17. def setup_loader_modules(self):
  18. return {table_out: {}}
  19. # The test data should include unicode chars, and in Python 2 there should
  20. # be an example both of an encoded str type and an actual unicode type.
  21. # Since unicode_literals is imported, we will achieve the former using
  22. # salt.utils.stringutils.to_str and the latter by simply using a string
  23. # literal.
  24. data = [
  25. {'Food': salt.utils.stringutils.to_str('яйца, бекон, колбаса и спам'),
  26. 'Price': 5.99},
  27. {'Food': 'спам, спам, спам, яйца и спам',
  28. 'Price': 3.99},
  29. ]
  30. def test_output(self):
  31. ret = table_out.output(self.data)
  32. self.assertEqual(
  33. ret,
  34. (' -----------------------------------------\n'
  35. ' | Food | Price |\n'
  36. ' -----------------------------------------\n'
  37. ' | яйца, бекон, колбаса и спам | 5.99 |\n'
  38. ' -----------------------------------------\n'
  39. ' | спам, спам, спам, яйца и спам | 3.99 |\n'
  40. ' -----------------------------------------')
  41. )