File: test_stdout.py

package info (click to toggle)
nbconvert 7.17.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,056 kB
  • sloc: python: 8,449; makefile: 199; javascript: 2
file content (46 lines) | stat: -rw-r--r-- 1,380 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
"""
Module with tests for stdout
"""

# -----------------------------------------------------------------------------
# Copyright (c) 2013, the IPython Development Team.
#
# Distributed under the terms of the Modified BSD License.
#
# The full license is in the file COPYING.txt, distributed with this software.
# -----------------------------------------------------------------------------

# -----------------------------------------------------------------------------
# Imports
# -----------------------------------------------------------------------------

import sys
from io import StringIO

from nbconvert.writers.stdout import StdoutWriter
from tests.base import TestsBase

# -----------------------------------------------------------------------------
# Class
# -----------------------------------------------------------------------------


class TestStdout(TestsBase):
    """Contains test functions for stdout.py"""

    def test_output(self):
        """Test stdout writer output."""

        # Capture the stdout.  Remember original.
        stdout = sys.stdout
        stream = StringIO()
        sys.stdout = stream

        # Create stdout writer, test output
        writer = StdoutWriter()
        writer.write("ax", {"b": "c"})
        output = stream.getvalue()
        self.fuzzy_compare(output, "ax")

        # Revert stdout
        sys.stdout = stdout