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

[tor-commits] [stem/master] Integ test for skipping a file due to its mime type



commit 9f8683f182b1199ba1eb6955130e46db0bae5372
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date:   Sun Mar 11 15:05:54 2012 -0700

    Integ test for skipping a file due to its mime type
    
    Adding an integration test that listens for a file which is skipped due to a
    type indicating that it doesn't contain descriptor data.
---
 stem/descriptor/reader.py       |    2 +-
 test/integ/descriptor/reader.py |   38 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 39 insertions(+), 1 deletions(-)

diff --git a/stem/descriptor/reader.py b/stem/descriptor/reader.py
index 8a1be75..0dde2a9 100644
--- a/stem/descriptor/reader.py
+++ b/stem/descriptor/reader.py
@@ -338,7 +338,7 @@ class DescriptorReader(threading.Thread):
     pass # TODO: implement
   
   def _notify_skip_listeners(self, path, exception):
-    for listener in self.skip_listeners:
+    for listener in self._skip_listeners:
       listener(path, exception)
   
   def __enter__(self):
diff --git a/test/integ/descriptor/reader.py b/test/integ/descriptor/reader.py
index e8a6c20..4ef1d58 100644
--- a/test/integ/descriptor/reader.py
+++ b/test/integ/descriptor/reader.py
@@ -37,6 +37,13 @@ def _make_processed_files_listing(contents):
   
   return test_listing_path
 
+class SkipListener:
+  def __init__(self):
+    self.results = [] # (path, exception) tuples that we've received
+  
+  def listener(self, path, exception):
+    self.results.append((path, exception))
+
 class TestDescriptorReader(unittest.TestCase):
   def tearDown(self):
     # cleans up 'processed file' listings that we made
@@ -211,4 +218,35 @@ class TestDescriptorReader(unittest.TestCase):
       for descriptor in reader:
         if str(descriptor) == skip_contents:
           self.fail() # we read the file that we were trying to skip
+  
+  def test_skip_listener_unrecognized_type(self):
+    """
+    Listens for a file that's skipped because its file type isn't recognized.
+    """
+    
+    # types are solely based on file extensions so making something that looks
+    # like an png image
+    
+    test_path = os.path.join(test.runner.get_runner().get_test_dir(), "test.png")
+    
+    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)
 



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