Show More
@@ -1,34 +1,34 b'' | |||||
1 | """ |
|
1 | """ | |
2 | Contains Stdout writer |
|
2 | Contains Stdout writer | |
3 | """ |
|
3 | """ | |
4 | #----------------------------------------------------------------------------- |
|
4 | #----------------------------------------------------------------------------- | |
5 | #Copyright (c) 2013, the IPython Development Team. |
|
5 | #Copyright (c) 2013, the IPython Development Team. | |
6 | # |
|
6 | # | |
7 | #Distributed under the terms of the Modified BSD License. |
|
7 | #Distributed under the terms of the Modified BSD License. | |
8 | # |
|
8 | # | |
9 | #The full license is in the file COPYING.txt, distributed with this software. |
|
9 | #The full license is in the file COPYING.txt, distributed with this software. | |
10 | #----------------------------------------------------------------------------- |
|
10 | #----------------------------------------------------------------------------- | |
11 |
|
11 | |||
12 | #----------------------------------------------------------------------------- |
|
12 | #----------------------------------------------------------------------------- | |
13 | # Imports |
|
13 | # Imports | |
14 | #----------------------------------------------------------------------------- |
|
14 | #----------------------------------------------------------------------------- | |
15 |
|
15 | |||
|
16 | from IPython.utils import io | |||
16 | from .base import WriterBase |
|
17 | from .base import WriterBase | |
17 |
|
18 | |||
18 | #----------------------------------------------------------------------------- |
|
19 | #----------------------------------------------------------------------------- | |
19 | # Classes |
|
20 | # Classes | |
20 | #----------------------------------------------------------------------------- |
|
21 | #----------------------------------------------------------------------------- | |
21 |
|
22 | |||
22 | class StdoutWriter(WriterBase): |
|
23 | class StdoutWriter(WriterBase): | |
23 | """Consumes output from nbconvert export...() methods and writes to the |
|
24 | """Consumes output from nbconvert export...() methods and writes to the | |
24 | stdout stream.""" |
|
25 | stdout stream.""" | |
25 |
|
26 | |||
26 |
|
27 | |||
27 | def write(self, output, resources, **kw): |
|
28 | def write(self, output, resources, **kw): | |
28 | """ |
|
29 | """ | |
29 | Consume and write Jinja output. |
|
30 | Consume and write Jinja output. | |
30 |
|
31 | |||
31 | See base for more... |
|
32 | See base for more... | |
32 | """ |
|
33 | """ | |
33 |
|
34 | io.unicode_std_stream().write(output) | ||
34 | print(output) |
|
@@ -1,51 +1,54 b'' | |||||
|
1 | # coding: utf-8 | |||
1 | """ |
|
2 | """ | |
2 | Module with tests for stdout |
|
3 | Module with tests for stdout | |
3 | """ |
|
4 | """ | |
4 |
|
5 | |||
5 | #----------------------------------------------------------------------------- |
|
6 | #----------------------------------------------------------------------------- | |
6 | # Copyright (c) 2013, the IPython Development Team. |
|
7 | # Copyright (c) 2013, the IPython Development Team. | |
7 | # |
|
8 | # | |
8 | # Distributed under the terms of the Modified BSD License. |
|
9 | # Distributed under the terms of the Modified BSD License. | |
9 | # |
|
10 | # | |
10 | # The full license is in the file COPYING.txt, distributed with this software. |
|
11 | # The full license is in the file COPYING.txt, distributed with this software. | |
11 | #----------------------------------------------------------------------------- |
|
12 | #----------------------------------------------------------------------------- | |
12 |
|
13 | |||
13 | #----------------------------------------------------------------------------- |
|
14 | #----------------------------------------------------------------------------- | |
14 | # Imports |
|
15 | # Imports | |
15 | #----------------------------------------------------------------------------- |
|
16 | #----------------------------------------------------------------------------- | |
16 |
|
17 | |||
17 | import sys |
|
18 | import sys | |
18 |
|
19 | |||
19 | from ...tests.base import TestsBase |
|
20 | from ...tests.base import TestsBase | |
20 | from ..stdout import StdoutWriter |
|
21 | from ..stdout import StdoutWriter | |
21 | from IPython.utils.py3compat import PY3 |
|
22 | from IPython.utils.py3compat import PY3 | |
22 |
|
23 | |||
23 | if PY3: |
|
24 | if PY3: | |
24 | from io import StringIO |
|
25 | from io import StringIO | |
25 | else: |
|
26 | else: | |
26 | from StringIO import StringIO |
|
27 | from StringIO import StringIO | |
27 |
|
28 | |||
28 |
|
29 | |||
29 | #----------------------------------------------------------------------------- |
|
30 | #----------------------------------------------------------------------------- | |
30 | # Class |
|
31 | # Class | |
31 | #----------------------------------------------------------------------------- |
|
32 | #----------------------------------------------------------------------------- | |
32 |
|
33 | |||
33 | class TestStdout(TestsBase): |
|
34 | class TestStdout(TestsBase): | |
34 | """Contains test functions for stdout.py""" |
|
35 | """Contains test functions for stdout.py""" | |
35 |
|
36 | |||
36 | def test_output(self): |
|
37 | def test_output(self): | |
37 | """Test stdout writer output.""" |
|
38 | """Test stdout writer output.""" | |
38 |
|
39 | |||
39 | # Capture the stdout. Remember original. |
|
40 | # Capture the stdout. Remember original. | |
40 | stdout = sys.stdout |
|
41 | stdout = sys.stdout | |
41 | stream = StringIO() |
|
42 | stream = StringIO() | |
42 | sys.stdout = stream |
|
43 | sys.stdout = stream | |
43 |
|
44 | |||
44 | # Create stdout writer, test output |
|
45 | # Create stdout writer, test output | |
45 | writer = StdoutWriter() |
|
46 | writer = StdoutWriter() | |
46 | writer.write('a', {'b': 'c'}) |
|
47 | writer.write(u'a×', {'b': 'c'}) | |
47 | output = stream.getvalue() |
|
48 | output = stream.getvalue() | |
48 | self.fuzzy_compare(output, 'a') |
|
49 | if not PY3: | |
|
50 | output = output.decode('utf-8') | |||
|
51 | self.fuzzy_compare(output, u'a×') | |||
49 |
|
52 | |||
50 | # Revert stdout |
|
53 | # Revert stdout | |
51 | sys.stdout = stdout No newline at end of file |
|
54 | sys.stdout = stdout |
General Comments 0
You need to be logged in to leave comments.
Login now