Show More
@@ -22,6 +22,11 b' import tempfile' | |||
|
22 | 22 | import warnings |
|
23 | 23 | from contextlib import contextmanager |
|
24 | 24 | |
|
25 | try: # Python 3.3+ | |
|
26 | from unittest.mock import patch | |
|
27 | except ImportError: | |
|
28 | from mock import patch | |
|
29 | ||
|
25 | 30 | from os.path import join, abspath, split |
|
26 | 31 | |
|
27 | 32 | import nose.tools as nt |
@@ -107,10 +112,6 b' def setup_environment():' | |||
|
107 | 112 | global oldstuff, platformstuff |
|
108 | 113 | oldstuff = (env.copy(), os.name, sys.platform, path.get_home_dir, IPython.__file__, os.getcwd()) |
|
109 | 114 | |
|
110 | if os.name == 'nt': | |
|
111 | platformstuff = (wreg.OpenKey, wreg.QueryValueEx,) | |
|
112 | ||
|
113 | ||
|
114 | 115 | def teardown_environment(): |
|
115 | 116 | """Restore things that were remembered by the setup_environment function |
|
116 | 117 | """ |
@@ -124,8 +125,6 b' def teardown_environment():' | |||
|
124 | 125 | env.update(oldenv) |
|
125 | 126 | if hasattr(sys, 'frozen'): |
|
126 | 127 | del sys.frozen |
|
127 | if os.name == 'nt': | |
|
128 | (wreg.OpenKey, wreg.QueryValueEx,) = platformstuff | |
|
129 | 128 | |
|
130 | 129 | # Build decorator that uses the setup_environment/setup_environment |
|
131 | 130 | with_environment = with_setup(setup_environment, teardown_environment) |
@@ -193,7 +192,6 b' def test_get_home_dir_5():' | |||
|
193 | 192 | os.name = 'posix' |
|
194 | 193 | nt.assert_raises(path.HomeDirError, path.get_home_dir, True) |
|
195 | 194 | |
|
196 | ||
|
197 | 195 | # Should we stub wreg fully so we can run the test on all platforms? |
|
198 | 196 | @skip_if_not_win32 |
|
199 | 197 | @with_environment |
@@ -207,18 +205,12 b' def test_get_home_dir_8():' | |||
|
207 | 205 | for key in ['HOME', 'HOMESHARE', 'HOMEDRIVE', 'HOMEPATH', 'USERPROFILE']: |
|
208 | 206 | env.pop(key, None) |
|
209 | 207 | |
|
210 | #Stub windows registry functions | |
|
211 | def OpenKey(x, y): | |
|
212 | 208 |
|
|
213 | 209 |
|
|
214 | 210 |
|
|
215 | return key() | |
|
216 | def QueryValueEx(x, y): | |
|
217 | return [abspath(HOME_TEST_DIR)] | |
|
218 | ||
|
219 | wreg.OpenKey = OpenKey | |
|
220 | wreg.QueryValueEx = QueryValueEx | |
|
221 | 211 | |
|
212 | with patch.object(wreg, 'OpenKey', return_value=key()), \ | |
|
213 | patch.object(wreg, 'QueryValueEx', return_value=[abspath(HOME_TEST_DIR)]): | |
|
222 | 214 | home_dir = path.get_home_dir() |
|
223 | 215 | nt.assert_equal(home_dir, abspath(HOME_TEST_DIR)) |
|
224 | 216 |
General Comments 0
You need to be logged in to leave comments.
Login now