##// END OF EJS Templates
transaction: use 'util.copyfile' for creating backup...
transaction: use 'util.copyfile' for creating backup Using 'copyfile' (single file) instead of 'copyfiles' (tree) will ensures destination file will be overwritten. This will prevent some abort if backup file are left in place for random reason. It also seems more correct.

File last commit:

r18666:fb9d1c28 default
r23900:5eb3541f default
Show More
test-atomictempfile.py
42 lines | 1.3 KiB | text/x-python | PythonLexer
/ tests / test-atomictempfile.py
Greg Ward
atomictempfile: avoid infinite recursion in __del__()....
r14007 import os
import glob
Idan Kamara
test-atomictempfile: convert to unit test
r18666 import unittest
import silenttestrunner
Greg Ward
atomictempfile: avoid infinite recursion in __del__()....
r14007 from mercurial.util import atomictempfile
Idan Kamara
test-atomictempfile: convert to unit test
r18666 class testatomictempfile(unittest.TestCase):
def test1_simple(self):
if os.path.exists('foo'):
os.remove('foo')
file = atomictempfile('foo')
(dir, basename) = os.path.split(file._tempname)
self.assertFalse(os.path.isfile('foo'))
self.assertTrue(basename in glob.glob('.foo-*'))
Greg Ward
atomictempfile: avoid infinite recursion in __del__()....
r14007
Idan Kamara
test-atomictempfile: convert to unit test
r18666 file.write('argh\n')
file.close()
Greg Ward
atomictempfile: avoid infinite recursion in __del__()....
r14007
Idan Kamara
test-atomictempfile: convert to unit test
r18666 self.assertTrue(os.path.isfile('foo'))
self.assertTrue(basename not in glob.glob('.foo-*'))
Greg Ward
atomictempfile: avoid infinite recursion in __del__()....
r14007
Idan Kamara
test-atomictempfile: convert to unit test
r18666 # discard() removes the temp file without making the write permanent
def test2_discard(self):
if os.path.exists('foo'):
os.remove('foo')
file = atomictempfile('foo')
(dir, basename) = os.path.split(file._tempname)
Greg Ward
atomictempfile: avoid infinite recursion in __del__()....
r14007
Idan Kamara
test-atomictempfile: convert to unit test
r18666 file.write('yo\n')
file.discard()
Greg Ward
atomictempfile: avoid infinite recursion in __del__()....
r14007
Idan Kamara
test-atomictempfile: convert to unit test
r18666 self.assertFalse(os.path.isfile('foo'))
self.assertTrue(basename not in os.listdir('.'))
# if a programmer screws up and passes bad args to atomictempfile, they
# get a plain ordinary TypeError, not infinite recursion
def test3_oops(self):
self.assertRaises(TypeError, atomictempfile)
Greg Ward
atomictempfile: avoid infinite recursion in __del__()....
r14007
if __name__ == '__main__':
Idan Kamara
test-atomictempfile: convert to unit test
r18666 silenttestrunner.main(__name__)