1
0

test_table_out.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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 Libs
  8. import salt.output.table_out as table_out
  9. import salt.utils.stringutils
  10. # Import Salt Testing Libs
  11. from tests.support.mixins import LoaderModuleMockMixin
  12. from tests.support.unit import TestCase
  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. {
  26. "Food": salt.utils.stringutils.to_str("яйца, бекон, колбаса и спам"),
  27. "Price": 5.99,
  28. },
  29. {"Food": "спам, спам, спам, яйца и спам", "Price": 3.99},
  30. ]
  31. def test_output(self):
  32. ret = table_out.output(self.data)
  33. self.assertEqual(
  34. ret,
  35. (
  36. " -----------------------------------------\n"
  37. " | Food | Price |\n"
  38. " -----------------------------------------\n"
  39. " | яйца, бекон, колбаса и спам | 5.99 |\n"
  40. " -----------------------------------------\n"
  41. " | спам, спам, спам, яйца и спам | 3.99 |\n"
  42. " -----------------------------------------"
  43. ),
  44. )