Mercurial > public > mercurial-scm > hg
diff tests/test-atomictempfile.py @ 15057:774da7121fc9
atomictempfile: make close() consistent with other file-like objects.
The usual contract is that close() makes your writes permanent, so
atomictempfile's use of close() to *discard* writes (and rename() to
keep them) is rather unexpected. Thus, change it so close() makes
things permanent and add a new discard() method to throw them away.
discard() is only used internally, in __del__(), to ensure that writes
are discarded when an atomictempfile object goes out of scope.
I audited mercurial.*, hgext.*, and ~80 third-party extensions, and
found no one using the existing semantics of close() to discard
writes, so this should be safe.
author | Greg Ward <greg@gerg.ca> |
---|---|
date | Thu, 25 Aug 2011 20:21:04 -0400 |
parents | d764463b433e |
children | fb9d1c2805ff |
line wrap: on
line diff
--- a/tests/test-atomictempfile.py Wed Aug 24 05:42:41 2011 -0400 +++ b/tests/test-atomictempfile.py Thu Aug 25 20:21:04 2011 -0400 @@ -12,22 +12,21 @@ assert basename in glob.glob('.foo-*') file.write('argh\n') - file.rename() + file.close() assert os.path.isfile('foo') assert basename not in glob.glob('.foo-*') print 'OK' -# close() removes the temp file but does not make the write -# permanent -- essentially discards your work (WTF?!) -def test2_close(): +# discard() removes the temp file without making the write permanent +def test2_discard(): if os.path.exists('foo'): os.remove('foo') file = atomictempfile('foo') (dir, basename) = os.path.split(file._tempname) file.write('yo\n') - file.close() + file.discard() assert not os.path.isfile('foo') assert basename not in os.listdir('.') @@ -45,5 +44,5 @@ if __name__ == '__main__': test1_simple() - test2_close() + test2_discard() test3_oops()