Show More
@@ -11,6 +11,7 b' import builtins as builtin_mod' | |||
|
11 | 11 | import gc |
|
12 | 12 | import itertools |
|
13 | 13 | import os |
|
14 | import shlex | |
|
14 | 15 | import sys |
|
15 | 16 | import time |
|
16 | 17 | import timeit |
@@ -617,6 +618,20 b' python-profiler package from non-free.""")' | |||
|
617 | 618 | |
|
618 | 619 | """ |
|
619 | 620 | |
|
621 | # Logic to handle issue #3664 | |
|
622 | # Add '--' after '-m <module_name>' to ignore additional args passed to a module. | |
|
623 | if '-m' in parameter_s and '--' not in parameter_s: | |
|
624 | argv = shlex.split(parameter_s, posix=(os.name == 'posix')) | |
|
625 | for idx, arg in enumerate(argv): | |
|
626 | if arg and arg.startswith('-') and arg != '-': | |
|
627 | if arg == '-m': | |
|
628 | argv.insert(idx + 2, '--') | |
|
629 | break | |
|
630 | else: | |
|
631 | # Positional arg, break | |
|
632 | break | |
|
633 | parameter_s = ' '.join(shlex.quote(arg) for arg in argv) | |
|
634 | ||
|
620 | 635 | # get arguments and set sys.argv for program to be run. |
|
621 | 636 | opts, arg_lst = self.parse_options(parameter_s, |
|
622 | 637 | 'nidtN:b:pD:l:rs:T:em:G', |
@@ -384,7 +384,14 b' tclass.py: deleting object: C-third' | |||
|
384 | 384 | _ip.magic("run %s" % self.fname) |
|
385 | 385 | |
|
386 | 386 | nt.assert_equal(_ip.user_ns['answer'], 42) |
|
387 | ||
|
387 | ||
|
388 | def test_file_options(self): | |
|
389 | src = ('import sys\n' | |
|
390 | 'a = " ".join(sys.argv[1:])\n') | |
|
391 | self.mktmp(src) | |
|
392 | test_opts = '-x 3 --verbose' | |
|
393 | _ip.run_line_magic("run", '{0} {1}'.format(self.fname, test_opts)) | |
|
394 | nt.assert_equal(_ip.user_ns['a'], test_opts) | |
|
388 | 395 | |
|
389 | 396 | |
|
390 | 397 | class TestMagicRunWithPackage(unittest.TestCase): |
@@ -417,6 +424,10 b' class TestMagicRunWithPackage(unittest.TestCase):' | |||
|
417 | 424 | self.writefile(os.path.join(package, 'absolute.py'), """ |
|
418 | 425 | from {0}.sub import x |
|
419 | 426 | """.format(package)) |
|
427 | self.writefile(os.path.join(package, 'args.py'), """ | |
|
428 | import sys | |
|
429 | a = " ".join(sys.argv[1:]) | |
|
430 | """.format(package)) | |
|
420 | 431 | |
|
421 | 432 | def tearDown(self): |
|
422 | 433 | os.chdir(self.__orig_cwd) |
@@ -458,6 +469,18 b' class TestMagicRunWithPackage(unittest.TestCase):' | |||
|
458 | 469 | def test_debug_run_submodule_with_relative_import(self): |
|
459 | 470 | self.check_run_submodule('relative', '-d') |
|
460 | 471 | |
|
472 | def test_module_options(self): | |
|
473 | _ip.user_ns.pop('a', None) | |
|
474 | test_opts = '-x abc -m test' | |
|
475 | _ip.run_line_magic('run', '-m {0}.args {1}'.format(self.package, test_opts)) | |
|
476 | nt.assert_equal(_ip.user_ns['a'], test_opts) | |
|
477 | ||
|
478 | def test_module_options_with_separator(self): | |
|
479 | _ip.user_ns.pop('a', None) | |
|
480 | test_opts = '-x abc -m test' | |
|
481 | _ip.run_line_magic('run', '-m {0}.args -- {1}'.format(self.package, test_opts)) | |
|
482 | nt.assert_equal(_ip.user_ns['a'], test_opts) | |
|
483 | ||
|
461 | 484 | def test_run__name__(): |
|
462 | 485 | with TemporaryDirectory() as td: |
|
463 | 486 | path = pjoin(td, 'foo.py') |
General Comments 0
You need to be logged in to leave comments.
Login now