Show More
@@ -2649,9 +2649,9 b' class InteractiveShell(SingletonConfigurable):' | |||||
2649 | def get_cells(): |
|
2649 | def get_cells(): | |
2650 | """generator for sequence of code blocks to run""" |
|
2650 | """generator for sequence of code blocks to run""" | |
2651 | if fname.endswith('.ipynb'): |
|
2651 | if fname.endswith('.ipynb'): | |
2652 |
from IPython.nbformat import |
|
2652 | from IPython.nbformat import read | |
2653 | with open(fname) as f: |
|
2653 | with io_open(fname) as f: | |
2654 |
nb = |
|
2654 | nb = read(f, as_version=4) | |
2655 | if not nb.cells: |
|
2655 | if not nb.cells: | |
2656 | return |
|
2656 | return | |
2657 | for cell in nb.cells: |
|
2657 | for cell in nb.cells: |
@@ -596,14 +596,16 b' Defaulting color scheme to \'NoColor\'"""' | |||||
596 | """ |
|
596 | """ | |
597 | args = magic_arguments.parse_argstring(self.notebook, s) |
|
597 | args = magic_arguments.parse_argstring(self.notebook, s) | |
598 |
|
598 | |||
599 |
from IPython.nbformat import |
|
599 | from IPython.nbformat import write, v4 | |
600 | args.filename = unquote_filename(args.filename) |
|
600 | args.filename = unquote_filename(args.filename) | |
601 | if args.export: |
|
601 | if args.export: | |
602 | cells = [] |
|
602 | cells = [] | |
603 | hist = list(self.shell.history_manager.get_range()) |
|
603 | hist = list(self.shell.history_manager.get_range()) | |
604 |
for session, |
|
604 | for session, execution_count, input in hist[:-1]: | |
605 |
cells.append( |
|
605 | cells.append(v4.new_code_cell( | |
606 | input=input)) |
|
606 | execution_count=execution_count, | |
607 | nb = current.new_notebook(cells=cells) |
|
607 | source=source | |
|
608 | )) | |||
|
609 | nb = v4.new_notebook(cells=cells) | |||
608 | with io.open(args.filename, 'w', encoding='utf-8') as f: |
|
610 | with io.open(args.filename, 'w', encoding='utf-8') as f: | |
609 |
|
|
611 | write(f, nb, version=4) |
@@ -5,10 +5,6 b' Needs to be run by nose (to make ipython session available).' | |||||
5 | """ |
|
5 | """ | |
6 | from __future__ import absolute_import |
|
6 | from __future__ import absolute_import | |
7 |
|
7 | |||
8 | #----------------------------------------------------------------------------- |
|
|||
9 | # Imports |
|
|||
10 | #----------------------------------------------------------------------------- |
|
|||
11 |
|
||||
12 | import io |
|
8 | import io | |
13 | import os |
|
9 | import os | |
14 | import sys |
|
10 | import sys | |
@@ -40,9 +36,6 b' if py3compat.PY3:' | |||||
40 | else: |
|
36 | else: | |
41 | from StringIO import StringIO |
|
37 | from StringIO import StringIO | |
42 |
|
38 | |||
43 | #----------------------------------------------------------------------------- |
|
|||
44 | # Test functions begin |
|
|||
45 | #----------------------------------------------------------------------------- |
|
|||
46 |
|
39 | |||
47 | @magic.magics_class |
|
40 | @magic.magics_class | |
48 | class DummyMagics(magic.Magics): pass |
|
41 | class DummyMagics(magic.Magics): pass | |
@@ -624,7 +617,7 b' def test_extension():' | |||||
624 |
|
617 | |||
625 |
|
618 | |||
626 | # The nose skip decorator doesn't work on classes, so this uses unittest's skipIf |
|
619 | # The nose skip decorator doesn't work on classes, so this uses unittest's skipIf | |
627 |
@skipIf(dec.module_not_available('IPython.nbformat |
|
620 | @skipIf(dec.module_not_available('IPython.nbformat'), 'nbformat not importable') | |
628 | class NotebookExportMagicTests(TestCase): |
|
621 | class NotebookExportMagicTests(TestCase): | |
629 | def test_notebook_export_json(self): |
|
622 | def test_notebook_export_json(self): | |
630 | with TemporaryDirectory() as td: |
|
623 | with TemporaryDirectory() as td: |
@@ -7,11 +7,12 b' will be kept in this separate file. This makes it easier to aggregate in one' | |||||
7 | place the tricks needed to handle it; most other magics are much easier to test |
|
7 | place the tricks needed to handle it; most other magics are much easier to test | |
8 | and we do so in a common test_magic file. |
|
8 | and we do so in a common test_magic file. | |
9 | """ |
|
9 | """ | |
|
10 | ||||
|
11 | # Copyright (c) IPython Development Team. | |||
|
12 | # Distributed under the terms of the Modified BSD License. | |||
|
13 | ||||
10 | from __future__ import absolute_import |
|
14 | from __future__ import absolute_import | |
11 |
|
15 | |||
12 | #----------------------------------------------------------------------------- |
|
|||
13 | # Imports |
|
|||
14 | #----------------------------------------------------------------------------- |
|
|||
15 |
|
16 | |||
16 | import functools |
|
17 | import functools | |
17 | import os |
|
18 | import os | |
@@ -32,9 +33,6 b' from IPython.utils.io import capture_output' | |||||
32 | from IPython.utils.tempdir import TemporaryDirectory |
|
33 | from IPython.utils.tempdir import TemporaryDirectory | |
33 | from IPython.core import debugger |
|
34 | from IPython.core import debugger | |
34 |
|
35 | |||
35 | #----------------------------------------------------------------------------- |
|
|||
36 | # Test functions begin |
|
|||
37 | #----------------------------------------------------------------------------- |
|
|||
38 |
|
36 | |||
39 | def doctest_refbug(): |
|
37 | def doctest_refbug(): | |
40 | """Very nasty problem with references held by multiple runs of a script. |
|
38 | """Very nasty problem with references held by multiple runs of a script. | |
@@ -372,17 +370,17 b' tclass.py: deleting object: C-third' | |||||
372 | with tt.AssertNotPrints('SystemExit'): |
|
370 | with tt.AssertNotPrints('SystemExit'): | |
373 | _ip.magic('run -e %s' % self.fname) |
|
371 | _ip.magic('run -e %s' % self.fname) | |
374 |
|
372 | |||
375 |
@dec.skip_without('IPython.nbformat |
|
373 | @dec.skip_without('IPython.nbformat') # Requires jsonschema | |
376 | def test_run_nb(self): |
|
374 | def test_run_nb(self): | |
377 | """Test %run notebook.ipynb""" |
|
375 | """Test %run notebook.ipynb""" | |
378 |
from IPython.nbformat import |
|
376 | from IPython.nbformat import v4, writes | |
379 |
nb = |
|
377 | nb = v4.new_notebook( | |
380 | cells=[ |
|
378 | cells=[ | |
381 |
|
|
379 | v4.new_markdown_cell("The Ultimate Question of Everything"), | |
382 |
|
|
380 | v4.new_code_cell("answer=42") | |
383 | ] |
|
381 | ] | |
384 | ) |
|
382 | ) | |
385 |
src = |
|
383 | src = writes(nb, version=4) | |
386 | self.mktmp(src, ext='.ipynb') |
|
384 | self.mktmp(src, ext='.ipynb') | |
387 |
|
385 | |||
388 | _ip.magic("run %s" % self.fname) |
|
386 | _ip.magic("run %s" % self.fname) |
@@ -1,23 +1,11 b'' | |||||
1 | """Test help output of various IPython entry points""" |
|
1 | """Test help output of various IPython entry points""" | |
2 |
|
2 | |||
3 | #----------------------------------------------------------------------------- |
|
3 | # Copyright (c) IPython Development Team. | |
4 | # Copyright (C) 2013 The IPython Development Team |
|
4 | # Distributed under the terms of the Modified BSD License. | |
5 | # |
|
|||
6 | # Distributed under the terms of the BSD License. The full license is in |
|
|||
7 | # the file COPYING, distributed as part of this software. |
|
|||
8 | #----------------------------------------------------------------------------- |
|
|||
9 |
|
||||
10 | #----------------------------------------------------------------------------- |
|
|||
11 | # Imports |
|
|||
12 | #----------------------------------------------------------------------------- |
|
|||
13 |
|
5 | |||
14 | import IPython.testing.tools as tt |
|
6 | import IPython.testing.tools as tt | |
15 | from IPython.testing.decorators import skip_without |
|
7 | from IPython.testing.decorators import skip_without | |
16 |
|
8 | |||
17 | #----------------------------------------------------------------------------- |
|
|||
18 | # Tests |
|
|||
19 | #----------------------------------------------------------------------------- |
|
|||
20 |
|
||||
21 |
|
9 | |||
22 | def test_ipython_help(): |
|
10 | def test_ipython_help(): | |
23 | tt.help_all_output_test() |
|
11 | tt.help_all_output_test() | |
@@ -37,6 +25,6 b' def test_locate_help():' | |||||
37 | def test_locate_profile_help(): |
|
25 | def test_locate_profile_help(): | |
38 | tt.help_all_output_test("locate profile") |
|
26 | tt.help_all_output_test("locate profile") | |
39 |
|
27 | |||
40 |
@skip_without('IPython.nbformat |
|
28 | @skip_without('IPython.nbformat') # Requires jsonschema to be installed | |
41 | def test_trust_help(): |
|
29 | def test_trust_help(): | |
42 | tt.help_all_output_test("trust") |
|
30 | tt.help_all_output_test("trust") |
General Comments 0
You need to be logged in to leave comments.
Login now