13
|
1 |
#
|
|
2 |
# Copyright (c) 2009-2010 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
# All rights reserved.
|
|
4 |
# This component and the accompanying materials are made available
|
|
5 |
# under the terms of the License "Eclipse Public License v1.0"
|
|
6 |
# which accompanies this distribution, and is available
|
|
7 |
# at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
#
|
|
9 |
# Initial Contributors:
|
|
10 |
# Nokia Corporation - initial contribution.
|
|
11 |
#
|
|
12 |
# Contributors:
|
|
13 |
#
|
|
14 |
# Description:
|
|
15 |
#
|
|
16 |
|
|
17 |
import generic_path
|
|
18 |
import unittest
|
|
19 |
import os
|
|
20 |
import sys
|
|
21 |
import re
|
|
22 |
|
|
23 |
class TestGenericPaths(unittest.TestCase):
|
|
24 |
|
|
25 |
def setUp(self):
|
|
26 |
self.cwd = os.getcwd().replace("\\", "/")
|
|
27 |
|
|
28 |
def isWin32(self):
|
|
29 |
return sys.platform.lower().startswith("win")
|
|
30 |
|
|
31 |
|
|
32 |
def testClassCommon(self):
|
|
33 |
|
|
34 |
p1 = generic_path.Path("a", "b")
|
|
35 |
|
|
36 |
p2 = p1.Append("c")
|
|
37 |
self.assertEqual(str(p2), "a/b/c")
|
|
38 |
|
|
39 |
p3 = p1.Append("c", "d")
|
|
40 |
self.assertEqual(str(p3), "a/b/c/d")
|
|
41 |
|
|
42 |
p4 = p1.Prepend("z")
|
|
43 |
self.assertEqual(str(p4), "z/a/b")
|
|
44 |
|
|
45 |
p5 = p1.Prepend("y", "z")
|
|
46 |
self.assertEqual(str(p5), "y/z/a/b")
|
|
47 |
|
|
48 |
self.assertEqual(str(p5.Dir()), "y/z/a")
|
|
49 |
self.assertEqual(p5.File(), "b")
|
|
50 |
|
|
51 |
p6 = generic_path.Join("test")
|
|
52 |
self.assertEqual(str(p6.Dir()), "")
|
|
53 |
self.assertEqual(p6.File(), "test")
|
|
54 |
|
|
55 |
|
|
56 |
def testClassWin32(self):
|
|
57 |
if not self.isWin32():
|
|
58 |
return
|
|
59 |
|
|
60 |
local1 = generic_path.Path('some\\folder\\another\\')
|
|
61 |
local2 = generic_path.Join(local1, "test", "tmp")
|
|
62 |
|
|
63 |
self.assertEqual(str(local2),"some/folder/another/test/tmp")
|
|
64 |
|
|
65 |
# Absolute
|
|
66 |
|
|
67 |
local1 = generic_path.Path('some\\folder')
|
|
68 |
self.failIf(local1.isAbsolute())
|
|
69 |
|
|
70 |
abs1 = local1.Absolute()
|
|
71 |
self.assertEqual(str(abs1).lower(), (self.cwd + "/some/folder").lower())
|
|
72 |
|
|
73 |
local2 = generic_path.Path('C:\\some\\folder')
|
|
74 |
self.failUnless(local2.isAbsolute())
|
|
75 |
|
|
76 |
abs2 = local2.Absolute()
|
|
77 |
self.assertEqual(str(abs2), "C:/some/folder")
|
|
78 |
|
|
79 |
local3 = generic_path.Path('\\somerandomfolder')
|
|
80 |
self.failUnless(re.match('^[A-Za-z]:/somerandomfolder$',str(local3)))
|
|
81 |
|
|
82 |
local4 = generic_path.Path('\\my\\folder\\')
|
|
83 |
self.failUnless(re.match('^[A-Za-z]:/my/folder$',str(local4)))
|
|
84 |
|
|
85 |
local5 = generic_path.Path('\\')
|
|
86 |
self.failUnless(re.match('^[A-Za-z]:$',str(local5)))
|
|
87 |
|
|
88 |
local6 = generic_path.Path("C:")
|
|
89 |
self.failUnless(local6.isAbsolute())
|
|
90 |
self.failUnless(local6.isDir())
|
|
91 |
self.failUnless(local6.Exists())
|
|
92 |
|
|
93 |
local7 = local6.Absolute()
|
|
94 |
self.assertEqual(str(local7), "C:")
|
|
95 |
|
|
96 |
local8 = generic_path.Path("C:/")
|
|
97 |
self.failUnless(local8.isAbsolute())
|
|
98 |
self.failUnless(local8.isDir())
|
|
99 |
self.failUnless(local8.Exists())
|
|
100 |
|
|
101 |
local9 = local8.Absolute()
|
|
102 |
self.assertEqual(str(local9), "C:")
|
|
103 |
|
|
104 |
# Drives
|
|
105 |
|
|
106 |
driveD = generic_path.Path("D:\\", "folder")
|
|
107 |
self.assertEqual(str(driveD), "D:/folder")
|
|
108 |
|
|
109 |
driveA = generic_path.Path("a:\\")
|
|
110 |
self.assertEqual(str(driveA), "a:")
|
|
111 |
self.assertEqual(str(driveA.Dir()), "a:")
|
|
112 |
|
|
113 |
driveZ = generic_path.Path("Z:\\test")
|
|
114 |
self.assertEqual(str(driveZ), "Z:/test")
|
|
115 |
|
|
116 |
joinC = generic_path.Join("C:\\", "something")
|
|
117 |
self.assertEqual(str(joinC), "C:/something")
|
|
118 |
|
|
119 |
joinM = generic_path.Join("M:", "something")
|
|
120 |
self.assertEqual(str(joinM), "M:/something")
|
|
121 |
|
|
122 |
# Path
|
|
123 |
|
|
124 |
path2 = generic_path.Path("m:/sys/thing/")
|
|
125 |
self.assertEqual(str(path2), "m:/sys/thing")
|
|
126 |
|
|
127 |
path3 = generic_path.Path("m:\\sys\\thing\\")
|
|
128 |
self.assertEqual(str(path3), "m:/sys/thing")
|
|
129 |
|
|
130 |
path4 = generic_path.Path("m:\\")
|
|
131 |
self.assertEqual(str(path4), "m:")
|
|
132 |
|
|
133 |
path5 = generic_path.Path("\\sys\\thing\\")
|
|
134 |
self.failUnless(re.match('^[A-Za-z]:/sys/thing$', str(path5)))
|
|
135 |
|
|
136 |
path6 = generic_path.Path("m:/")
|
|
137 |
self.assertEqual(str(path6), "m:")
|
|
138 |
|
|
139 |
# SpaceSafePath
|
|
140 |
|
|
141 |
epocroot = os.path.abspath(os.environ.get('EPOCROOT')).replace('\\','/').rstrip('/')
|
|
142 |
pathwithspaces = epocroot+"/epoc32/build/Program Files/Some tool installed with spaces/no_spaces/s p c/no_more_spaces"
|
|
143 |
path7 = generic_path.Path(pathwithspaces)
|
|
144 |
|
|
145 |
# SpaceSafe paths on Windows are 8.3 format, and these can only be deduced if they actually exist.
|
|
146 |
os.makedirs(pathwithspaces)
|
|
147 |
spacesafe = path7.GetSpaceSafePath()
|
|
148 |
self.assertTrue(spacesafe.endswith("PROGRA~1/SOMETO~1/NO_SPA~1/SPC~1/NO_MOR~1"))
|
|
149 |
|
|
150 |
os.removedirs(pathwithspaces)
|
|
151 |
spacesafe = path7.GetSpaceSafePath()
|
|
152 |
self.assertEqual(spacesafe, None)
|
|
153 |
|
|
154 |
|
|
155 |
def testClassLinux(self):
|
|
156 |
if self.isWin32():
|
|
157 |
return
|
|
158 |
|
|
159 |
local1 = generic_path.Path('some/folder/another/')
|
|
160 |
local2 = generic_path.Join(local1, "test", "tmp")
|
|
161 |
|
|
162 |
self.assertEqual(str(local2),"some/folder/another/test/tmp")
|
|
163 |
|
|
164 |
msys1 = generic_path.Path('some/folder/another/')
|
|
165 |
msys2 = generic_path.Join(msys1, "test", "tmp")
|
|
166 |
|
|
167 |
self.assertEqual(str(msys2),"some/folder/another/test/tmp")
|
|
168 |
|
|
169 |
# Absolute
|
|
170 |
|
|
171 |
local1 = generic_path.Path('some/folder')
|
|
172 |
self.failIf(local1.isAbsolute())
|
|
173 |
|
|
174 |
abs1 = local1.Absolute()
|
|
175 |
self.assertEqual(str(abs1), self.cwd + "/some/folder")
|
|
176 |
|
|
177 |
local2 = generic_path.Path('/some/folder')
|
|
178 |
self.failUnless(local2.isAbsolute())
|
|
179 |
|
|
180 |
abs2 = local2.Absolute()
|
|
181 |
self.assertEqual(str(abs2), "/some/folder")
|
|
182 |
|
|
183 |
root = generic_path.Path("/")
|
|
184 |
self.assertEqual(str(root), "/")
|
|
185 |
|
|
186 |
# Path
|
|
187 |
|
|
188 |
path = generic_path.Path("some/thing/")
|
|
189 |
self.assertEqual(str(path), "some/thing")
|
|
190 |
|
|
191 |
# SpaceSafePath
|
|
192 |
|
|
193 |
# This doesn't mean much on non-Windows platforms, but we confirm nothing breaks if it is used
|
|
194 |
pathwithspaces = "/Program Files/Some tool installed with spaces/no_spaces/s p c/no_more_spaces"
|
|
195 |
path2 = generic_path.Path(pathwithspaces)
|
|
196 |
|
|
197 |
spacesafe = path2.GetSpaceSafePath()
|
|
198 |
self.assertEqual(spacesafe, None)
|
|
199 |
|
|
200 |
|
|
201 |
# run all the tests
|
|
202 |
|
|
203 |
from raptor_tests import SmokeTest
|
|
204 |
|
|
205 |
def run():
|
|
206 |
t = SmokeTest()
|
|
207 |
t.id = "999"
|
|
208 |
t.name = "generic_path_unit"
|
|
209 |
|
|
210 |
tests = unittest.makeSuite(TestGenericPaths)
|
|
211 |
result = unittest.TextTestRunner(verbosity=2).run(tests)
|
|
212 |
|
|
213 |
if result.wasSuccessful():
|
|
214 |
t.result = SmokeTest.PASS
|
|
215 |
else:
|
|
216 |
t.result = SmokeTest.FAIL
|
|
217 |
|
|
218 |
return t
|