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

login
register
mail settings
Submitter Idan Kamara
Date Feb. 9, 2013, 5:17 p.m.
Message ID <4a4b4c13211532f5bdf4.1360430220@idan>
Download mbox | patch
Permalink /patch/900/
State Accepted
Commit fb9d1c2805ff709bf9dc5729791eb62f8b5b2f23
Headers show

Comments

Idan Kamara - Feb. 9, 2013, 5:17 p.m.
# HG changeset patch
# User Idan Kamara <idankk86@gmail.com>
# Date 1360429365 -7200
# Node ID 4a4b4c13211532f5bdf48c6f09a50023fbef176b
# Parent  15828f7e5de2c59201fbe8a996a7d71a6bb07926
test-atomictempfile: convert to unit test
Idan Kamara - Feb. 9, 2013, 5:18 p.m.
On Sat, Feb 9, 2013 at 7:17 PM, Idan Kamara <idankk86@gmail.com> wrote:
>
> # HG changeset patch
> # User Idan Kamara <idankk86@gmail.com>
> # Date 1360429365 -7200
> # Node ID 4a4b4c13211532f5bdf48c6f09a50023fbef176b
> # Parent  15828f7e5de2c59201fbe8a996a7d71a6bb07926
> test-atomictempfile: convert to unit test

Oops, this should have been patch #2.
Bryan O'Sullivan - Feb. 11, 2013, 10:03 p.m.
On Sat, Feb 09, 2013 at 07:17:00PM +0200, Idan Kamara wrote:
> test-atomictempfile: convert to unit test

Crewed both patches (in the correct order), thanks.

Patch

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