Skip to content
Snippets Groups Projects
Commit fb9d1c2805ff authored by Idan Kamara's avatar Idan Kamara
Browse files

test-atomictempfile: convert to unit test

parent 2cbfb8c497ee
No related branches found
No related tags found
No related merge requests found
import os
import glob
import unittest
import silenttestrunner
from mercurial.util import atomictempfile
......@@ -3,11 +6,11 @@
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-*')
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-*'))
......@@ -13,4 +16,4 @@
file.write('argh\n')
file.close()
file.write('argh\n')
file.close()
......@@ -16,5 +19,4 @@
assert os.path.isfile('foo')
assert basename not in glob.glob('.foo-*')
print 'OK'
self.assertTrue(os.path.isfile('foo'))
self.assertTrue(basename not in glob.glob('.foo-*'))
......@@ -20,11 +22,8 @@
# 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()
# 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)
......@@ -30,5 +29,4 @@
assert not os.path.isfile('foo')
assert basename not in os.listdir('.')
print 'OK'
file.write('yo\n')
file.discard()
......@@ -34,12 +32,10 @@
# 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"
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)
if __name__ == '__main__':
......@@ -44,5 +40,3 @@
if __name__ == '__main__':
test1_simple()
test2_discard()
test3_oops()
silenttestrunner.main(__name__)
OK
OK
OK
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment