Show More
@@ -0,0 +1,43 b'' | |||
|
1 | """ | |
|
2 | Module with utility functions for transformer tests | |
|
3 | """ | |
|
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 | #----------------------------------------------------------------------------- | |
|
14 | # Imports | |
|
15 | #----------------------------------------------------------------------------- | |
|
16 | ||
|
17 | from ...tests.base import TestsBase | |
|
18 | ||
|
19 | from IPython.nbformat import current as nbformat | |
|
20 | ||
|
21 | #----------------------------------------------------------------------------- | |
|
22 | # Class | |
|
23 | #----------------------------------------------------------------------------- | |
|
24 | ||
|
25 | class TransformerTestsBase(TestsBase): | |
|
26 | """Contains test functions transformer tests""" | |
|
27 | ||
|
28 | ||
|
29 | def build_notebook(self): | |
|
30 | """Build a notebook in memory for use with transformer tests""" | |
|
31 | ||
|
32 | outputs = [nbformat.new_output(output_type="stream", stream="stdout", output_text="a"), | |
|
33 | nbformat.new_output(output_type="text", output_text="b"), | |
|
34 | nbformat.new_output(output_type="stream", stream="stdout", output_text="c"), | |
|
35 | nbformat.new_output(output_type="stream", stream="stdout", output_text="d"), | |
|
36 | nbformat.new_output(output_type="stream", stream="stderr", output_text="e"), | |
|
37 | nbformat.new_output(output_type="stream", stream="stderr", output_text="f")] | |
|
38 | ||
|
39 | cells=[nbformat.new_code_cell(input="test", | |
|
40 | prompt_number=1,outputs=outputs)] | |
|
41 | worksheets = [nbformat.new_worksheet(name="worksheet1", cells=cells)] | |
|
42 | ||
|
43 | return nbformat.new_notebook(name="notebook1", worksheets=worksheets) |
@@ -0,0 +1,37 b'' | |||
|
1 | """ | |
|
2 | Module with tests for the csshtmlheader transformer | |
|
3 | """ | |
|
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 | #----------------------------------------------------------------------------- | |
|
14 | # Imports | |
|
15 | #----------------------------------------------------------------------------- | |
|
16 | ||
|
17 | from .base import TransformerTestsBase | |
|
18 | from ..csshtmlheader import CSSHTMLHeaderTransformer | |
|
19 | ||
|
20 | ||
|
21 | #----------------------------------------------------------------------------- | |
|
22 | # Class | |
|
23 | #----------------------------------------------------------------------------- | |
|
24 | ||
|
25 | class TestCSSHTMLHeader(TransformerTestsBase): | |
|
26 | """Contains test functions for csshtmlheader.py""" | |
|
27 | ||
|
28 | def test_constructor(self): | |
|
29 | """Can a CSSHTMLHeaderTransformer be constructed?""" | |
|
30 | CSSHTMLHeaderTransformer() | |
|
31 | ||
|
32 | ||
|
33 | def test_output(self): | |
|
34 | """Test the output of the CSSHTMLHeaderTransformer""" | |
|
35 | nb, res = CSSHTMLHeaderTransformer()(self.build_notebook(), {}) | |
|
36 | assert 'inlining' in res | |
|
37 | assert 'css' in res.inlining No newline at end of file |
@@ -14,32 +14,19 b' Module with tests for the coalescestreams transformer' | |||
|
14 | 14 | # Imports |
|
15 | 15 | #----------------------------------------------------------------------------- |
|
16 | 16 | |
|
17 |
from |
|
|
17 | from .base import TransformerTestsBase | |
|
18 | 18 | from ..coalescestreams import coalesce_streams |
|
19 | 19 | |
|
20 | from IPython.nbformat import current as nbformat | |
|
21 | 20 | |
|
22 | 21 | #----------------------------------------------------------------------------- |
|
23 | 22 | # Class |
|
24 | 23 | #----------------------------------------------------------------------------- |
|
25 | 24 | |
|
26 | class TestCoalesceStreams(TestsBase): | |
|
25 | class TestCoalesceStreams(TransformerTestsBase): | |
|
27 | 26 | """Contains test functions for coalescestreams.py""" |
|
28 | 27 | |
|
29 | ||
|
30 | def build_notebook(self): | |
|
31 | outputs = [nbformat.new_output(output_type="stream", stream="stdout", output_text="a"), | |
|
32 | nbformat.new_output(output_type="text", output_text="b"), | |
|
33 | nbformat.new_output(output_type="stream", stream="stdout", output_text="c"), | |
|
34 | nbformat.new_output(output_type="stream", stream="stdout", output_text="d"), | |
|
35 | nbformat.new_output(output_type="stream", stream="stderr", output_text="e"), | |
|
36 | nbformat.new_output(output_type="stream", stream="stderr", output_text="f")] | |
|
37 | cells=[nbformat.new_code_cell(input="test", | |
|
38 | prompt_number=1,outputs=outputs)] | |
|
39 | worksheets = [nbformat.new_worksheet(name="worksheet1", cells=cells)] | |
|
40 | return nbformat.new_notebook(name="notebook1", worksheets=worksheets) | |
|
41 | ||
|
42 | 28 | def test_coalesce_streams(self): |
|
29 | """coalesce_streams transformer output test""" | |
|
43 | 30 | nb, res = coalesce_streams(self.build_notebook(), {}) |
|
44 | 31 | self.assertEqual(nb.worksheets[0].cells[0].outputs[0].text, "a") |
|
45 | 32 | self.assertEqual(nb.worksheets[0].cells[0].outputs[1].output_type, "text") |
General Comments 0
You need to be logged in to leave comments.
Login now