##// END OF EJS Templates
Start adding tests from runipy
Julia Evans -
Show More
@@ -0,0 +1,46 b''
1 {
2 "metadata": {
3 "name": ""
4 },
5 "nbformat": 3,
6 "nbformat_minor": 0,
7 "worksheets": [
8 {
9 "cells": [
10 {
11 "cell_type": "code",
12 "collapsed": false,
13 "input": [
14 "from IPython.display import clear_output"
15 ],
16 "language": "python",
17 "metadata": {},
18 "outputs": [],
19 "prompt_number": 1
20 },
21 {
22 "cell_type": "code",
23 "collapsed": false,
24 "input": [
25 "for i in range(10):\n",
26 " clear_output()\n",
27 " print i"
28 ],
29 "language": "python",
30 "metadata": {},
31 "outputs": [
32 {
33 "output_type": "stream",
34 "stream": "stdout",
35 "text": [
36 "9\n"
37 ]
38 }
39 ],
40 "prompt_number": 2
41 }
42 ],
43 "metadata": {}
44 }
45 ]
46 } No newline at end of file
@@ -0,0 +1,55 b''
1 {
2 "metadata": {
3 "name": ""
4 },
5 "nbformat": 3,
6 "nbformat_minor": 0,
7 "worksheets": [
8 {
9 "cells": [
10 {
11 "cell_type": "code",
12 "collapsed": false,
13 "input": [
14 "i, j = 1, 1"
15 ],
16 "language": "python",
17 "metadata": {},
18 "outputs": [],
19 "prompt_number": 1
20 },
21 {
22 "cell_type": "code",
23 "collapsed": false,
24 "input": [
25 "for m in range(10):\n",
26 " i, j = j, i + j\n",
27 " print j"
28 ],
29 "language": "python",
30 "metadata": {},
31 "outputs": [
32 {
33 "output_type": "stream",
34 "stream": "stdout",
35 "text": [
36 "2\n",
37 "3\n",
38 "5\n",
39 "8\n",
40 "13\n",
41 "21\n",
42 "34\n",
43 "55\n",
44 "89\n",
45 "144\n"
46 ]
47 }
48 ],
49 "prompt_number": 2
50 }
51 ],
52 "metadata": {}
53 }
54 ]
55 } No newline at end of file
@@ -0,0 +1,33 b''
1 {
2 "metadata": {
3 "name": ""
4 },
5 "nbformat": 3,
6 "nbformat_minor": 0,
7 "worksheets": [
8 {
9 "cells": [
10 {
11 "cell_type": "code",
12 "collapsed": false,
13 "input": [
14 "print \"Hello World\""
15 ],
16 "language": "python",
17 "metadata": {},
18 "outputs": [
19 {
20 "output_type": "stream",
21 "stream": "stdout",
22 "text": [
23 "Hello World\n"
24 ]
25 }
26 ],
27 "prompt_number": 1
28 }
29 ],
30 "metadata": {}
31 }
32 ]
33 } No newline at end of file
@@ -0,0 +1,36 b''
1 {
2 "metadata": {
3 "name": ""
4 },
5 "nbformat": 3,
6 "nbformat_minor": 0,
7 "worksheets": [
8 {
9 "cells": [
10 {
11 "cell_type": "code",
12 "collapsed": false,
13 "input": [
14 "from IPython.display import Image"
15 ],
16 "language": "python",
17 "metadata": {},
18 "outputs": [],
19 "prompt_number": 1
20 },
21 {
22 "cell_type": "code",
23 "collapsed": false,
24 "input": [
25 "Image('../input/python.png');"
26 ],
27 "language": "python",
28 "metadata": {},
29 "outputs": [],
30 "prompt_number": 2
31 }
32 ],
33 "metadata": {}
34 }
35 ]
36 } No newline at end of file
@@ -0,0 +1,53 b''
1 {
2 "metadata": {
3 "name": ""
4 },
5 "nbformat": 3,
6 "nbformat_minor": 0,
7 "worksheets": [
8 {
9 "cells": [
10 {
11 "cell_type": "code",
12 "collapsed": false,
13 "input": [
14 "from IPython.display import SVG"
15 ],
16 "language": "python",
17 "metadata": {},
18 "outputs": [],
19 "prompt_number": 1
20 },
21 {
22 "cell_type": "code",
23 "collapsed": false,
24 "input": [
25 "SVG(data='''\n",
26 "<svg height=\"100\" width=\"100\">\n",
27 " <circle cx=\"50\" cy=\"50\" r=\"40\" stroke=\"black\" stroke-width=\"2\" fill=\"red\" />\n",
28 "</svg>''')"
29 ],
30 "language": "python",
31 "metadata": {},
32 "outputs": [
33 {
34 "metadata": {},
35 "output_type": "pyout",
36 "prompt_number": 2,
37 "svg": [
38 "<svg height=\"100\" width=\"100\">\n",
39 " <circle cx=\"50\" cy=\"50\" fill=\"red\" r=\"40\" stroke=\"black\" stroke-width=\"2\"/>\n",
40 "</svg>"
41 ],
42 "text": [
43 "<IPython.core.display.SVG at 0x10428e150>"
44 ]
45 }
46 ],
47 "prompt_number": 2
48 }
49 ],
50 "metadata": {}
51 }
52 ]
53 } No newline at end of file
@@ -0,0 +1,55 b''
1 {
2 "metadata": {
3 "name": ""
4 },
5 "nbformat": 3,
6 "nbformat_minor": 0,
7 "worksheets": [
8 {
9 "cells": [
10 {
11 "cell_type": "code",
12 "collapsed": false,
13 "input": [
14 "1 / 0"
15 ],
16 "language": "python",
17 "metadata": {},
18 "outputs": [
19 {
20 "ename": "ZeroDivisionError",
21 "evalue": "integer division or modulo by zero",
22 "output_type": "pyerr",
23 "traceback": [
24 "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m\n\u001b[1;31mZeroDivisionError\u001b[0m Traceback (most recent call last)",
25 "\u001b[1;32m<ipython-input-1-b710d87c980c>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[1;36m1\u001b[0m \u001b[1;33m/\u001b[0m \u001b[1;36m0\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
26 "\u001b[1;31mZeroDivisionError\u001b[0m: integer division or modulo by zero"
27 ]
28 }
29 ],
30 "prompt_number": 1
31 },
32 {
33 "cell_type": "code",
34 "collapsed": false,
35 "input": [
36 "print 'ok'"
37 ],
38 "language": "python",
39 "metadata": {},
40 "outputs": [
41 {
42 "output_type": "stream",
43 "stream": "stdout",
44 "text": [
45 "ok\n"
46 ]
47 }
48 ],
49 "prompt_number": 2
50 }
51 ],
52 "metadata": {}
53 }
54 ]
55 } No newline at end of file
@@ -0,0 +1,33 b''
1 {
2 "metadata": {
3 "name": ""
4 },
5 "nbformat": 3,
6 "nbformat_minor": 0,
7 "worksheets": [
8 {
9 "cells": [
10 {
11 "cell_type": "code",
12 "collapsed": false,
13 "input": [
14 "print '\u2603'"
15 ],
16 "language": "python",
17 "metadata": {},
18 "outputs": [
19 {
20 "output_type": "stream",
21 "stream": "stdout",
22 "text": [
23 "\u2603\n"
24 ]
25 }
26 ],
27 "prompt_number": 1
28 }
29 ],
30 "metadata": {}
31 }
32 ]
33 } No newline at end of file
@@ -0,0 +1,36 b''
1 {
2 "metadata": {
3 "name": ""
4 },
5 "nbformat": 3,
6 "nbformat_minor": 0,
7 "worksheets": [
8 {
9 "cells": [
10 {
11 "cell_type": "code",
12 "collapsed": false,
13 "input": [
14 "from IPython.display import clear_output"
15 ],
16 "language": "python",
17 "metadata": {},
18 "outputs": []
19 },
20 {
21 "cell_type": "code",
22 "collapsed": false,
23 "input": [
24 "for i in range(10):\n",
25 " clear_output()\n",
26 " print i"
27 ],
28 "language": "python",
29 "metadata": {},
30 "outputs": []
31 }
32 ],
33 "metadata": {}
34 }
35 ]
36 } No newline at end of file
@@ -0,0 +1,36 b''
1 {
2 "metadata": {
3 "name": ""
4 },
5 "nbformat": 3,
6 "nbformat_minor": 0,
7 "worksheets": [
8 {
9 "cells": [
10 {
11 "cell_type": "code",
12 "collapsed": false,
13 "input": [
14 "i, j = 1, 1"
15 ],
16 "language": "python",
17 "metadata": {},
18 "outputs": []
19 },
20 {
21 "cell_type": "code",
22 "collapsed": false,
23 "input": [
24 "for m in range(10):\n",
25 " i, j = j, i + j\n",
26 " print j"
27 ],
28 "language": "python",
29 "metadata": {},
30 "outputs": []
31 }
32 ],
33 "metadata": {}
34 }
35 ]
36 } No newline at end of file
@@ -0,0 +1,24 b''
1 {
2 "metadata": {
3 "name": ""
4 },
5 "nbformat": 3,
6 "nbformat_minor": 0,
7 "worksheets": [
8 {
9 "cells": [
10 {
11 "cell_type": "code",
12 "collapsed": false,
13 "input": [
14 "print \"Hello World\""
15 ],
16 "language": "python",
17 "metadata": {},
18 "outputs": []
19 }
20 ],
21 "metadata": {}
22 }
23 ]
24 } No newline at end of file
@@ -0,0 +1,34 b''
1 {
2 "metadata": {
3 "name": ""
4 },
5 "nbformat": 3,
6 "nbformat_minor": 0,
7 "worksheets": [
8 {
9 "cells": [
10 {
11 "cell_type": "code",
12 "collapsed": false,
13 "input": [
14 "from IPython.display import Image"
15 ],
16 "language": "python",
17 "metadata": {},
18 "outputs": []
19 },
20 {
21 "cell_type": "code",
22 "collapsed": false,
23 "input": [
24 "Image('../input/python.png');"
25 ],
26 "language": "python",
27 "metadata": {},
28 "outputs": []
29 }
30 ],
31 "metadata": {}
32 }
33 ]
34 } No newline at end of file
@@ -0,0 +1,37 b''
1 {
2 "metadata": {
3 "name": ""
4 },
5 "nbformat": 3,
6 "nbformat_minor": 0,
7 "worksheets": [
8 {
9 "cells": [
10 {
11 "cell_type": "code",
12 "collapsed": false,
13 "input": [
14 "from IPython.display import SVG"
15 ],
16 "language": "python",
17 "metadata": {},
18 "outputs": []
19 },
20 {
21 "cell_type": "code",
22 "collapsed": false,
23 "input": [
24 "SVG(data='''\n",
25 "<svg height=\"100\" width=\"100\">\n",
26 " <circle cx=\"50\" cy=\"50\" r=\"40\" stroke=\"black\" stroke-width=\"2\" fill=\"red\" />\n",
27 "</svg>''')"
28 ],
29 "language": "python",
30 "metadata": {},
31 "outputs": []
32 }
33 ],
34 "metadata": {}
35 }
36 ]
37 } No newline at end of file
@@ -0,0 +1,55 b''
1 {
2 "metadata": {
3 "name": ""
4 },
5 "nbformat": 3,
6 "nbformat_minor": 0,
7 "worksheets": [
8 {
9 "cells": [
10 {
11 "cell_type": "code",
12 "collapsed": false,
13 "input": [
14 "1 / 0"
15 ],
16 "language": "python",
17 "metadata": {},
18 "outputs": [
19 {
20 "ename": "ZeroDivisionError",
21 "evalue": "integer division or modulo by zero",
22 "output_type": "pyerr",
23 "traceback": [
24 "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m\n\u001b[1;31mZeroDivisionError\u001b[0m Traceback (most recent call last)",
25 "\u001b[1;32m<ipython-input-1-b710d87c980c>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[1;36m1\u001b[0m \u001b[1;33m/\u001b[0m \u001b[1;36m0\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
26 "\u001b[1;31mZeroDivisionError\u001b[0m: integer division or modulo by zero"
27 ]
28 }
29 ],
30 "prompt_number": 1
31 },
32 {
33 "cell_type": "code",
34 "collapsed": false,
35 "input": [
36 "print 'ok'"
37 ],
38 "language": "python",
39 "metadata": {},
40 "outputs": [
41 {
42 "output_type": "stream",
43 "stream": "stdout",
44 "text": [
45 "ok\n"
46 ]
47 }
48 ],
49 "prompt_number": 2
50 }
51 ],
52 "metadata": {}
53 }
54 ]
55 } No newline at end of file
@@ -0,0 +1,24 b''
1 {
2 "metadata": {
3 "name": ""
4 },
5 "nbformat": 3,
6 "nbformat_minor": 0,
7 "worksheets": [
8 {
9 "cells": [
10 {
11 "cell_type": "code",
12 "collapsed": false,
13 "input": [
14 "print '\u2603'"
15 ],
16 "language": "python",
17 "metadata": {},
18 "outputs": []
19 }
20 ],
21 "metadata": {}
22 }
23 ]
24 } No newline at end of file
1 NO CONTENT: new file 100644, binary diff hidden
NO CONTENT: new file 100644, binary diff hidden
@@ -9,6 +9,8 b' Module with tests for the execute preprocessor.'
9 # Imports
9 # Imports
10 #-----------------------------------------------------------------------------
10 #-----------------------------------------------------------------------------
11 import copy
11 import copy
12 import os
13 import re
12
14
13 from IPython.nbformat import current as nbformat
15 from IPython.nbformat import current as nbformat
14
16
@@ -23,6 +25,28 b' from ..execute import ExecutePreprocessor'
23 class TestExecute(PreprocessorTestsBase):
25 class TestExecute(PreprocessorTestsBase):
24 """Contains test functions for execute.py"""
26 """Contains test functions for execute.py"""
25
27
28 def prepare_cell(self, cell):
29 cell = dict(cell)
30 if 'metadata' in cell:
31 del cell['metadata']
32 if 'text' in cell:
33 cell['text'] = re.sub('0x[0-9a-f]{7,9}', '<HEXADDR>', cell['text'])
34 return cell
35
36
37 def assert_notebooks_equal(self, expected, actual):
38 expected_cells = expected['worksheets'][0]['cells']
39 actual_cells = actual['worksheets'][0]['cells']
40 assert len(expected_cells) == len(actual_cells)
41
42 # TODO: what does this code do?
43 for expected_out, actual_out in zip(expected_cells, actual_cells):
44 for k in set(expected_out).union(actual_out):
45 if k == 'outputs':
46 self.assertEquals(len(expected_out[k]), len(actual_out[k]))
47 for e, a in zip(expected_out[k], actual_out[k]):
48 assert self.prepare_cell(e) == self.prepare_cell(a)
49
26
50
27 def build_preprocessor(self):
51 def build_preprocessor(self):
28 """Make an instance of a preprocessor"""
52 """Make an instance of a preprocessor"""
@@ -30,16 +54,25 b' class TestExecute(PreprocessorTestsBase):'
30 preprocessor.enabled = True
54 preprocessor.enabled = True
31 return preprocessor
55 return preprocessor
32
56
57
33 def test_constructor(self):
58 def test_constructor(self):
34 """Can a ExecutePreprocessor be constructed?"""
59 """Can a ExecutePreprocessor be constructed?"""
35 self.build_preprocessor()
60 self.build_preprocessor()
36
61
37 def test_correct_output(self):
62
38 """Test that ExecutePreprocessor evaluates a cell to the right thing"""
63 def test_run_notebooks(self):
39 nb = self.build_notebook()
64 """Runs a series of test notebooks and compares them to their actual output"""
65 current_dir = os.path.dirname(__file__)
66 input_files = os.listdir(os.path.join(current_dir, 'input'))
67 for filename in input_files:
68 if not filename.endswith(".ipynb"):
69 continue
70 with open(os.path.join(current_dir, 'input', filename)) as f:
71 input_nb = nbformat.read(f, 'ipynb')
72 with open(os.path.join(current_dir, 'expected', filename)) as f:
73 expected_nb = nbformat.read(f, 'ipynb')
40 res = self.build_resources()
74 res = self.build_resources()
41 nb.worksheets[0].cells[0].input = "print 'hi!'"
42 preprocessor = self.build_preprocessor()
75 preprocessor = self.build_preprocessor()
43 nb, res = preprocessor(nb, res)
76 output_nb, _ = preprocessor(input_nb, res)
44 expected_outputs = [{'output_type': 'stream', 'stream': 'stdout', 'text': 'hi!\n'}]
77 self.assert_notebooks_equal(output_nb, expected_nb)
45 assert nb.worksheets[0].cells[0].outputs == expected_outputs
78
General Comments 0
You need to be logged in to leave comments. Login now