##// END OF EJS Templates
pathutil: add doctests for canonpath()...
Matt Harbison -
r34981:705d0f2b stable
parent child Browse files
Show More
@@ -135,7 +135,47 b' class pathauditor(object):'
135 return False
135 return False
136
136
137 def canonpath(root, cwd, myname, auditor=None):
137 def canonpath(root, cwd, myname, auditor=None):
138 '''return the canonical path of myname, given cwd and root'''
138 '''return the canonical path of myname, given cwd and root
139
140 >>> def check(root, cwd, myname):
141 ... a = pathauditor(root, realfs=False)
142 ... try:
143 ... return canonpath(root, cwd, myname, a)
144 ... except error.Abort:
145 ... return 'aborted'
146 >>> def unixonly(root, cwd, myname, expected='aborted'):
147 ... if pycompat.iswindows:
148 ... return expected
149 ... return check(root, cwd, myname)
150 >>> def winonly(root, cwd, myname, expected='aborted'):
151 ... if not pycompat.iswindows:
152 ... return expected
153 ... return check(root, cwd, myname)
154 >>> winonly(b'd:\\\\repo', b'c:\\\\dir', b'filename')
155 'aborted'
156 >>> winonly(b'c:\\\\repo', b'c:\\\\dir', b'filename')
157 'aborted'
158 >>> winonly(b'c:\\\\repo', b'c:\\\\', b'filename')
159 'aborted'
160 >>> winonly(b'c:\\\\repo', b'c:\\\\', b'repo\\\\filename',
161 ... b'filename')
162 'filename'
163 >>> winonly(b'c:\\\\repo', b'c:\\\\repo', b'filename', b'filename')
164 'filename'
165 >>> winonly(b'c:\\\\repo', b'c:\\\\repo\\\\subdir', b'filename',
166 ... b'subdir/filename')
167 'subdir/filename'
168 >>> unixonly(b'/repo', b'/dir', b'filename')
169 'aborted'
170 >>> unixonly(b'/repo', b'/', b'filename')
171 'aborted'
172 >>> unixonly(b'/repo', b'/', b'repo/filename', b'filename')
173 'filename'
174 >>> unixonly(b'/repo', b'/repo', b'filename', b'filename')
175 'filename'
176 >>> unixonly(b'/repo', b'/repo/subdir', b'filename', b'subdir/filename')
177 'subdir/filename'
178 '''
139 if util.endswithsep(root):
179 if util.endswithsep(root):
140 rootsep = root
180 rootsep = root
141 else:
181 else:
General Comments 0
You need to be logged in to leave comments. Login now