Mercurial > hg
comparison mercurial/pathutil.py @ 34980:705d0f2bb677 stable
pathutil: add doctests for canonpath()
This is a followup to f445b10dc7fb. Since there's no way to ensure that more
drive letters than C: exist, this seems like the only way to test it. This is
enough to catch the f445b10dc7fb scenario, as well as CWD outside of the repo
when the path isn't prefixed with path/to/repo.
author | Matt Harbison <matt_harbison@yahoo.com> |
---|---|
date | Fri, 03 Nov 2017 22:22:50 -0400 |
parents | f445b10dc7fb |
children | 052351e3e1cd |
comparison
equal
deleted
inserted
replaced
34979:b64ea7fb9599 | 34980:705d0f2bb677 |
---|---|
133 return True | 133 return True |
134 except (OSError, error.Abort): | 134 except (OSError, error.Abort): |
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: |
142 rootsep = root + pycompat.ossep | 182 rootsep = root + pycompat.ossep |
143 name = myname | 183 name = myname |