[tor-commits] [ooni-probe/master] Add unittest for the YAMLReporter
art at torproject.org
art at torproject.org
Fri Feb 28 14:32:21 UTC 2014
commit 8484bfe2870968e43c46b764688202d3c74213c0
Author: Arturo Filastò <art at fuffa.org>
Date: Thu Jan 30 17:54:25 2014 +0100
Add unittest for the YAMLReporter
---
ooni/tests/test_reporter.py | 39 +++++++++++++++++++++++++++++++++++++++
1 file changed, 39 insertions(+)
diff --git a/ooni/tests/test_reporter.py b/ooni/tests/test_reporter.py
new file mode 100644
index 0000000..0a4d240
--- /dev/null
+++ b/ooni/tests/test_reporter.py
@@ -0,0 +1,39 @@
+import yaml
+import time
+
+from twisted.trial import unittest
+
+from ooni.reporter import YAMLReporter
+
+class MockTest(object):
+ _start_time = time.time()
+ report = {'report_content': 'ham'}
+ input = 'spam'
+
+class TestYAMLReporter(unittest.TestCase):
+ def setUp(self):
+ pass
+
+ def test_write_report(self):
+ test_details = {
+ 'test_name': 'spam',
+ 'test_version': '1.0'
+ }
+ test = MockTest()
+
+ y_reporter = YAMLReporter(test_details)
+ y_reporter.createReport()
+ y_reporter.testDone(test, 'spam')
+ with open(y_reporter.report_path) as f:
+ report_entries = yaml.safe_load_all(f)
+ # Check for keys in header
+ entry = report_entries.next()
+ assert all(x in entry for x in ['test_name', 'test_version'])
+
+ entry = report_entries.next()
+ # Check for first entry of report
+ assert all(x in entry \
+ for x in ['report_content', 'input', \
+ 'test_name', 'test_started', \
+ 'test_runtime'])
+
More information about the tor-commits
mailing list