Show More
@@ -6,7 +6,6 b' import tempfile' | |||||
6 | import warnings |
|
6 | import warnings | |
7 | from unittest.mock import patch |
|
7 | from unittest.mock import patch | |
8 |
|
8 | |||
9 | import nose.tools as nt |
|
|||
10 | from testpath import modified_env, assert_isdir, assert_isfile |
|
9 | from testpath import modified_env, assert_isdir, assert_isfile | |
11 |
|
10 | |||
12 | from IPython import paths |
|
11 | from IPython import paths | |
@@ -52,7 +51,7 b' def test_get_ipython_dir_1():' | |||||
52 | modified_env({'IPYTHONDIR': env_ipdir}): |
|
51 | modified_env({'IPYTHONDIR': env_ipdir}): | |
53 | ipdir = paths.get_ipython_dir() |
|
52 | ipdir = paths.get_ipython_dir() | |
54 |
|
53 | |||
55 |
|
|
54 | assert ipdir == env_ipdir | |
56 |
|
55 | |||
57 | def test_get_ipython_dir_2(): |
|
56 | def test_get_ipython_dir_2(): | |
58 | """test_get_ipython_dir_2, Testcase to see if we can call get_ipython_dir without Exceptions.""" |
|
57 | """test_get_ipython_dir_2, Testcase to see if we can call get_ipython_dir without Exceptions.""" | |
@@ -66,7 +65,7 b' def test_get_ipython_dir_2():' | |||||
66 | }): |
|
65 | }): | |
67 | ipdir = paths.get_ipython_dir() |
|
66 | ipdir = paths.get_ipython_dir() | |
68 |
|
67 | |||
69 |
|
|
68 | assert ipdir == os.path.join("someplace", ".ipython") | |
70 |
|
69 | |||
71 | def test_get_ipython_dir_3(): |
|
70 | def test_get_ipython_dir_3(): | |
72 | """test_get_ipython_dir_3, move XDG if defined, and .ipython doesn't exist.""" |
|
71 | """test_get_ipython_dir_3, move XDG if defined, and .ipython doesn't exist.""" | |
@@ -81,10 +80,10 b' def test_get_ipython_dir_3():' | |||||
81 | }), warnings.catch_warnings(record=True) as w: |
|
80 | }), warnings.catch_warnings(record=True) as w: | |
82 | ipdir = paths.get_ipython_dir() |
|
81 | ipdir = paths.get_ipython_dir() | |
83 |
|
82 | |||
84 |
|
|
83 | assert ipdir == os.path.join(tmphome.name, ".ipython") | |
85 | if sys.platform != 'darwin': |
|
84 | if sys.platform != 'darwin': | |
86 |
|
|
85 | assert len(w) == 1 | |
87 |
|
|
86 | assert "Moving" in str(w[0]) | |
88 | finally: |
|
87 | finally: | |
89 | tmphome.cleanup() |
|
88 | tmphome.cleanup() | |
90 |
|
89 | |||
@@ -106,10 +105,11 b' def test_get_ipython_dir_4():' | |||||
106 | }), warnings.catch_warnings(record=True) as w: |
|
105 | }), warnings.catch_warnings(record=True) as w: | |
107 | ipdir = paths.get_ipython_dir() |
|
106 | ipdir = paths.get_ipython_dir() | |
108 |
|
107 | |||
109 |
|
|
108 | assert ipdir == os.path.join(HOME_TEST_DIR, ".ipython") | |
110 | if sys.platform != 'darwin': |
|
109 | if sys.platform != 'darwin': | |
111 |
|
|
110 | assert len(w) == 1 | |
112 |
|
|
111 | assert "Ignoring" in str(w[0]) | |
|
112 | ||||
113 |
|
113 | |||
114 | def test_get_ipython_dir_5(): |
|
114 | def test_get_ipython_dir_5(): | |
115 | """test_get_ipython_dir_5, use .ipython if exists and XDG defined, but doesn't exist.""" |
|
115 | """test_get_ipython_dir_5, use .ipython if exists and XDG defined, but doesn't exist.""" | |
@@ -128,7 +128,7 b' def test_get_ipython_dir_5():' | |||||
128 | }): |
|
128 | }): | |
129 | ipdir = paths.get_ipython_dir() |
|
129 | ipdir = paths.get_ipython_dir() | |
130 |
|
130 | |||
131 |
|
|
131 | assert ipdir == IP_TEST_DIR | |
132 |
|
132 | |||
133 | def test_get_ipython_dir_6(): |
|
133 | def test_get_ipython_dir_6(): | |
134 | """test_get_ipython_dir_6, use home over XDG if defined and neither exist.""" |
|
134 | """test_get_ipython_dir_6, use home over XDG if defined and neither exist.""" | |
@@ -146,8 +146,8 b' def test_get_ipython_dir_6():' | |||||
146 | }), warnings.catch_warnings(record=True) as w: |
|
146 | }), warnings.catch_warnings(record=True) as w: | |
147 | ipdir = paths.get_ipython_dir() |
|
147 | ipdir = paths.get_ipython_dir() | |
148 |
|
148 | |||
149 |
|
|
149 | assert ipdir == os.path.join(HOME_TEST_DIR, ".ipython") | |
150 |
|
|
150 | assert len(w) == 0 | |
151 |
|
151 | |||
152 | def test_get_ipython_dir_7(): |
|
152 | def test_get_ipython_dir_7(): | |
153 | """test_get_ipython_dir_7, test home directory expansion on IPYTHONDIR""" |
|
153 | """test_get_ipython_dir_7, test home directory expansion on IPYTHONDIR""" | |
@@ -155,7 +155,8 b' def test_get_ipython_dir_7():' | |||||
155 | with modified_env({'IPYTHONDIR': os.path.join('~', 'somewhere')}), \ |
|
155 | with modified_env({'IPYTHONDIR': os.path.join('~', 'somewhere')}), \ | |
156 | patch.object(paths, '_writable_dir', return_value=True): |
|
156 | patch.object(paths, '_writable_dir', return_value=True): | |
157 | ipdir = paths.get_ipython_dir() |
|
157 | ipdir = paths.get_ipython_dir() | |
158 |
|
|
158 | assert ipdir == os.path.join(home_dir, "somewhere") | |
|
159 | ||||
159 |
|
160 | |||
160 | @skip_win32 |
|
161 | @skip_win32 | |
161 | def test_get_ipython_dir_8(): |
|
162 | def test_get_ipython_dir_8(): | |
@@ -164,14 +165,16 b' def test_get_ipython_dir_8():' | |||||
164 | # test only when HOME directory actually writable |
|
165 | # test only when HOME directory actually writable | |
165 | return |
|
166 | return | |
166 |
|
167 | |||
167 |
with patch.object(paths, |
|
168 | with patch.object(paths, "_writable_dir", lambda path: bool(path)), patch.object( | |
168 |
|
|
169 | paths, "get_xdg_dir", return_value=None | |
169 |
|
|
170 | ), modified_env( | |
170 | 'IPYTHON_DIR': None, |
|
171 | { | |
171 |
|
|
172 | "IPYTHON_DIR": None, | |
172 | 'HOME': '/', |
|
173 | "IPYTHONDIR": None, | |
173 |
|
|
174 | "HOME": "/", | |
174 | nt.assert_equal(paths.get_ipython_dir(), '/.ipython') |
|
175 | } | |
|
176 | ): | |||
|
177 | assert paths.get_ipython_dir() == "/.ipython" | |||
175 |
|
178 | |||
176 |
|
179 | |||
177 | def test_get_ipython_cache_dir(): |
|
180 | def test_get_ipython_cache_dir(): | |
@@ -181,18 +184,16 b' def test_get_ipython_cache_dir():' | |||||
181 | os.makedirs(os.path.join(HOME_TEST_DIR, ".cache")) |
|
184 | os.makedirs(os.path.join(HOME_TEST_DIR, ".cache")) | |
182 | with modified_env({'XDG_CACHE_HOME': None}): |
|
185 | with modified_env({'XDG_CACHE_HOME': None}): | |
183 | ipdir = paths.get_ipython_cache_dir() |
|
186 | ipdir = paths.get_ipython_cache_dir() | |
184 |
|
|
187 | assert os.path.join(HOME_TEST_DIR, ".cache", "ipython") == ipdir | |
185 | ipdir) |
|
|||
186 | assert_isdir(ipdir) |
|
188 | assert_isdir(ipdir) | |
187 |
|
189 | |||
188 | # test env override |
|
190 | # test env override | |
189 | with modified_env({"XDG_CACHE_HOME": XDG_CACHE_DIR}): |
|
191 | with modified_env({"XDG_CACHE_HOME": XDG_CACHE_DIR}): | |
190 | ipdir = paths.get_ipython_cache_dir() |
|
192 | ipdir = paths.get_ipython_cache_dir() | |
191 | assert_isdir(ipdir) |
|
193 | assert_isdir(ipdir) | |
192 |
|
|
194 | assert ipdir == os.path.join(XDG_CACHE_DIR, "ipython") | |
193 | else: |
|
195 | else: | |
194 |
|
|
196 | assert paths.get_ipython_cache_dir() == paths.get_ipython_dir() | |
195 | paths.get_ipython_dir()) |
|
|||
196 |
|
197 | |||
197 | def test_get_ipython_package_dir(): |
|
198 | def test_get_ipython_package_dir(): | |
198 | ipdir = paths.get_ipython_package_dir() |
|
199 | ipdir = paths.get_ipython_package_dir() |
General Comments 0
You need to be logged in to leave comments.
Login now