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