##// END OF EJS Templates
Added tests test_get_home_dir_3-test_get_home_dir_9...
Jorgen Stenarson -
Show More
@@ -931,13 +931,11 b' def get_home_dir():'
931 if hasattr(sys, "frozen"): #Is frozen by py2exe
931 if hasattr(sys, "frozen"): #Is frozen by py2exe
932 if '\\library.zip\\' in IPython.__file__.lower():#libraries compressed to zip-file
932 if '\\library.zip\\' in IPython.__file__.lower():#libraries compressed to zip-file
933 root, rest = IPython.__file__.lower().split('library.zip')
933 root, rest = IPython.__file__.lower().split('library.zip')
934 if isdir(root + '_ipython'):
935 os.environ["IPYKITROOT"] = root.rstrip('\\')
936 return root
937 else:
934 else:
938 root=os.path.abspath(os.path.join(os.path.split(IPython.__file__)[0],"../../"))
935 root=os.path.join(os.path.split(IPython.__file__)[0],"../../")
936 root=os.path.abspath(root).rstrip('\\')
939 if isdir(os.path.join(root, '_ipython')):
937 if isdir(os.path.join(root, '_ipython')):
940 os.environ["IPYKITROOT"] = root.rstrip('\\')
938 os.environ["IPYKITROOT"] = root
941 return root
939 return root
942 try:
940 try:
943 homedir = env['HOME']
941 homedir = env['HOME']
@@ -958,7 +956,7 b' def get_home_dir():'
958 if not isdir(homedir):
956 if not isdir(homedir):
959 raise HomeDirError
957 raise HomeDirError
960 return homedir
958 return homedir
961 except:
959 except KeyError:
962 try:
960 try:
963 # Use the registry to get the 'My Documents' folder.
961 # Use the registry to get the 'My Documents' folder.
964 import _winreg as wreg
962 import _winreg as wreg
@@ -16,31 +16,142 b' __docformat__ = "restructuredtext en"'
16 #-----------------------------------------------------------------------------
16 #-----------------------------------------------------------------------------
17
17
18 from IPython import genutils
18 from IPython import genutils
19 import os
19
20 import os, sys, IPython
20 env = os.environ
21 env = os.environ
21
22
23 from os.path import join, abspath
22
24
23 def test_get_home_dir_1():
25 def test_get_home_dir_1():
24 """Make sure we can get the home directory."""
26 """Testcase to see if we can call get_home_dir without Exceptions."""
25 home_dir = genutils.get_home_dir()
27 home_dir = genutils.get_home_dir()
26
28
27 def test_get_home_dir_2():
29 def test_get_home_dir_2():
28 """Make sure we can get the home directory."""
30 """Testcase for py2exe logic, un-compressed lib
29 old=env["HOME"]
31 """
30 env["HOME"]=os.path.join(".","home_test_dir")
32 sys.frozen=True
33 oldstuff=IPython.__file__
34
35 #fake filename for IPython.__init__
36 IPython.__file__=abspath(join(".", "home_test_dir/Lib/IPython/__init__.py"))
37
38 home_dir = genutils.get_home_dir()
39 assert home_dir==abspath(join(".", "home_test_dir"))
40 IPython.__file__=oldstuff
41 del sys.frozen
42
43 def test_get_home_dir_3():
44 """Testcase for py2exe logic, compressed lib
45 """
46
47 sys.frozen=True
48 oldstuff=IPython.__file__
49
50 #fake filename for IPython.__init__
51 IPython.__file__=abspath(join(".", "home_test_dir/Library.zip/IPython/__init__.py"))
52
53 home_dir = genutils.get_home_dir()
54 assert home_dir==abspath(join(".", "home_test_dir")).lower()
55
56 del sys.frozen
57 IPython.__file__=oldstuff
58
59
60 def test_get_home_dir_4():
61 """Testcase $HOME is set, then use its value as home directory."""
62 oldstuff=env["HOME"]
63
64 env["HOME"]=join(".","home_test_dir")
31 home_dir = genutils.get_home_dir()
65 home_dir = genutils.get_home_dir()
32 assert home_dir==env["HOME"]
66 assert home_dir==env["HOME"]
33 env["HOME"]=old
34
67
68 env["HOME"]=oldstuff
35
69
70 def test_get_home_dir_5():
71 """Testcase $HOME is not set, os=='posix'.
72 This should fail with HomeDirError"""
73 oldstuff=env["HOME"],os.name
74
75 os.name='posix'
76 del os.environ["HOME"]
77 try:
78 genutils.get_home_dir()
79 assert False
80 except genutils.HomeDirError:
81 pass
82 finally:
83 env["HOME"],os.name=oldstuff
84
85 def test_get_home_dir_6():
86 """Testcase $HOME is not set, os=='nt'
87 env['HOMEDRIVE'],env['HOMEPATH'] points to path."""
88
89 oldstuff=env["HOME"],os.name,env['HOMEDRIVE'],env['HOMEPATH']
90
91 os.name='nt'
92 del os.environ["HOME"]
93 env['HOMEDRIVE'],env['HOMEPATH']=os.path.abspath("."),"home_test_dir"
94
95 home_dir = genutils.get_home_dir()
96 assert home_dir==abspath(join(".", "home_test_dir"))
97
98 env["HOME"],os.name,env['HOMEDRIVE'],env['HOMEPATH']=oldstuff
99
100 def test_get_home_dir_8():
101 """Testcase $HOME is not set, os=='nt'
102 env['HOMEDRIVE'],env['HOMEPATH'] do not point to path.
103 env['USERPROFILE'] points to path
104 """
105 oldstuff=(env["HOME"],os.name,env['HOMEDRIVE'],env['HOMEPATH'])
106
107 os.name='nt'
108 del os.environ["HOME"]
109 env['HOMEDRIVE'],env['HOMEPATH']=os.path.abspath("."),"DOES NOT EXIST"
110 env["USERPROFILE"]=abspath(join(".","home_test_dir"))
36
111
112 home_dir = genutils.get_home_dir()
113 assert home_dir==abspath(join(".", "home_test_dir"))
114
115 (env["HOME"],os.name,env['HOMEDRIVE'],env['HOMEPATH'])=oldstuff
116
117 def test_get_home_dir_9():
118 """Testcase $HOME is not set, os=='nt'
119 env['HOMEDRIVE'],env['HOMEPATH'], env['USERPROFILE'] missing
120 """
121 import _winreg as wreg
122 oldstuff = (env["HOME"],os.name,env['HOMEDRIVE'],
123 env['HOMEPATH'],env["USERPROFILE"],
124 wreg.OpenKey, wreg.QueryValueEx,
125 )
126 os.name='nt'
127 del env["HOME"],env['HOMEDRIVE']
128
129 #Stub windows registry functions
130 def OpenKey(x,y):
131 class key:
132 def Close(self):
133 pass
134 return key()
135 def QueryValueEx(x,y):
136 return [abspath(join(".", "home_test_dir"))]
137
138 wreg.OpenKey=OpenKey
139 wreg.QueryValueEx=QueryValueEx
140
141
142 home_dir = genutils.get_home_dir()
143 assert home_dir==abspath(join(".", "home_test_dir"))
37
144
145 (env["HOME"],os.name,env['HOMEDRIVE'],
146 env['HOMEPATH'],env["USERPROFILE"],
147 wreg.OpenKey, wreg.QueryValueEx,) = oldstuff
148
38
149
39 def test_get_ipython_dir():
150 def test_get_ipython_dir():
40 """Make sure we can get the ipython directory."""
151 """Testcase to see if we can call get_ipython_dir without Exceptions."""
41 ipdir = genutils.get_ipython_dir()
152 ipdir = genutils.get_ipython_dir()
42
153
43 def test_get_security_dir():
154 def test_get_security_dir():
44 """Make sure we can get the ipython/security directory."""
155 """Testcase to see if we can call get_security_dir without Exceptions."""
45 sdir = genutils.get_security_dir()
156 sdir = genutils.get_security_dir()
46 No newline at end of file
157
General Comments 0
You need to be logged in to leave comments. Login now