##// END OF EJS Templates
Fix startup directory test for Python 3.
Thomas Kluyver -
Show More
@@ -1,103 +1,103 b''
1 """Tests for profile-related functions.
1 """Tests for profile-related functions.
2
2
3 Currently only the startup-dir functionality is tested, but more tests should
3 Currently only the startup-dir functionality is tested, but more tests should
4 be added for:
4 be added for:
5
5
6 * ipython profile create
6 * ipython profile create
7 * ipython profile list
7 * ipython profile list
8 * ipython profile create --parallel
8 * ipython profile create --parallel
9 * security dir permissions
9 * security dir permissions
10
10
11 Authors
11 Authors
12 -------
12 -------
13
13
14 * MinRK
14 * MinRK
15
15
16 """
16 """
17 from __future__ import absolute_import
17 from __future__ import absolute_import
18
18
19 #-----------------------------------------------------------------------------
19 #-----------------------------------------------------------------------------
20 # Imports
20 # Imports
21 #-----------------------------------------------------------------------------
21 #-----------------------------------------------------------------------------
22
22
23 import os
23 import os
24 import shutil
24 import shutil
25 import sys
25 import sys
26 import tempfile
26 import tempfile
27
27
28 import nose.tools as nt
28 import nose.tools as nt
29 from nose import SkipTest
29 from nose import SkipTest
30
30
31 from IPython.core.profiledir import ProfileDir
31 from IPython.core.profiledir import ProfileDir
32
32
33 from IPython.testing import decorators as dec
33 from IPython.testing import decorators as dec
34 from IPython.testing import tools as tt
34 from IPython.testing import tools as tt
35 from IPython.utils import py3compat
35 from IPython.utils import py3compat
36
36
37
37
38 #-----------------------------------------------------------------------------
38 #-----------------------------------------------------------------------------
39 # Globals
39 # Globals
40 #-----------------------------------------------------------------------------
40 #-----------------------------------------------------------------------------
41 TMP_TEST_DIR = tempfile.mkdtemp()
41 TMP_TEST_DIR = tempfile.mkdtemp()
42 HOME_TEST_DIR = os.path.join(TMP_TEST_DIR, "home_test_dir")
42 HOME_TEST_DIR = os.path.join(TMP_TEST_DIR, "home_test_dir")
43 IP_TEST_DIR = os.path.join(HOME_TEST_DIR,'.ipython')
43 IP_TEST_DIR = os.path.join(HOME_TEST_DIR,'.ipython')
44
44
45 #
45 #
46 # Setup/teardown functions/decorators
46 # Setup/teardown functions/decorators
47 #
47 #
48
48
49 def setup():
49 def setup():
50 """Setup test environment for the module:
50 """Setup test environment for the module:
51
51
52 - Adds dummy home dir tree
52 - Adds dummy home dir tree
53 """
53 """
54 # Do not mask exceptions here. In particular, catching WindowsError is a
54 # Do not mask exceptions here. In particular, catching WindowsError is a
55 # problem because that exception is only defined on Windows...
55 # problem because that exception is only defined on Windows...
56 os.makedirs(IP_TEST_DIR)
56 os.makedirs(IP_TEST_DIR)
57
57
58
58
59 def teardown():
59 def teardown():
60 """Teardown test environment for the module:
60 """Teardown test environment for the module:
61
61
62 - Remove dummy home dir tree
62 - Remove dummy home dir tree
63 """
63 """
64 # Note: we remove the parent test dir, which is the root of all test
64 # Note: we remove the parent test dir, which is the root of all test
65 # subdirs we may have created. Use shutil instead of os.removedirs, so
65 # subdirs we may have created. Use shutil instead of os.removedirs, so
66 # that non-empty directories are all recursively removed.
66 # that non-empty directories are all recursively removed.
67 shutil.rmtree(TMP_TEST_DIR)
67 shutil.rmtree(TMP_TEST_DIR)
68
68
69
69
70 #-----------------------------------------------------------------------------
70 #-----------------------------------------------------------------------------
71 # Test functions
71 # Test functions
72 #-----------------------------------------------------------------------------
72 #-----------------------------------------------------------------------------
73
73
74 def test_startup_py():
74 def test_startup_py():
75 # create profile dir
75 # create profile dir
76 pd = ProfileDir.create_profile_dir_by_name(IP_TEST_DIR, 'test')
76 pd = ProfileDir.create_profile_dir_by_name(IP_TEST_DIR, 'test')
77 # write startup python file
77 # write startup python file
78 with open(os.path.join(pd.startup_dir, '00-start.py'), 'w') as f:
78 with open(os.path.join(pd.startup_dir, '00-start.py'), 'w') as f:
79 f.write('zzz=123\n')
79 f.write('zzz=123\n')
80 # write simple test file, to check that the startup file was run
80 # write simple test file, to check that the startup file was run
81 fname = os.path.join(TMP_TEST_DIR, 'test.py')
81 fname = os.path.join(TMP_TEST_DIR, 'test.py')
82 with open(fname, 'w') as f:
82 with open(fname, 'w') as f:
83 f.write('print zzz\n')
83 f.write(py3compat.doctest_refactor_print('print zzz\n'))
84 # validate output
84 # validate output
85 tt.ipexec_validate(fname, '123', '',
85 tt.ipexec_validate(fname, '123', '',
86 options=['--ipython-dir', IP_TEST_DIR, '--profile', 'test'])
86 options=['--ipython-dir', IP_TEST_DIR, '--profile', 'test'])
87
87
88 def test_startup_ipy():
88 def test_startup_ipy():
89 # create profile dir
89 # create profile dir
90 pd = ProfileDir.create_profile_dir_by_name(IP_TEST_DIR, 'test')
90 pd = ProfileDir.create_profile_dir_by_name(IP_TEST_DIR, 'test')
91 # write startup ipython file
91 # write startup ipython file
92 with open(os.path.join(pd.startup_dir, '00-start.ipy'), 'w') as f:
92 with open(os.path.join(pd.startup_dir, '00-start.ipy'), 'w') as f:
93 f.write('%profile\n')
93 f.write('%profile\n')
94 # write empty script, because we don't need anything to happen
94 # write empty script, because we don't need anything to happen
95 # after the startup file is run
95 # after the startup file is run
96 fname = os.path.join(TMP_TEST_DIR, 'test.py')
96 fname = os.path.join(TMP_TEST_DIR, 'test.py')
97 with open(fname, 'w') as f:
97 with open(fname, 'w') as f:
98 f.write('')
98 f.write('')
99 # validate output
99 # validate output
100 tt.ipexec_validate(fname, 'test', '',
100 tt.ipexec_validate(fname, 'test', '',
101 options=['--ipython-dir', IP_TEST_DIR, '--profile', 'test'])
101 options=['--ipython-dir', IP_TEST_DIR, '--profile', 'test'])
102
102
103 No newline at end of file
103
General Comments 0
You need to be logged in to leave comments. Login now