##// END OF EJS Templates
Merge pull request #8151 from brotherjack/master...
Thomas Kluyver -
r20905:e99285da merge
parent child Browse files
Show More
@@ -151,8 +151,8 b' class Alias(object):'
151 raise InvalidAliasError("An alias command must be a string, "
151 raise InvalidAliasError("An alias command must be a string, "
152 "got: %r" % self.cmd)
152 "got: %r" % self.cmd)
153
153
154 nargs = self.cmd.count('%s')
154 nargs = self.cmd.count('%s') - self.cmd.count('%%s')
155
155
156 if (nargs > 0) and (self.cmd.find('%l') >= 0):
156 if (nargs > 0) and (self.cmd.find('%l') >= 0):
157 raise InvalidAliasError('The %s and %l specifiers are mutually '
157 raise InvalidAliasError('The %s and %l specifiers are mutually '
158 'exclusive in alias definitions.')
158 'exclusive in alias definitions.')
@@ -169,7 +169,10 b' class Alias(object):'
169 if cmd.find('%l') >= 0:
169 if cmd.find('%l') >= 0:
170 cmd = cmd.replace('%l', rest)
170 cmd = cmd.replace('%l', rest)
171 rest = ''
171 rest = ''
172
172 if nargs==0:
173 if nargs==0:
174 if cmd.find('%%s') >= 1:
175 cmd = cmd.replace('%%s', '%s')
173 # Simple, argument-less aliases
176 # Simple, argument-less aliases
174 cmd = '%s %s' % (cmd, rest)
177 cmd = '%s %s' % (cmd, rest)
175 else:
178 else:
@@ -38,4 +38,25 b' def test_alias_args_error():'
38 with capture_output() as cap:
38 with capture_output() as cap:
39 _ip.run_cell('parts 1')
39 _ip.run_cell('parts 1')
40
40
41 nt.assert_equal(cap.stderr.split(':')[0], 'UsageError') No newline at end of file
41 nt.assert_equal(cap.stderr.split(':')[0], 'UsageError')
42
43 def test_alias_args_commented():
44 """Check that alias correctly ignores 'commented out' args"""
45 _ip.magic('alias commetarg echo this is %%s a commented out arg')
46
47 with capture_output() as cap:
48 _ip.run_cell('commetarg')
49
50 nt.assert_equal(cap.stdout, 'this is %s a commented out arg')
51
52 def test_alias_args_commented_nargs():
53 """Check that alias correctly counts args, excluding those commented out"""
54 am = _ip.alias_manager
55 alias_name = 'comargcount'
56 cmd = 'echo this is %%s a commented out arg and this is not %s'
57
58 am.define_alias(alias_name, cmd)
59 assert am.is_alias(alias_name)
60
61 thealias = am.get_alias(alias_name)
62 nt.assert_equal(thealias.nargs, 1) No newline at end of file
General Comments 0
You need to be logged in to leave comments. Login now