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

[tor-commits] [stem/master] Integ test for files skipped due to permissions



commit 77ac27cbe057e9411c28d0a8be814046465d335b
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date:   Sun Mar 11 15:20:50 2012 -0700

    Integ test for files skipped due to permissions
    
    Adding an integration test that listens for a file which is skipped because
    the user lacks read permissions.
---
 test/integ/descriptor/reader.py |   30 ++++++++++++++++++++++++++++++
 1 files changed, 30 insertions(+), 0 deletions(-)

diff --git a/test/integ/descriptor/reader.py b/test/integ/descriptor/reader.py
index 7e5955d..fa2c7b5 100644
--- a/test/integ/descriptor/reader.py
+++ b/test/integ/descriptor/reader.py
@@ -250,6 +250,36 @@ class TestDescriptorReader(unittest.TestCase):
     if os.path.exists(test_path):
       os.remove(test_path)
   
+  def test_skip_listener_read_failure(self):
+    """
+    Listens for a file that's skipped because we lack read permissions.
+    """
+    
+    test_path = os.path.join(test.runner.get_runner().get_test_dir(), "secret_file")
+    
+    with open(test_path, "w") as test_file:
+      test_file.write("test data for test_skip_listener_unrecognized_type()")
+    
+    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)
+  
   def test_skip_listener_file_missing(self):
     """
     Listens for a file that's skipped because the file doesn't exist.



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