##// END OF EJS Templates
Merge pull request #8151 from brotherjack/master...
Thomas Kluyver -
r20905:e99285da merge
parent child Browse files
Show More
@@ -151,7 +151,7 b' class Alias(object):'
151 151 raise InvalidAliasError("An alias command must be a string, "
152 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 156 if (nargs > 0) and (self.cmd.find('%l') >= 0):
157 157 raise InvalidAliasError('The %s and %l specifiers are mutually '
@@ -169,7 +169,10 b' class Alias(object):'
169 169 if cmd.find('%l') >= 0:
170 170 cmd = cmd.replace('%l', rest)
171 171 rest = ''
172
172 173 if nargs==0:
174 if cmd.find('%%s') >= 1:
175 cmd = cmd.replace('%%s', '%s')
173 176 # Simple, argument-less aliases
174 177 cmd = '%s %s' % (cmd, rest)
175 178 else:
@@ -39,3 +39,24 b' def test_alias_args_error():'
39 39 _ip.run_cell('parts 1')
40 40
41 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