[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [stem/master] Integration test for reading non-descriptor files
commit 9faad3255491642f87801926512c9cb6d334f6d8
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date: Sat Mar 24 16:50:03 2012 -0700
Integration test for reading non-descriptor files
Integ test for reading non-descriptor plaintext and binary data.
---
stem/descriptor/reader.py | 7 ++++++-
test/integ/descriptor/data/riddle | 20 ++++++++++++++++++++
test/integ/descriptor/data/tiny.png | Bin 0 -> 188 bytes
test/integ/descriptor/reader.py | 18 ++++++++++++++++++
4 files changed, 44 insertions(+), 1 deletions(-)
diff --git a/stem/descriptor/reader.py b/stem/descriptor/reader.py
index 511ba04..de39d54 100644
--- a/stem/descriptor/reader.py
+++ b/stem/descriptor/reader.py
@@ -94,7 +94,10 @@ class ParsingFailure(FileSkipped):
self.exception = parsing_exception
class UnrecognizedType(FileSkipped):
- "File's mime type indicates that it isn't descriptor data."
+ """
+ File doesn't contain descriptor data. This could either be due to its file
+ type or because it doens't conform to a recognizable descriptor type.
+ """
def __init__(self, mime_type):
FileSkipped.__init__(self)
@@ -369,6 +372,8 @@ class DescriptorReader:
self._enqueue_descriptor(desc)
self._iter_notice.set()
except TypeError, exc:
+ self._notify_skip_listeners(target, UnrecognizedType(None))
+ except ValueError, exc:
self._notify_skip_listeners(target, ParsingFailure(exc))
except IOError, exc:
self._notify_skip_listeners(target, ReadFailed(exc))
diff --git a/test/integ/descriptor/data/riddle b/test/integ/descriptor/data/riddle
new file mode 100644
index 0000000..ac08f36
--- /dev/null
+++ b/test/integ/descriptor/data/riddle
@@ -0,0 +1,20 @@
+Riddle by Damian Johnson (May, 2009)
+
+Curtains raise, they take the stage,
+ mute actors that never age.
+The clouds are cotton, the floor is pine,
+ the souls bound up in fine twine.
+
+Crowds will cheer, the players dance,
+ flowing scene to scene as in a trance.
+The world is perfect, they never whine,
+ for there's not a single will, save mine.
+
+The play has ended, we take a bow,
+ but the viewers are the actors now.
+When freed from decision, of thought and blame,
+ we'll walk to another drum just the same.
+
+answer:
+http://www.atagar.com/riddles/answer10.php
+
diff --git a/test/integ/descriptor/data/tiny.png b/test/integ/descriptor/data/tiny.png
new file mode 100644
index 0000000..e86715f
Binary files /dev/null and b/test/integ/descriptor/data/tiny.png differ
diff --git a/test/integ/descriptor/reader.py b/test/integ/descriptor/reader.py
index cdc33c2..717a55b 100644
--- a/test/integ/descriptor/reader.py
+++ b/test/integ/descriptor/reader.py
@@ -287,6 +287,24 @@ class TestDescriptorReader(unittest.TestCase):
self.assertEquals(expected_results, reader.get_processed_files())
+ def test_skip_nondescriptor_contents(self):
+ """
+ Checks that the reader properly reports when it skips both binary and
+ plaintext non-descriptor files.
+ """
+
+ skip_listener = SkipListener()
+ reader = stem.descriptor.reader.DescriptorReader([DESCRIPTOR_TEST_DATA])
+ reader.register_skip_listener(skip_listener.listener)
+
+ with reader: list(reader) # iterates over all of the descriptors
+
+ 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"))
+ self.assertTrue(isinstance(skip_exception, stem.descriptor.reader.UnrecognizedType))
+
def test_skip_listener_already_read(self):
"""
Checks that calling set_processed_files() prior to reading makes us skip
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits