[PATCH 1 of 2] test-atomictempfile: convert to unit test

Idan Kamara idankk86 at gmail.com
Sat Feb 9 17:17:00 UTC 2013


# HG changeset patch
# User Idan Kamara <idankk86 at gmail.com>
# Date 1360429365 -7200
# Node ID 4a4b4c13211532f5bdf48c6f09a50023fbef176b
# Parent  15828f7e5de2c59201fbe8a996a7d71a6bb07926
test-atomictempfile: convert to unit test

diff --git a/tests/test-atomictempfile.py b/tests/test-atomictempfile.py
--- a/tests/test-atomictempfile.py
+++ b/tests/test-atomictempfile.py
@@ -1,48 +1,42 @@
 import os
 import glob
+import unittest
+import silenttestrunner
+
 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-*'))
 
-    file.write('argh\n')
-    file.close()
+        file.write('argh\n')
+        file.close()
 
-    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-*'))
 
-# 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)
+    # 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)
 
-    file.write('yo\n')
-    file.discard()
+        file.write('yo\n')
+        file.discard()
 
-    assert not os.path.isfile('foo')
-    assert basename not in os.listdir('.')
-    print 'OK'
+        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():
-    try:
-        file = atomictempfile()
-    except TypeError:
-        print "OK"
-    else:
-        print "expected TypeError"
+    # 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__':
-    test1_simple()
-    test2_discard()
-    test3_oops()
+    silenttestrunner.main(__name__)
diff --git a/tests/test-atomictempfile.py.out b/tests/test-atomictempfile.py.out
deleted file mode 100644
--- a/tests/test-atomictempfile.py.out
+++ /dev/null
@@ -1,3 +0,0 @@
-OK
-OK
-OK


More information about the Mercurial-devel mailing list