##// END OF EJS Templates
Some reformatting of code
Jorgen Stenarson -
Show More
@@ -30,7 +30,7 b' try:'
30 except ImportError:
30 except ImportError:
31 #Fake _winreg module on none windows platforms
31 #Fake _winreg module on none windows platforms
32 import new
32 import new
33 sys.modules["_winreg"]=new.module("_winreg")
33 sys.modules["_winreg"] = new.module("_winreg")
34 import _winreg as wreg
34 import _winreg as wreg
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)
@@ -41,8 +41,8 b' def setup_environment():'
41 global oldstuff, platformstuff
41 global oldstuff, platformstuff
42 oldstuff = (env.copy(), os.name, genutils.get_home_dir, IPython.__file__,)
42 oldstuff = (env.copy(), os.name, genutils.get_home_dir, IPython.__file__,)
43
43
44 if os.name=='nt':
44 if os.name == 'nt':
45 platformstuff=(wreg.OpenKey, wreg.QueryValueEx,)
45 platformstuff = (wreg.OpenKey, wreg.QueryValueEx,)
46
46
47 if 'IPYTHONDIR' in env:
47 if 'IPYTHONDIR' in env:
48 del env['IPYTHONDIR']
48 del env['IPYTHONDIR']
@@ -55,10 +55,10 b' def teardown_environment():'
55 env.update(oldenv)
55 env.update(oldenv)
56 if hasattr(sys, 'frozen'):
56 if hasattr(sys, 'frozen'):
57 del sys.frozen
57 del sys.frozen
58 if os.name=='nt':
58 if os.name == 'nt':
59 (wreg.OpenKey, wreg.QueryValueEx,)=platformstuff
59 (wreg.OpenKey, wreg.QueryValueEx,) = platformstuff
60
60
61 with_enivronment=with_setup(setup_environment, teardown_environment)
61 with_enivronment = with_setup(setup_environment, teardown_environment)
62
62
63
63
64
64
@@ -72,13 +72,13 b' def test_get_home_dir_1():'
72 def test_get_home_dir_2():
72 def test_get_home_dir_2():
73 """Testcase for py2exe logic, un-compressed lib
73 """Testcase for py2exe logic, un-compressed lib
74 """
74 """
75 sys.frozen=True
75 sys.frozen = True
76
76
77 #fake filename for IPython.__init__
77 #fake filename for IPython.__init__
78 IPython.__file__=abspath(join(".", "home_test_dir/Lib/IPython/__init__.py"))
78 IPython.__file__ = abspath(join(".", "home_test_dir/Lib/IPython/__init__.py"))
79
79
80 home_dir = genutils.get_home_dir()
80 home_dir = genutils.get_home_dir()
81 assert home_dir==abspath(join(".", "home_test_dir"))
81 assert home_dir == abspath(join(".", "home_test_dir"))
82
82
83 @with_enivronment
83 @with_enivronment
84 def test_get_home_dir_3():
84 def test_get_home_dir_3():
@@ -86,24 +86,24 b' def test_get_home_dir_3():'
86 """
86 """
87 sys.frozen=True
87 sys.frozen=True
88 #fake filename for IPython.__init__
88 #fake filename for IPython.__init__
89 IPython.__file__=abspath(join(".", "home_test_dir/Library.zip/IPython/__init__.py"))
89 IPython.__file__ = abspath(join(".", "home_test_dir/Library.zip/IPython/__init__.py"))
90
90
91 home_dir = genutils.get_home_dir()
91 home_dir = genutils.get_home_dir()
92 assert home_dir==abspath(join(".", "home_test_dir")).lower()
92 assert home_dir == abspath(join(".", "home_test_dir")).lower()
93
93
94 @with_enivronment
94 @with_enivronment
95 def test_get_home_dir_4():
95 def test_get_home_dir_4():
96 """Testcase $HOME is set, then use its value as home directory."""
96 """Testcase $HOME is set, then use its value as home directory."""
97 env["HOME"]=join(".","home_test_dir")
97 env["HOME"] = join(".","home_test_dir")
98 home_dir = genutils.get_home_dir()
98 home_dir = genutils.get_home_dir()
99 assert home_dir==env["HOME"]
99 assert home_dir == env["HOME"]
100
100
101 @with_enivronment
101 @with_enivronment
102 def test_get_home_dir_5():
102 def test_get_home_dir_5():
103 """Testcase $HOME is not set, os=='posix'.
103 """Testcase $HOME is not set, os=='posix'.
104 This should fail with HomeDirError"""
104 This should fail with HomeDirError"""
105
105
106 os.name='posix'
106 os.name = 'posix'
107 del os.environ["HOME"]
107 del os.environ["HOME"]
108 try:
108 try:
109 genutils.get_home_dir()
109 genutils.get_home_dir()
@@ -116,12 +116,12 b' def test_get_home_dir_6():'
116 """Testcase $HOME is not set, os=='nt'
116 """Testcase $HOME is not set, os=='nt'
117 env['HOMEDRIVE'],env['HOMEPATH'] points to path."""
117 env['HOMEDRIVE'],env['HOMEPATH'] points to path."""
118
118
119 os.name='nt'
119 os.name = 'nt'
120 del os.environ["HOME"]
120 del os.environ["HOME"]
121 env['HOMEDRIVE'],env['HOMEPATH']=os.path.abspath("."),"home_test_dir"
121 env['HOMEDRIVE'],env['HOMEPATH'] = os.path.abspath("."),"home_test_dir"
122
122
123 home_dir = genutils.get_home_dir()
123 home_dir = genutils.get_home_dir()
124 assert home_dir==abspath(join(".", "home_test_dir"))
124 assert home_dir == abspath(join(".", "home_test_dir"))
125
125
126 @with_enivronment
126 @with_enivronment
127 def test_get_home_dir_8():
127 def test_get_home_dir_8():
@@ -130,13 +130,13 b' def test_get_home_dir_8():'
130 env['USERPROFILE'] points to path
130 env['USERPROFILE'] points to path
131 """
131 """
132
132
133 os.name='nt'
133 os.name = 'nt'
134 del os.environ["HOME"]
134 del os.environ["HOME"]
135 env['HOMEDRIVE'],env['HOMEPATH']=os.path.abspath("."),"DOES NOT EXIST"
135 env['HOMEDRIVE'],env['HOMEPATH'] = os.path.abspath("."),"DOES NOT EXIST"
136 env["USERPROFILE"]=abspath(join(".","home_test_dir"))
136 env["USERPROFILE"] = abspath(join(".","home_test_dir"))
137
137
138 home_dir = genutils.get_home_dir()
138 home_dir = genutils.get_home_dir()
139 assert home_dir==abspath(join(".", "home_test_dir"))
139 assert home_dir == abspath(join(".", "home_test_dir"))
140
140
141 # Should we stub wreg fully so we can run the test on all platforms?
141 # Should we stub wreg fully so we can run the test on all platforms?
142 #@skip_if_not_win32
142 #@skip_if_not_win32
@@ -145,23 +145,23 b' def test_get_home_dir_9():'
145 """Testcase $HOME is not set, os=='nt'
145 """Testcase $HOME is not set, os=='nt'
146 env['HOMEDRIVE'],env['HOMEPATH'], env['USERPROFILE'] missing
146 env['HOMEDRIVE'],env['HOMEPATH'], env['USERPROFILE'] missing
147 """
147 """
148 os.name='nt'
148 os.name = 'nt'
149 del env["HOME"],env['HOMEDRIVE']
149 del env["HOME"],env['HOMEDRIVE']
150
150
151 #Stub windows registry functions
151 #Stub windows registry functions
152 def OpenKey(x,y):
152 def OpenKey(x, y):
153 class key:
153 class key:
154 def Close(self):
154 def Close(self):
155 pass
155 pass
156 return key()
156 return key()
157 def QueryValueEx(x,y):
157 def QueryValueEx(x, y):
158 return [abspath(join(".", "home_test_dir"))]
158 return [abspath(join(".", "home_test_dir"))]
159
159
160 wreg.OpenKey=OpenKey
160 wreg.OpenKey = OpenKey
161 wreg.QueryValueEx=QueryValueEx
161 wreg.QueryValueEx = QueryValueEx
162
162
163 home_dir = genutils.get_home_dir()
163 home_dir = genutils.get_home_dir()
164 assert home_dir==abspath(join(".", "home_test_dir"))
164 assert home_dir == abspath(join(".", "home_test_dir"))
165
165
166
166
167 #
167 #
@@ -177,7 +177,7 b' def test_get_ipython_dir_1():'
177 @with_enivronment
177 @with_enivronment
178 def test_get_ipython_dir_2():
178 def test_get_ipython_dir_2():
179 """2 Testcase to see if we can call get_ipython_dir without Exceptions."""
179 """2 Testcase to see if we can call get_ipython_dir without Exceptions."""
180 env['IPYTHONDIR']="someplace/.ipython"
180 env['IPYTHONDIR'] = "someplace/.ipython"
181 ipdir = genutils.get_ipython_dir()
181 ipdir = genutils.get_ipython_dir()
182 assert ipdir == os.path.abspath("someplace/.ipython")
182 assert ipdir == os.path.abspath("someplace/.ipython")
183
183
@@ -186,15 +186,15 b' def test_get_ipython_dir_2():'
186 def test_get_ipython_dir_3():
186 def test_get_ipython_dir_3():
187 """3 Testcase to see if we can call get_ipython_dir without Exceptions."""
187 """3 Testcase to see if we can call get_ipython_dir without Exceptions."""
188 genutils.get_home_dir=lambda : "someplace"
188 genutils.get_home_dir=lambda : "someplace"
189 os.name="posix"
189 os.name = "posix"
190 ipdir = genutils.get_ipython_dir()
190 ipdir = genutils.get_ipython_dir()
191 assert ipdir == os.path.abspath(os.path.join("someplace", ".ipython"))
191 assert ipdir == os.path.abspath(os.path.join("someplace", ".ipython"))
192
192
193 @with_enivronment
193 @with_enivronment
194 def test_get_ipython_dir_4():
194 def test_get_ipython_dir_4():
195 """4 Testcase to see if we can call get_ipython_dir without Exceptions."""
195 """4 Testcase to see if we can call get_ipython_dir without Exceptions."""
196 genutils.get_home_dir=lambda : "someplace"
196 genutils.get_home_dir = lambda : "someplace"
197 os.name="nt"
197 os.name = "nt"
198 ipdir = genutils.get_ipython_dir()
198 ipdir = genutils.get_ipython_dir()
199 assert ipdir == os.path.abspath(os.path.join("someplace", "_ipython"))
199 assert ipdir == os.path.abspath(os.path.join("someplace", "_ipython"))
200
200
@@ -214,30 +214,30 b' def test_get_security_dir():'
214 #
214 #
215
215
216 def test_popkey_1():
216 def test_popkey_1():
217 dct=dict(a=1, b=2, c=3)
217 dct = dict(a=1, b=2, c=3)
218 assert genutils.popkey(dct, "a")==1
218 assert genutils.popkey(dct, "a") == 1
219 assert dct==dict(b=2, c=3)
219 assert dct == dict(b=2, c=3)
220 assert genutils.popkey(dct, "b")==2
220 assert genutils.popkey(dct, "b") == 2
221 assert dct==dict(c=3)
221 assert dct == dict(c=3)
222 assert genutils.popkey(dct, "c")==3
222 assert genutils.popkey(dct, "c") == 3
223 assert dct==dict()
223 assert dct == dict()
224
224
225 @raises(KeyError)
225 @raises(KeyError)
226 def test_popkey_2():
226 def test_popkey_2():
227 dct=dict(a=1, b=2, c=3)
227 dct = dict(a=1, b=2, c=3)
228 genutils.popkey(dct, "d")
228 genutils.popkey(dct, "d")
229
229
230 def test_popkey_3():
230 def test_popkey_3():
231 dct=dict(a=1, b=2, c=3)
231 dct = dict(a=1, b=2, c=3)
232 assert genutils.popkey(dct, "A", 13)==13
232 assert genutils.popkey(dct, "A", 13)==13
233 assert dct==dict(a=1, b=2, c=3)
233 assert dct == dict(a=1, b=2, c=3)
234 assert genutils.popkey(dct, "B", 14)==14
234 assert genutils.popkey(dct, "B", 14)==14
235 assert dct==dict(a=1, b=2, c=3)
235 assert dct == dict(a=1, b=2, c=3)
236 assert genutils.popkey(dct, "C", 15)==15
236 assert genutils.popkey(dct, "C", 15)==15
237 assert dct==dict(a=1, b=2, c=3)
237 assert dct == dict(a=1, b=2, c=3)
238 assert genutils.popkey(dct, "a")==1
238 assert genutils.popkey(dct, "a")==1
239 assert dct==dict(b=2, c=3)
239 assert dct == dict(b=2, c=3)
240 assert genutils.popkey(dct, "b")==2
240 assert genutils.popkey(dct, "b")==2
241 assert dct==dict(c=3)
241 assert dct == dict(c=3)
242 assert genutils.popkey(dct, "c")==3
242 assert genutils.popkey(dct, "c")==3
243 assert dct==dict()
243 assert dct == dict()
General Comments 0
You need to be logged in to leave comments. Login now