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

[tor-commits] [stem/master] Improving error output for test_skip_nondescriptor_contents



commit 9d53a2854178d12222480958795876e45ec0f1d6
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date:   Tue Jan 29 08:54:03 2013 -0800

    Improving error output for test_skip_nondescriptor_contents
    
    The descriptor reader's test_skip_nondescriptor_contents integ test is
    especially tickle since it can fail whenever there's new non-descriptor content
    in the test/integ/descriptor/data directory.
    
    Improving its error output to say what it expected and got rather than simply
    saying that the counts mismatch.
---
 test/integ/descriptor/reader.py |   17 ++++++++++++-----
 1 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/test/integ/descriptor/reader.py b/test/integ/descriptor/reader.py
index 960eaeb..97ea27c 100644
--- a/test/integ/descriptor/reader.py
+++ b/test/integ/descriptor/reader.py
@@ -363,16 +363,23 @@ class TestDescriptorReader(unittest.TestCase):
     reader = stem.descriptor.reader.DescriptorReader(DESCRIPTOR_TEST_DATA)
     reader.register_skip_listener(skip_listener.listener)
 
+    expected_skip_files = ("riddle", "tiny.png", "vote", "new_metrics_type")
+
     with reader:
       list(reader)  # iterates over all of the descriptors
 
-    self.assertEqual(4, len(skip_listener.results))
+    # strip anything with a .swp suffix (vim tmp files)
 
-    for skip_path, skip_exception in skip_listener.results:
-      if skip_path.endswith(".swp"):
-        continue  # skip vim temp files
+    skip_listener.results = [(path, exc) for (path, exc) in skip_listener.results if not path.endswith(".swp")]
+
+    if len(skip_listener.results) != len(expected_skip_files):
+      expected_label = ",\n  ".join(expected_skip_files)
+      results_label = ",\n  ".join(["%s (%s)" % (path, exc) for (path, exc) in skip_listener.results])
 
-      if not os.path.basename(skip_path) in ("riddle", "tiny.png", "vote", "new_metrics_type"):
+      self.fail("Skipped files that we should have been able to parse.\n\nExpected:\n  %s\n\nResult:\n  %s" % (expected_label, results_label))
+
+    for skip_path, skip_exception in skip_listener.results:
+      if not os.path.basename(skip_path) in expected_skip_files:
         self.fail("Unexpected non-descriptor content: %s" % skip_path)
 
       self.assertTrue(isinstance(skip_exception, stem.descriptor.reader.UnrecognizedType))



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