Show More
@@ -672,17 +672,16 b' class ExecutionMagics(Magics):' | |||
|
672 | 672 | modulename = opts["m"][0] |
|
673 | 673 | modpath = find_mod(modulename) |
|
674 | 674 | if modpath is None: |
|
675 |
|
|
|
676 |
r |
|
|
675 | msg = '%r is not a valid modulename on sys.path'%modulename | |
|
676 | raise Exception(msg) | |
|
677 | 677 | arg_lst = [modpath] + arg_lst |
|
678 | 678 | try: |
|
679 | 679 | fpath = None # initialize to make sure fpath is in scope later |
|
680 | 680 | fpath = arg_lst[0] |
|
681 | 681 | filename = file_finder(fpath) |
|
682 | 682 | except IndexError: |
|
683 |
|
|
|
684 | print('\n%run:\n', oinspect.getdoc(self.run)) | |
|
685 | return | |
|
683 | msg = 'you must provide at least a filename.' | |
|
684 | raise Exception(msg) | |
|
686 | 685 | except IOError as e: |
|
687 | 686 | try: |
|
688 | 687 | msg = str(e) |
@@ -690,8 +689,7 b' class ExecutionMagics(Magics):' | |||
|
690 | 689 | msg = e.message |
|
691 | 690 | if os.name == 'nt' and re.match(r"^'.*'$",fpath): |
|
692 | 691 | warn('For Windows, use double quotes to wrap a filename: %run "mypath\\myfile.py"') |
|
693 |
|
|
|
694 | return | |
|
692 | raise Exception(msg) | |
|
695 | 693 | except TypeError: |
|
696 | 694 | if fpath in sys.meta_path: |
|
697 | 695 | filename = "" |
@@ -701,7 +699,7 b' class ExecutionMagics(Magics):' | |||
|
701 | 699 | if filename.lower().endswith(('.ipy', '.ipynb')): |
|
702 | 700 | with preserve_keys(self.shell.user_ns, '__file__'): |
|
703 | 701 | self.shell.user_ns['__file__'] = filename |
|
704 | self.shell.safe_execfile_ipy(filename) | |
|
702 | self.shell.safe_execfile_ipy(filename, raise_exceptions=True) | |
|
705 | 703 | return |
|
706 | 704 | |
|
707 | 705 | # Control the response to exit() calls made by the script being run |
@@ -396,6 +396,25 b' tclass.py: deleting object: C-third' | |||
|
396 | 396 | |
|
397 | 397 | nt.assert_equal(_ip.user_ns['answer'], 42) |
|
398 | 398 | |
|
399 | def test_run_nb_error(self): | |
|
400 | """Test %run notebook.ipynb error""" | |
|
401 | from nbformat import v4, writes | |
|
402 | # %run when a file name isn't provided | |
|
403 | nt.assert_raises(Exception, _ip.magic, "run") | |
|
404 | ||
|
405 | # %run when a file doesn't exist | |
|
406 | nt.assert_raises(Exception, _ip.magic, "run foobar.ipynb") | |
|
407 | ||
|
408 | # %run on a notebook with an error | |
|
409 | nb = v4.new_notebook( | |
|
410 | cells=[ | |
|
411 | v4.new_code_cell("0/0") | |
|
412 | ] | |
|
413 | ) | |
|
414 | src = writes(nb, version=4) | |
|
415 | self.mktmp(src, ext='.ipynb') | |
|
416 | nt.assert_raises(Exception, _ip.magic, "run %s" % self.fname) | |
|
417 | ||
|
399 | 418 | def test_file_options(self): |
|
400 | 419 | src = ('import sys\n' |
|
401 | 420 | 'a = " ".join(sys.argv[1:])\n') |
General Comments 0
You need to be logged in to leave comments.
Login now