test_stdout.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. # coding: utf-8
  2. """
  3. Module with tests for stdout
  4. """
  5. #-----------------------------------------------------------------------------
  6. # Copyright (c) 2013, the IPython Development Team.
  7. #
  8. # Distributed under the terms of the Modified BSD License.
  9. #
  10. # The full license is in the file COPYING.txt, distributed with this software.
  11. #-----------------------------------------------------------------------------
  12. #-----------------------------------------------------------------------------
  13. # Imports
  14. #-----------------------------------------------------------------------------
  15. import sys
  16. from ...tests.base import TestsBase
  17. from ..stdout import StdoutWriter
  18. from ipython_genutils.py3compat import PY3
  19. if PY3:
  20. from io import StringIO
  21. else:
  22. from StringIO import StringIO
  23. #-----------------------------------------------------------------------------
  24. # Class
  25. #-----------------------------------------------------------------------------
  26. class TestStdout(TestsBase):
  27. """Contains test functions for stdout.py"""
  28. def test_output(self):
  29. """Test stdout writer output."""
  30. # Capture the stdout. Remember original.
  31. stdout = sys.stdout
  32. stream = StringIO()
  33. sys.stdout = stream
  34. # Create stdout writer, test output
  35. writer = StdoutWriter()
  36. writer.write(u'a×', {'b': 'c'})
  37. output = stream.getvalue()
  38. if not PY3:
  39. output = output.decode('utf-8')
  40. self.fuzzy_compare(output, u'a×')
  41. # Revert stdout
  42. sys.stdout = stdout