##// END OF EJS Templates
IPython.testing.decorators is imported as dec everywhere else, unify....
Thomas Spura -
Show More
@@ -1,50 +1,50 b''
1 # coding: utf-8
1 # coding: utf-8
2 """Tests for IPython.core.application"""
2 """Tests for IPython.core.application"""
3
3
4 import os
4 import os
5 import tempfile
5 import tempfile
6
6
7 from IPython.core.application import BaseIPythonApplication
7 from IPython.core.application import BaseIPythonApplication
8 from IPython.testing import decorators as testdec
8 from IPython.testing import decorators as dec
9 from IPython.utils import py3compat
9 from IPython.utils import py3compat
10
10
11 @testdec.onlyif_unicode_paths
11 @dec.onlyif_unicode_paths
12 def test_unicode_cwd():
12 def test_unicode_cwd():
13 """Check that IPython starts with non-ascii characters in the path."""
13 """Check that IPython starts with non-ascii characters in the path."""
14 wd = tempfile.mkdtemp(suffix=u"€")
14 wd = tempfile.mkdtemp(suffix=u"€")
15
15
16 old_wd = os.getcwdu()
16 old_wd = os.getcwdu()
17 os.chdir(wd)
17 os.chdir(wd)
18 #raise Exception(repr(os.getcwdu()))
18 #raise Exception(repr(os.getcwdu()))
19 try:
19 try:
20 app = BaseIPythonApplication()
20 app = BaseIPythonApplication()
21 # The lines below are copied from Application.initialize()
21 # The lines below are copied from Application.initialize()
22 app.init_profile_dir()
22 app.init_profile_dir()
23 app.init_config_files()
23 app.init_config_files()
24 app.load_config_file(suppress_errors=False)
24 app.load_config_file(suppress_errors=False)
25 finally:
25 finally:
26 os.chdir(old_wd)
26 os.chdir(old_wd)
27
27
28 @testdec.onlyif_unicode_paths
28 @dec.onlyif_unicode_paths
29 def test_unicode_ipdir():
29 def test_unicode_ipdir():
30 """Check that IPython starts with non-ascii characters in the IP dir."""
30 """Check that IPython starts with non-ascii characters in the IP dir."""
31 ipdir = tempfile.mkdtemp(suffix=u"€")
31 ipdir = tempfile.mkdtemp(suffix=u"€")
32
32
33 # Create the config file, so it tries to load it.
33 # Create the config file, so it tries to load it.
34 with open(os.path.join(ipdir, 'ipython_config.py'), "w") as f:
34 with open(os.path.join(ipdir, 'ipython_config.py'), "w") as f:
35 pass
35 pass
36
36
37 old_ipdir1 = os.environ.pop("IPYTHONDIR", None)
37 old_ipdir1 = os.environ.pop("IPYTHONDIR", None)
38 old_ipdir2 = os.environ.pop("IPYTHON_DIR", None)
38 old_ipdir2 = os.environ.pop("IPYTHON_DIR", None)
39 os.environ["IPYTHONDIR"] = py3compat.unicode_to_str(ipdir, "utf-8")
39 os.environ["IPYTHONDIR"] = py3compat.unicode_to_str(ipdir, "utf-8")
40 try:
40 try:
41 app = BaseIPythonApplication()
41 app = BaseIPythonApplication()
42 # The lines below are copied from Application.initialize()
42 # The lines below are copied from Application.initialize()
43 app.init_profile_dir()
43 app.init_profile_dir()
44 app.init_config_files()
44 app.init_config_files()
45 app.load_config_file(suppress_errors=False)
45 app.load_config_file(suppress_errors=False)
46 finally:
46 finally:
47 if old_ipdir1:
47 if old_ipdir1:
48 os.environ["IPYTHONDIR"] = old_ipdir1
48 os.environ["IPYTHONDIR"] = old_ipdir1
49 if old_ipdir2:
49 if old_ipdir2:
50 os.environ["IPYTHONDIR"] = old_ipdir2
50 os.environ["IPYTHONDIR"] = old_ipdir2
@@ -1,68 +1,68 b''
1 # encoding: utf-8
1 # encoding: utf-8
2 """
2 """
3 Test process execution and IO redirection.
3 Test process execution and IO redirection.
4 """
4 """
5
5
6 __docformat__ = "restructuredtext en"
6 __docformat__ = "restructuredtext en"
7
7
8 #-----------------------------------------------------------------------------
8 #-----------------------------------------------------------------------------
9 # Copyright (C) 2008-2011 The IPython Development Team
9 # Copyright (C) 2008-2011 The IPython Development Team
10 #
10 #
11 # Distributed under the terms of the BSD License. The full license is
11 # Distributed under the terms of the BSD License. The full license is
12 # in the file COPYING, distributed as part of this software.
12 # in the file COPYING, distributed as part of this software.
13 #-----------------------------------------------------------------------------
13 #-----------------------------------------------------------------------------
14
14
15 from cStringIO import StringIO
15 from cStringIO import StringIO
16 from time import sleep
16 from time import sleep
17 import sys
17 import sys
18
18
19 from IPython.frontend.process import PipedProcess
19 from IPython.frontend.process import PipedProcess
20 from IPython.testing import decorators as testdec
20 from IPython.testing import decorators as dec
21
21
22
22
23 def test_capture_out():
23 def test_capture_out():
24 """ A simple test to see if we can execute a process and get the output.
24 """ A simple test to see if we can execute a process and get the output.
25 """
25 """
26 s = StringIO()
26 s = StringIO()
27 p = PipedProcess('echo 1', out_callback=s.write, )
27 p = PipedProcess('echo 1', out_callback=s.write, )
28 p.start()
28 p.start()
29 p.join()
29 p.join()
30 result = s.getvalue().rstrip()
30 result = s.getvalue().rstrip()
31 assert result == '1'
31 assert result == '1'
32
32
33
33
34 def test_io():
34 def test_io():
35 """ Checks that we can send characters on stdin to the process.
35 """ Checks that we can send characters on stdin to the process.
36 """
36 """
37 s = StringIO()
37 s = StringIO()
38 p = PipedProcess(sys.executable + ' -c "a = raw_input(); print a"',
38 p = PipedProcess(sys.executable + ' -c "a = raw_input(); print a"',
39 out_callback=s.write, )
39 out_callback=s.write, )
40 p.start()
40 p.start()
41 test_string = '12345\n'
41 test_string = '12345\n'
42 while not hasattr(p, 'process'):
42 while not hasattr(p, 'process'):
43 sleep(0.1)
43 sleep(0.1)
44 p.process.stdin.write(test_string)
44 p.process.stdin.write(test_string)
45 p.join()
45 p.join()
46 result = s.getvalue()
46 result = s.getvalue()
47 assert result == test_string
47 assert result == test_string
48
48
49
49
50 @testdec.skip_win32
50 @dec.skip_win32
51 def test_kill():
51 def test_kill():
52 """ Check that we can kill a process, and its subprocess.
52 """ Check that we can kill a process, and its subprocess.
53 """
53 """
54 s = StringIO()
54 s = StringIO()
55 p = PipedProcess(sys.executable + ' -c "a = raw_input();"',
55 p = PipedProcess(sys.executable + ' -c "a = raw_input();"',
56 out_callback=s.write, )
56 out_callback=s.write, )
57 p.start()
57 p.start()
58 while not hasattr(p, 'process'):
58 while not hasattr(p, 'process'):
59 sleep(0.1)
59 sleep(0.1)
60 p.process.kill()
60 p.process.kill()
61 assert p.process.poll() is not None
61 assert p.process.poll() is not None
62
62
63
63
64 if __name__ == '__main__':
64 if __name__ == '__main__':
65 test_capture_out()
65 test_capture_out()
66 test_io()
66 test_io()
67 test_kill()
67 test_kill()
68
68
General Comments 0
You need to be logged in to leave comments. Login now