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

[tor-commits] [stem/master] Integration tests for load_processed_files()



commit c547ed5688da5015dbddbb091118e351fef31bdd
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date:   Thu Mar 8 08:27:51 2012 -0800

    Integration tests for load_processed_files()
    
    Basic set of integ tests exercising file reading when successful, non-existant,
    or lacking permission.
---
 run_tests.py                      |    2 +
 test/integ/descriptor/__init__.py |    6 +++
 test/integ/descriptor/reader.py   |   74 +++++++++++++++++++++++++++++++++++++
 3 files changed, 82 insertions(+), 0 deletions(-)

diff --git a/run_tests.py b/run_tests.py
index 7cf5117..60118af 100755
--- a/run_tests.py
+++ b/run_tests.py
@@ -28,6 +28,7 @@ import test.integ.connection.protocolinfo
 import test.integ.control.base_controller
 import test.integ.socket.control_message
 import test.integ.socket.control_socket
+import test.integ.descriptor.reader
 import test.integ.util.conf
 import test.integ.util.system
 import test.integ.version
@@ -92,6 +93,7 @@ UNIT_TESTS = (
 INTEG_TESTS = (
   test.integ.util.conf.TestConf,
   test.integ.util.system.TestSystem,
+  test.integ.descriptor.reader.TestDescriptorReader,
   test.integ.version.TestVersion,
   test.integ.socket.control_socket.TestControlSocket,
   test.integ.socket.control_message.TestControlMessage,
diff --git a/test/integ/descriptor/__init__.py b/test/integ/descriptor/__init__.py
new file mode 100644
index 0000000..e1095ca
--- /dev/null
+++ b/test/integ/descriptor/__init__.py
@@ -0,0 +1,6 @@
+"""
+Integration tests for stem.descriptor.* contents.
+"""
+
+__all__ = ["reader"]
+
diff --git a/test/integ/descriptor/reader.py b/test/integ/descriptor/reader.py
new file mode 100644
index 0000000..c8b93b0
--- /dev/null
+++ b/test/integ/descriptor/reader.py
@@ -0,0 +1,74 @@
+"""
+Integration tests for stem.descriptor.reader.
+"""
+
+import os
+import unittest
+
+import stem.descriptor.reader
+import test.runner
+
+BASIC_LISTING = """
+/tmp 123
+/bin/grep 4567
+/file with spaces/and \\ stuff 890
+"""
+
+def _get_processed_files_path():
+  return os.path.join(test.runner.get_runner().get_test_dir(), "descriptor_processed_files")
+
+def _make_processed_files_listing(contents):
+  """
+  Writes the given 'processed file' listing to disk, returning the path where
+  it is located.
+  """
+  
+  test_listing_path = _get_processed_files_path()
+  
+  test_listing_file = open(test_listing_path, "w")
+  test_listing_file.write(contents)
+  test_listing_file.close()
+  
+  return test_listing_path
+
+class TestDescriptorReader(unittest.TestCase):
+  def tearDown(self):
+    # cleans up 'processed file' listings that we made
+    test_listing_path = _get_processed_files_path()
+    
+    if os.path.exists(test_listing_path):
+      os.remove(test_listing_path)
+  
+  def test_load_processed_files(self):
+    """
+    Basic sanity test for loading a processed files listing from disk.
+    """
+    
+    test_listing_path = _make_processed_files_listing(BASIC_LISTING)
+    loaded_listing = stem.descriptor.reader.load_processed_files(test_listing_path)
+    
+    expected_listing = {
+      "/tmp": 123,
+      "/bin/grep": 4567,
+      "/file with spaces/and \\ stuff": 890,
+    }
+    
+    self.assertEquals(expected_listing, loaded_listing)
+  
+  def test_load_processed_files_missing(self):
+    """
+    Tests the load_processed_files() function with a file that doesn't exist.
+    """
+    
+    self.assertRaises(IOError, stem.descriptor.reader.load_processed_files, "/non-existant/path")
+  
+  def test_load_processed_files_permissions(self):
+    """
+    Tests the load_processed_files() function with a file that can't be read
+    due to permissions.
+    """
+    
+    test_listing_path = _make_processed_files_listing(BASIC_LISTING)
+    os.chmod(test_listing_path, 0077) # remove read permissions
+    self.assertRaises(IOError, stem.descriptor.reader.load_processed_files, test_listing_path)
+



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