22
33import pytest
44
5+
56def test_alias_lifecycle ():
6- name = ' test_alias1'
7+ name = " test_alias1"
78 cmd = 'echo "Hello"'
89 am = _ip .alias_manager
910 am .clear_aliases ()
1011 am .define_alias (name , cmd )
1112 assert am .is_alias (name )
1213 assert am .retrieve_alias (name ) == cmd
1314 assert (name , cmd ) in am .aliases
14-
15+
1516 # Test running the alias
1617 orig_system = _ip .system
1718 result = []
1819 _ip .system = result .append
1920 try :
20- _ip .run_cell (' %{}' .format (name ))
21+ _ip .run_cell (" %{}" .format (name ))
2122 result = [c .strip () for c in result ]
2223 assert result == [cmd ]
2324 finally :
2425 _ip .system = orig_system
25-
26+
2627 # Test removing the alias
2728 am .undefine_alias (name )
2829 assert not am .is_alias (name )
2930 with pytest .raises (ValueError ):
3031 am .retrieve_alias (name )
3132 assert (name , cmd ) not in am .aliases
32-
33+
3334
3435def test_alias_args_error ():
3536 """Error expanding with wrong number of arguments"""
36- _ip .alias_manager .define_alias (' parts' , ' echo first %s second %s' )
37+ _ip .alias_manager .define_alias (" parts" , " echo first %s second %s" )
3738 # capture stderr:
3839 with capture_output () as cap :
39- _ip .run_cell (' parts 1' )
40+ _ip .run_cell (" parts 1" )
4041
4142 assert cap .stderr .split (":" )[0 ] == "UsageError"
4243
@@ -51,16 +52,17 @@ def test_alias_args_commented():
5152 # strip() is for pytest compat; testing via iptest patch IPython shell
5253 # in testing.globalipapp and replace the system call which messed up the
5354 # \r\n
54- assert cap .stdout .strip () == 'this is %s a commented out arg'
55+ assert cap .stdout .strip () == "this is %s a commented out arg"
56+
5557
5658def test_alias_args_commented_nargs ():
5759 """Check that alias correctly counts args, excluding those commented out"""
5860 am = _ip .alias_manager
59- alias_name = ' comargcount'
60- cmd = ' echo this is %%s a commented out arg and this is not %s'
61-
61+ alias_name = " comargcount"
62+ cmd = " echo this is %%s a commented out arg and this is not %s"
63+
6264 am .define_alias (alias_name , cmd )
6365 assert am .is_alias (alias_name )
64-
66+
6567 thealias = am .get_alias (alias_name )
6668 assert thealias .nargs == 1
0 commit comments