##// END OF EJS Templates
localrepo: use the path relative to "self.vfs" instead of "path" argument...
localrepo: use the path relative to "self.vfs" instead of "path" argument As a part of migration to vfs, this patch uses "self.root", which can be recognized as the path relative to "self.vfs", instead of "path" argument. This fix allows to make invocations of "util.makedirs()" and "os.path.exists()" while ensuring repository directory in "localrepository.__init__()" ones indirectly via vfs. But this fix also raises issue 2528: "hg clone" with empty destination. "path" argument is empty in many cases, so this issue can't be fixed in the view of "localrepository.__init__()". Before this patch, it is fixed by empty-ness check ("not name") of exception handler in "util.makedirs()". try: os.mkdir(name) except OSError, err: if err.errno == errno.EEXIST: return if err.errno != errno.ENOENT or not name: raise This requires "localrepository.__init__()" to invoke "util.makedirs()" with "path" instead of "self.root", because empty "path" is treated as "current directory" and "self.root" becomes valid path. But "hg clone" with empty destination can be detected also in "hg.clone()" before "localrepository.__init__()" invocation, so this patch re-fixes issue2528 by checking it in "hg.clone()".

File last commit:

r15057:774da712 default
r17159:36a30168 default
Show More
test-atomictempfile.py
48 lines | 1.2 KiB | text/x-python | PythonLexer
/ tests / test-atomictempfile.py
Greg Ward
atomictempfile: avoid infinite recursion in __del__()....
r14007 import os
import glob
from mercurial.util import atomictempfile
# basic usage
def test1_simple():
if os.path.exists('foo'):
os.remove('foo')
file = atomictempfile('foo')
(dir, basename) = os.path.split(file._tempname)
assert not os.path.isfile('foo')
assert basename in glob.glob('.foo-*')
file.write('argh\n')
Greg Ward
atomictempfile: make close() consistent with other file-like objects....
r15057 file.close()
Greg Ward
atomictempfile: avoid infinite recursion in __del__()....
r14007
assert os.path.isfile('foo')
assert basename not in glob.glob('.foo-*')
print 'OK'
Greg Ward
atomictempfile: make close() consistent with other file-like objects....
r15057 # discard() removes the temp file without making the write permanent
def test2_discard():
Greg Ward
atomictempfile: avoid infinite recursion in __del__()....
r14007 if os.path.exists('foo'):
os.remove('foo')
file = atomictempfile('foo')
(dir, basename) = os.path.split(file._tempname)
file.write('yo\n')
Greg Ward
atomictempfile: make close() consistent with other file-like objects....
r15057 file.discard()
Greg Ward
atomictempfile: avoid infinite recursion in __del__()....
r14007
assert not os.path.isfile('foo')
assert basename not in os.listdir('.')
print 'OK'
# if a programmer screws up and passes bad args to atomictempfile, they
# get a plain ordinary TypeError, not infinite recursion
def test3_oops():
try:
file = atomictempfile()
except TypeError:
print "OK"
else:
print "expected TypeError"
if __name__ == '__main__':
test1_simple()
Greg Ward
atomictempfile: make close() consistent with other file-like objects....
r15057 test2_discard()
Greg Ward
atomictempfile: avoid infinite recursion in __del__()....
r14007 test3_oops()