##// END OF EJS Templates
Removed pesky decorative quotes from the OTHER test function
Thomas Adriaan Hellinger -
Show More
@@ -1,62 +1,62 b''
1 from IPython.utils.capture import capture_output
1 from IPython.utils.capture import capture_output
2
2
3 import nose.tools as nt
3 import nose.tools as nt
4
4
5 def test_alias_lifecycle():
5 def test_alias_lifecycle():
6 name = 'test_alias1'
6 name = 'test_alias1'
7 cmd = 'echo "Hello"'
7 cmd = 'echo "Hello"'
8 am = _ip.alias_manager
8 am = _ip.alias_manager
9 am.clear_aliases()
9 am.clear_aliases()
10 am.define_alias(name, cmd)
10 am.define_alias(name, cmd)
11 assert am.is_alias(name)
11 assert am.is_alias(name)
12 nt.assert_equal(am.retrieve_alias(name), cmd)
12 nt.assert_equal(am.retrieve_alias(name), cmd)
13 nt.assert_in((name, cmd), am.aliases)
13 nt.assert_in((name, cmd), am.aliases)
14
14
15 # Test running the alias
15 # Test running the alias
16 orig_system = _ip.system
16 orig_system = _ip.system
17 result = []
17 result = []
18 _ip.system = result.append
18 _ip.system = result.append
19 try:
19 try:
20 _ip.run_cell('%{}'.format(name))
20 _ip.run_cell('%{}'.format(name))
21 result = [c.strip() for c in result]
21 result = [c.strip() for c in result]
22 nt.assert_equal(result, [cmd])
22 nt.assert_equal(result, [cmd])
23 finally:
23 finally:
24 _ip.system = orig_system
24 _ip.system = orig_system
25
25
26 # Test removing the alias
26 # Test removing the alias
27 am.undefine_alias(name)
27 am.undefine_alias(name)
28 assert not am.is_alias(name)
28 assert not am.is_alias(name)
29 with nt.assert_raises(ValueError):
29 with nt.assert_raises(ValueError):
30 am.retrieve_alias(name)
30 am.retrieve_alias(name)
31 nt.assert_not_in((name, cmd), am.aliases)
31 nt.assert_not_in((name, cmd), am.aliases)
32
32
33
33
34 def test_alias_args_error():
34 def test_alias_args_error():
35 """Error expanding with wrong number of arguments"""
35 """Error expanding with wrong number of arguments"""
36 _ip.alias_manager.define_alias('parts', 'echo first %s second %s')
36 _ip.alias_manager.define_alias('parts', 'echo first %s second %s')
37 # capture stderr:
37 # capture stderr:
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')
41 nt.assert_equal(cap.stderr.split(':')[0], 'UsageError')
42
42
43 def test_alias_args_commented():
43 def test_alias_args_commented():
44 """Check that alias correctly ignores 'commented out' args"""
44 """Check that alias correctly ignores 'commented out' args"""
45 _ip.magic('alias commetarg echo this is %%s a "commented out" arg')
45 _ip.magic('alias commetarg echo this is %%s a commented out arg')
46
46
47 with capture_output() as cap:
47 with capture_output() as cap:
48 _ip.run_cell('commetarg')
48 _ip.run_cell('commetarg')
49
49
50 nt.assert_equal(cap.stdout, 'this is %s a "commented out" arg')
50 nt.assert_equal(cap.stdout, 'this is %s a commented out arg')
51
51
52 def test_alias_args_commented_nargs():
52 def test_alias_args_commented_nargs():
53 """Check that alias correctly counts args, excluding those commented out"""
53 """Check that alias correctly counts args, excluding those commented out"""
54 am = _ip.alias_manager
54 am = _ip.alias_manager
55 alias_name = 'comargcount'
55 alias_name = 'comargcount'
56 cmd = 'echo this is %%s a commented out arg and this is not %s'
56 cmd = 'echo this is %%s a commented out arg and this is not %s'
57
57
58 am.define_alias(alias_name, cmd)
58 am.define_alias(alias_name, cmd)
59 assert am.is_alias(alias_name)
59 assert am.is_alias(alias_name)
60
60
61 thealias = am.get_alias(alias_name)
61 thealias = am.get_alias(alias_name)
62 nt.assert_equal(thealias.nargs, 1) No newline at end of file
62 nt.assert_equal(thealias.nargs, 1)
General Comments 0
You need to be logged in to leave comments. Login now