##// END OF EJS Templates
addressing linting issues
Aditya Sathe -
Show More
@@ -618,9 +618,9 b' class Magics(Configurable):'
618 posix = kw.get('posix', os.name == 'posix')
618 posix = kw.get('posix', os.name == 'posix')
619 strict = kw.get('strict', True)
619 strict = kw.get('strict', True)
620
620
621 preserve_non_opts = kw.get('preserve_non_opts', False)
621 preserve_non_opts = kw.get("preserve_non_opts", False)
622 remainder_arg_str = arg_str
622 remainder_arg_str = arg_str
623
623
624 # Check if we have more than one argument to warrant extra processing:
624 # Check if we have more than one argument to warrant extra processing:
625 odict = {} # Dictionary with options
625 odict = {} # Dictionary with options
626 args = arg_str.split()
626 args = arg_str.split()
@@ -632,15 +632,18 b' class Magics(Configurable):'
632 try:
632 try:
633 opts,args = getopt(argv, opt_str, long_opts)
633 opts,args = getopt(argv, opt_str, long_opts)
634 except GetoptError as e:
634 except GetoptError as e:
635 raise UsageError('%s ( allowed: "%s" %s)' % (e.msg,opt_str,
635 raise UsageError(
636 " ".join(long_opts))) from e
636 '%s ( allowed: "%s" %s)' % (e.msg, opt_str, " ".join(long_opts))
637 for o,a in opts:
637 ) from e
638 if mode is 'string' and preserve_non_opts:
638 for o, a in opts:
639 if mode is "string" and preserve_non_opts:
639 # remove option-parts from the original args-string and preserve remaining-part.
640 # remove option-parts from the original args-string and preserve remaining-part.
640 # This relies on the arg_split(...) and getopt(...)'s impl spec, that the parsed options are
641 # This relies on the arg_split(...) and getopt(...)'s impl spec, that the parsed options are
641 # returned in the original order.
642 # returned in the original order.
642 remainder_arg_str = remainder_arg_str.replace(o, '', 1).replace(a, '', 1)
643 remainder_arg_str = remainder_arg_str.replace(o, "", 1).replace(
643 if o.startswith('--'):
644 a, "", 1
645 )
646 if o.startswith("--"):
644 o = o[2:]
647 o = o[2:]
645 else:
648 else:
646 o = o[1:]
649 o = o[1:]
@@ -1073,8 +1073,9 b' class ExecutionMagics(Magics):'
1073 does not matter as long as results from timeit.py are not mixed with
1073 does not matter as long as results from timeit.py are not mixed with
1074 those from %timeit."""
1074 those from %timeit."""
1075
1075
1076 opts, stmt = self.parse_options(line, 'n:r:tcp:qo',
1076 opts, stmt = self.parse_options(
1077 posix=False, strict=False, preserve_non_opts=True)
1077 line, "n:r:tcp:qo", posix=False, strict=False, preserve_non_opts=True
1078 )
1078 if stmt == "" and cell is None:
1079 if stmt == "" and cell is None:
1079 return
1080 return
1080
1081
@@ -473,17 +473,19 b' def test_parse_options():'
473 def test_parse_options_preserve_non_option_string():
473 def test_parse_options_preserve_non_option_string():
474 """Test to assert preservation of non-option part of magic-block, while parsing magic options."""
474 """Test to assert preservation of non-option part of magic-block, while parsing magic options."""
475 m = DummyMagics(_ip)
475 m = DummyMagics(_ip)
476 opts, stmt = m.parse_options(' -n1 -r 13 _ = 314 + foo', 'n:r:', preserve_non_opts= True)
476 opts, stmt = m.parse_options(
477 nt.assert_equal(opts, {'n': '1', 'r': '13'})
477 " -n1 -r 13 _ = 314 + foo", "n:r:", preserve_non_opts=True
478 nt.assert_equal(stmt, '_ = 314 + foo')
478 )
479 nt.assert_equal(opts, {"n": "1", "r": "13"})
480 nt.assert_equal(stmt, "_ = 314 + foo")
479
481
480
482
481 def test_run_magic_preserve_code_block():
483 def test_run_magic_preserve_code_block():
482 """Test to assert preservation of non-option part of magic-block, while running magic."""
484 """Test to assert preservation of non-option part of magic-block, while running magic."""
483 _ip.user_ns['spaces'] = []
485 _ip.user_ns["spaces"] = []
484 _ip.magic("timeit -n1 -r1 spaces.append([s.count(' ') for s in ['document']])")
486 _ip.magic("timeit -n1 -r1 spaces.append([s.count(' ') for s in ['document']])")
485 assert _ip.user_ns['spaces'] == [[0]]
487 assert _ip.user_ns["spaces"] == [[0]]
486
488
487
489
488 def test_dirops():
490 def test_dirops():
489 """Test various directory handling operations."""
491 """Test various directory handling operations."""
General Comments 0
You need to be logged in to leave comments. Login now