Mercurial > hg
view tests/test-atomictempfile.py @ 18401:683a76a07325
hgweb: add test regarding filtering and hgweb
Since 4d1671b39168 hgweb is broken with filtering. This changeset add test that
should pass once it is fixed. Test currently broken are commented and will be
uncommented by changeset that fix them.
The filelog test is currently passing because we already have some hack in core
regarding filelog (see 518c1403838f).
author | Pierre-Yves David <pierre-yves.david@ens-lyon.org> |
---|---|
date | Wed, 16 Jan 2013 11:39:22 -0600 |
parents | 774da7121fc9 |
children | fb9d1c2805ff |
line wrap: on
line source
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') file.close() assert os.path.isfile('foo') assert basename not in glob.glob('.foo-*') print 'OK' # 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.discard() 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() test2_discard() test3_oops()