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

[tor-commits] [stem/master] Making descriptor reader skip tests more resilient



commit 04176384995a89555067ddecf4cf6a7fe882ce39
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date:   Sat Apr 14 17:03:28 2012 -0700

    Making descriptor reader skip tests more resilient
    
    Couple problems with the skip tests for the descriptor reader:
    - A bug in the test for skipping unmodified files caused the test to rely on
      the order in which descriptors were read. It had a check that should have
      caught this, but rather than "assertEqual(1, len(skipped_files))" it had
      "assertTrue(1, len(skipped_files))".
    
      Fixed the check and narrowed the test to just the single descriptor file
      that it was supposed to test against.
    
    - The test which checks that we properly skip and report non-descriptor content
      would fail if other files are added to the data directory. This is as it
      should be, but the error message wasn't helpful and I've encountered this a
      lot due to vim '.swp' files.
---
 test/integ/descriptor/reader.py |   10 +++++++---
 1 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/test/integ/descriptor/reader.py b/test/integ/descriptor/reader.py
index 1444dbb..5c84704 100644
--- a/test/integ/descriptor/reader.py
+++ b/test/integ/descriptor/reader.py
@@ -302,7 +302,11 @@ class TestDescriptorReader(unittest.TestCase):
     self.assertTrue(2, len(skip_listener.results))
     
     for skip_path, skip_exception in skip_listener.results:
-      self.assertTrue(os.path.basename(skip_path) in ("riddle", "tiny.png"))
+      if skip_path.endswith(".swp"): continue # skip vim temp files
+      
+      if not os.path.basename(skip_path) in ("riddle", "tiny.png"):
+        self.fail("Unexpected non-descriptor content: %s" % skip_path)
+      
       self.assertTrue(isinstance(skip_exception, stem.descriptor.reader.UnrecognizedType))
   
   def test_skip_listener_already_read(self):
@@ -317,14 +321,14 @@ class TestDescriptorReader(unittest.TestCase):
     initial_processed_files = {test_path: sys.maxint}
     
     skip_listener = SkipListener()
-    reader = stem.descriptor.reader.DescriptorReader([DESCRIPTOR_TEST_DATA])
+    reader = stem.descriptor.reader.DescriptorReader([test_path])
     reader.register_skip_listener(skip_listener.listener)
     reader.set_processed_files(initial_processed_files)
     
     self.assertEquals(initial_processed_files, reader.get_processed_files())
     with reader: list(reader) # iterates over all of the descriptors
     
-    self.assertTrue(1, len(skip_listener.results))
+    self.assertEquals(1, len(skip_listener.results))
     
     skipped_path, skip_exception = skip_listener.results[0]
     self.assertEqual(test_path, skipped_path)



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