Show More
@@ -23,7 +23,7 b' from nose.tools import raises' | |||||
23 | import os, sys, IPython |
|
23 | import os, sys, IPython | |
24 | env = os.environ |
|
24 | env = os.environ | |
25 |
|
25 | |||
26 | from os.path import join, abspath |
|
26 | from os.path import join, abspath, split | |
27 |
|
27 | |||
28 | try: |
|
28 | try: | |
29 | import _winreg as wreg |
|
29 | import _winreg as wreg | |
@@ -35,6 +35,8 b' except ImportError:' | |||||
35 | #Add entries that needs to be stubbed by the testing code |
|
35 | #Add entries that needs to be stubbed by the testing code | |
36 | (wreg.OpenKey, wreg.QueryValueEx,) = (None, None) |
|
36 | (wreg.OpenKey, wreg.QueryValueEx,) = (None, None) | |
37 |
|
37 | |||
|
38 | test_file_path = split(abspath(__file__))[0] | |||
|
39 | ||||
38 | #skip_if_not_win32 = skipif(sys.platform!='win32',"This test only runs under Windows") |
|
40 | #skip_if_not_win32 = skipif(sys.platform!='win32',"This test only runs under Windows") | |
39 |
|
41 | |||
40 | def setup_environment(): |
|
42 | def setup_environment(): | |
@@ -75,10 +77,10 b' def test_get_home_dir_2():' | |||||
75 | sys.frozen = True |
|
77 | sys.frozen = True | |
76 |
|
78 | |||
77 | #fake filename for IPython.__init__ |
|
79 | #fake filename for IPython.__init__ | |
78 |
IPython.__file__ = abspath(join( |
|
80 | IPython.__file__ = abspath(join(test_file_path, "home_test_dir/Lib/IPython/__init__.py")) | |
79 |
|
81 | |||
80 | home_dir = genutils.get_home_dir() |
|
82 | home_dir = genutils.get_home_dir() | |
81 |
assert home_dir == abspath(join( |
|
83 | assert home_dir == abspath(join(test_file_path, "home_test_dir")) | |
82 |
|
84 | |||
83 | @with_enivronment |
|
85 | @with_enivronment | |
84 | def test_get_home_dir_3(): |
|
86 | def test_get_home_dir_3(): | |
@@ -86,15 +88,15 b' def test_get_home_dir_3():' | |||||
86 | """ |
|
88 | """ | |
87 | sys.frozen=True |
|
89 | sys.frozen=True | |
88 | #fake filename for IPython.__init__ |
|
90 | #fake filename for IPython.__init__ | |
89 |
IPython.__file__ = abspath(join( |
|
91 | IPython.__file__ = abspath(join(test_file_path, "home_test_dir/Library.zip/IPython/__init__.py")) | |
90 |
|
92 | |||
91 | home_dir = genutils.get_home_dir() |
|
93 | home_dir = genutils.get_home_dir() | |
92 |
assert home_dir == abspath(join( |
|
94 | assert home_dir == abspath(join(test_file_path, "home_test_dir")).lower() | |
93 |
|
95 | |||
94 | @with_enivronment |
|
96 | @with_enivronment | |
95 | def test_get_home_dir_4(): |
|
97 | def test_get_home_dir_4(): | |
96 | """Testcase $HOME is set, then use its value as home directory.""" |
|
98 | """Testcase $HOME is set, then use its value as home directory.""" | |
97 |
env["HOME"] = join( |
|
99 | env["HOME"] = join(test_file_path,"home_test_dir") | |
98 | home_dir = genutils.get_home_dir() |
|
100 | home_dir = genutils.get_home_dir() | |
99 | assert home_dir == env["HOME"] |
|
101 | assert home_dir == env["HOME"] | |
100 |
|
102 | |||
@@ -118,10 +120,10 b' def test_get_home_dir_6():' | |||||
118 |
|
120 | |||
119 | os.name = 'nt' |
|
121 | os.name = 'nt' | |
120 | del os.environ["HOME"] |
|
122 | del os.environ["HOME"] | |
121 |
env['HOMEDRIVE'],env['HOMEPATH'] = os.path.abspath( |
|
123 | env['HOMEDRIVE'],env['HOMEPATH'] = os.path.abspath(test_file_path),"home_test_dir" | |
122 |
|
124 | |||
123 | home_dir = genutils.get_home_dir() |
|
125 | home_dir = genutils.get_home_dir() | |
124 |
assert home_dir == abspath(join( |
|
126 | assert home_dir == abspath(join(test_file_path, "home_test_dir")) | |
125 |
|
127 | |||
126 | @with_enivronment |
|
128 | @with_enivronment | |
127 | def test_get_home_dir_8(): |
|
129 | def test_get_home_dir_8(): | |
@@ -132,11 +134,11 b' def test_get_home_dir_8():' | |||||
132 |
|
134 | |||
133 | os.name = 'nt' |
|
135 | os.name = 'nt' | |
134 | del os.environ["HOME"] |
|
136 | del os.environ["HOME"] | |
135 |
env['HOMEDRIVE'],env['HOMEPATH'] = os.path.abspath( |
|
137 | env['HOMEDRIVE'],env['HOMEPATH'] = os.path.abspath(test_file_path),"DOES NOT EXIST" | |
136 |
env["USERPROFILE"] = abspath(join( |
|
138 | env["USERPROFILE"] = abspath(join(test_file_path,"home_test_dir")) | |
137 |
|
139 | |||
138 | home_dir = genutils.get_home_dir() |
|
140 | home_dir = genutils.get_home_dir() | |
139 |
assert home_dir == abspath(join( |
|
141 | assert home_dir == abspath(join(test_file_path, "home_test_dir")) | |
140 |
|
142 | |||
141 | # Should we stub wreg fully so we can run the test on all platforms? |
|
143 | # Should we stub wreg fully so we can run the test on all platforms? | |
142 | #@skip_if_not_win32 |
|
144 | #@skip_if_not_win32 | |
@@ -155,13 +157,13 b' def test_get_home_dir_9():' | |||||
155 | pass |
|
157 | pass | |
156 | return key() |
|
158 | return key() | |
157 | def QueryValueEx(x, y): |
|
159 | def QueryValueEx(x, y): | |
158 |
return [abspath(join( |
|
160 | return [abspath(join(test_file_path, "home_test_dir"))] | |
159 |
|
161 | |||
160 | wreg.OpenKey = OpenKey |
|
162 | wreg.OpenKey = OpenKey | |
161 | wreg.QueryValueEx = QueryValueEx |
|
163 | wreg.QueryValueEx = QueryValueEx | |
162 |
|
164 | |||
163 | home_dir = genutils.get_home_dir() |
|
165 | home_dir = genutils.get_home_dir() | |
164 |
assert home_dir == abspath(join( |
|
166 | assert home_dir == abspath(join(test_file_path, "home_test_dir")) | |
165 |
|
167 | |||
166 |
|
168 | |||
167 | # |
|
169 | # |
General Comments 0
You need to be logged in to leave comments.
Login now