[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [stem/master] Being more careful to remove temporary test files
commit 16feb65cb0b8141137a14ab0cdde79ed79ed6f5a
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date: Mon Mar 12 08:18:57 2012 -0700
Being more careful to remove temporary test files
When tests failed they could leave behind temporary files which, in the case of
the 'secret_file' (which lacked read permissions) this would trip up future
test runs.
---
test/integ/descriptor/reader.py | 70 ++++++++++++++++++++-------------------
1 files changed, 36 insertions(+), 34 deletions(-)
diff --git a/test/integ/descriptor/reader.py b/test/integ/descriptor/reader.py
index fa2c7b5..a6190ef 100644
--- a/test/integ/descriptor/reader.py
+++ b/test/integ/descriptor/reader.py
@@ -232,23 +232,24 @@ class TestDescriptorReader(unittest.TestCase):
with open(test_path, "w") as test_file:
test_file.write("test data for test_skip_listener_unrecognized_type()")
- skip_listener = SkipListener()
- reader = stem.descriptor.reader.DescriptorReader([test_path])
- reader.register_skip_listener(skip_listener.listener)
-
- with reader:
- for descriptor in reader:
- pass
-
- self.assertTrue(len(skip_listener.results) == 1)
-
- skipped_path, skip_exception = skip_listener.results[0]
- self.assertEqual(test_path, skipped_path)
- self.assertTrue(isinstance(skip_exception, stem.descriptor.reader.UnrecognizedType))
- self.assertEqual(("image/png", None), skip_exception.mime_type)
-
- if os.path.exists(test_path):
- os.remove(test_path)
+ try:
+ skip_listener = SkipListener()
+ reader = stem.descriptor.reader.DescriptorReader([test_path])
+ reader.register_skip_listener(skip_listener.listener)
+
+ with reader:
+ for descriptor in reader:
+ pass
+
+ self.assertTrue(len(skip_listener.results) == 1)
+
+ skipped_path, skip_exception = skip_listener.results[0]
+ self.assertEqual(test_path, skipped_path)
+ self.assertTrue(isinstance(skip_exception, stem.descriptor.reader.UnrecognizedType))
+ self.assertEqual(("image/png", None), skip_exception.mime_type)
+ finally:
+ if os.path.exists(test_path):
+ os.remove(test_path)
def test_skip_listener_read_failure(self):
"""
@@ -262,23 +263,24 @@ class TestDescriptorReader(unittest.TestCase):
os.chmod(test_path, 0077) # remove read permissions
- skip_listener = SkipListener()
- reader = stem.descriptor.reader.DescriptorReader([test_path])
- reader.register_skip_listener(skip_listener.listener)
-
- with reader:
- for descriptor in reader:
- pass
-
- self.assertTrue(len(skip_listener.results) == 1)
-
- skipped_path, skip_exception = skip_listener.results[0]
- self.assertEqual(test_path, skipped_path)
- self.assertTrue(isinstance(skip_exception, stem.descriptor.reader.ReadFailed))
- self.assertTrue(isinstance(skip_exception.exception, IOError))
-
- if os.path.exists(test_path):
- os.remove(test_path)
+ try:
+ skip_listener = SkipListener()
+ reader = stem.descriptor.reader.DescriptorReader([test_path])
+ reader.register_skip_listener(skip_listener.listener)
+
+ with reader:
+ for descriptor in reader:
+ pass
+
+ self.assertTrue(len(skip_listener.results) == 1)
+
+ skipped_path, skip_exception = skip_listener.results[0]
+ self.assertEqual(test_path, skipped_path)
+ self.assertTrue(isinstance(skip_exception, stem.descriptor.reader.ReadFailed))
+ self.assertTrue(isinstance(skip_exception.exception, IOError))
+ finally:
+ if os.path.exists(test_path):
+ os.remove(test_path)
def test_skip_listener_file_missing(self):
"""
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits