[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [stem/master] Integ test for skipping files that don't exist



commit 827d3495084f762d4e2e0df3253fea00fc532707
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date:   Sun Mar 11 15:13:57 2012 -0700

    Integ test for skipping files that don't exist
    
    Adding an integration test that listens for a file which is skipped because it
    doesn't exist.
---
 stem/descriptor/reader.py       |    5 ++++-
 test/integ/descriptor/reader.py |   21 +++++++++++++++++++++
 2 files changed, 25 insertions(+), 1 deletions(-)

diff --git a/stem/descriptor/reader.py b/stem/descriptor/reader.py
index 0dde2a9..9ef6781 100644
--- a/stem/descriptor/reader.py
+++ b/stem/descriptor/reader.py
@@ -108,10 +108,13 @@ class ReadFailed(FileSkipped):
   "An IOError occured while trying to read the file."
   
   def __init__(self, read_exception):
-    self.exception = exception
+    self.exception = read_exception
 
 class FileMissing(ReadFailed):
   "File does not exist."
+  
+  def __init__(self):
+    ReadFailed.__init__(self, None)
 
 def load_processed_files(path):
   """
diff --git a/test/integ/descriptor/reader.py b/test/integ/descriptor/reader.py
index 4ef1d58..7e5955d 100644
--- a/test/integ/descriptor/reader.py
+++ b/test/integ/descriptor/reader.py
@@ -249,4 +249,25 @@ class TestDescriptorReader(unittest.TestCase):
     
     if os.path.exists(test_path):
       os.remove(test_path)
+  
+  def test_skip_listener_file_missing(self):
+    """
+    Listens for a file that's skipped because the file doesn't exist.
+    """
+    
+    test_path = "/foo/bar/doesn't_exist"
+    
+    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.FileMissing))
 



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits