test_debug.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. """
  2. Module with tests for debug
  3. """
  4. #-----------------------------------------------------------------------------
  5. # Copyright (c) 2013, the IPython Development Team.
  6. #
  7. # Distributed under the terms of the Modified BSD License.
  8. #
  9. # The full license is in the file COPYING.txt, distributed with this software.
  10. #-----------------------------------------------------------------------------
  11. #-----------------------------------------------------------------------------
  12. # Imports
  13. #-----------------------------------------------------------------------------
  14. import sys
  15. from ...tests.base import TestsBase
  16. from ..debug import DebugWriter
  17. from ipython_genutils.py3compat import PY3
  18. if PY3:
  19. from io import StringIO
  20. else:
  21. from StringIO import StringIO
  22. #-----------------------------------------------------------------------------
  23. # Class
  24. #-----------------------------------------------------------------------------
  25. class TestDebug(TestsBase):
  26. """Contains test functions for debug.py"""
  27. def test_output(self):
  28. """Test debug writer output."""
  29. # Capture the stdout. Remember original.
  30. stdout = sys.stdout
  31. stream = StringIO()
  32. sys.stdout = stream
  33. # Create stdout writer, get output
  34. writer = DebugWriter()
  35. writer.write('aaa', {'outputs': {'bbb': 'ccc'}})
  36. output = stream.getvalue()
  37. # Check output. Make sure resources dictionary is dumped, but nothing
  38. # else.
  39. assert 'aaa' not in output
  40. assert 'bbb' in output
  41. assert 'ccc' in output
  42. # Revert stdout
  43. sys.stdout = stdout