]> granicus.if.org Git - python/commitdiff
Fix a bunch of UnboundLocalErrors when the tests fail.
authorNeal Norwitz <nnorwitz@gmail.com>
Tue, 25 Mar 2008 04:17:38 +0000 (04:17 +0000)
committerNeal Norwitz <nnorwitz@gmail.com>
Tue, 25 Mar 2008 04:17:38 +0000 (04:17 +0000)
Lib/test/test_deque.py
Lib/test/test_uu.py

index b69110d88d5bcc349a94ac8a79887f9e136e0768..a185f78dba79b28aabd72ce78f5c137b25772d87 100644 (file)
@@ -63,27 +63,27 @@ class TestBasic(unittest.TestCase):
         self.assertEqual(list(d), range(7, 10))
         d = deque(xrange(200), maxlen=10)
         d.append(d)
+        fo = open(test_support.TESTFN, "wb")
         try:
-            fo = open(test_support.TESTFN, "wb")
             print >> fo, d,
             fo.close()
             fo = open(test_support.TESTFN, "rb")
             self.assertEqual(fo.read(), repr(d))
         finally:
             fo.close()
-            os.remove(test_support.TESTFN)
+            test_support.unlink(test_support.TESTFN)
 
         d = deque(range(10), maxlen=None)
         self.assertEqual(repr(d), 'deque([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])')
+        fo = open(test_support.TESTFN, "wb")
         try:
-            fo = open(test_support.TESTFN, "wb")
             print >> fo, d,
             fo.close()
             fo = open(test_support.TESTFN, "rb")
             self.assertEqual(fo.read(), repr(d))
         finally:
             fo.close()
-            os.remove(test_support.TESTFN)
+            test_support.unlink(test_support.TESTFN)
 
     def test_comparisons(self):
         d = deque('xabc'); d.popleft()
@@ -281,15 +281,15 @@ class TestBasic(unittest.TestCase):
     def test_print(self):
         d = deque(xrange(200))
         d.append(d)
+        fo = open(test_support.TESTFN, "wb")
         try:
-            fo = open(test_support.TESTFN, "wb")
             print >> fo, d,
             fo.close()
             fo = open(test_support.TESTFN, "rb")
             self.assertEqual(fo.read(), repr(d))
         finally:
             fo.close()
-            os.remove(test_support.TESTFN)
+            test_support.unlink(test_support.TESTFN)
 
     def test_init(self):
         self.assertRaises(TypeError, deque, 'abc', 2, 3);
index 9aad56e72e8bc88d00cb634cddf623ab6fba48bd..346cfb2ced0526f0e09dede7508d1a2b3ed6309a 100644 (file)
@@ -112,6 +112,7 @@ class UUFileTest(unittest.TestCase):
         del self.tmpout
 
     def test_encode(self):
+        fin = fout = None
         try:
             fin = open(self.tmpin, 'wb')
             fin.write(plaintext)
@@ -140,6 +141,7 @@ class UUFileTest(unittest.TestCase):
             self._kill(fout)
 
     def test_decode(self):
+        f = None
         try:
             f = open(self.tmpin, 'w')
             f.write(encodedtextwrapped % (0644, self.tmpout))
@@ -159,6 +161,7 @@ class UUFileTest(unittest.TestCase):
 
     def test_decodetwice(self):
         # Verify that decode() will refuse to overwrite an existing file
+        f = None
         try:
             f = cStringIO.StringIO(encodedtextwrapped % (0644, self.tmpout))