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

[tor-commits] [arm/master] Unit tests for missing_event_types()



commit bf3a92f2e08140f2fd9aad84b1586becd0b94fb4
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date:   Sat Dec 28 21:19:46 2013 -0800

    Unit tests for missing_event_types()
    
    Just some basic unit tests. It's not a terribly big function.
---
 test/arguments.py |   31 ++++++++++++++++++++++++++++++-
 1 file changed, 30 insertions(+), 1 deletion(-)

diff --git a/test/arguments.py b/test/arguments.py
index f0fcdb9..97c4ecf 100644
--- a/test/arguments.py
+++ b/test/arguments.py
@@ -1,7 +1,9 @@
 import getopt
 import unittest
 
-from arm.arguments import DEFAULT_ARGS, parse, expand_events
+from mock import Mock, patch
+
+from arm.arguments import DEFAULT_ARGS, parse, expand_events, missing_event_types
 
 
 class TestArgumentParsing(unittest.TestCase):
@@ -63,6 +65,7 @@ class TestArgumentParsing(unittest.TestCase):
     for invalid_input in invalid_inputs:
       self.assertRaises(ValueError, parse, ['--interface', invalid_input])
 
+
 class TestExpandEvents(unittest.TestCase):
   def test_examples(self):
     self.assertEqual(set(['INFO', 'NOTICE', 'UNKNOWN', 'STATUS_CLIENT']), expand_events('inUt'))
@@ -101,3 +104,29 @@ class TestExpandEvents(unittest.TestCase):
       self.fail()
     except ValueError as exc:
       self.assertEqual(set(expected), set(str(exc)))
+
+
+class TestMissingEventTypes(unittest.TestCase):
+  @patch('arm.arguments.tor_controller')
+  def test_with_a_failed_query(self, controller_mock):
+    controller = Mock()
+    controller.get_info.return_value = None
+    controller_mock.return_value = controller
+
+    self.assertEqual([], missing_event_types())
+
+  @patch('arm.arguments.tor_controller')
+  def test_without_unrecognized_events(self, controller_mock):
+    controller = Mock()
+    controller.get_info.return_value = 'DEBUG INFO NOTICE WARN ERR'
+    controller_mock.return_value = controller
+
+    self.assertEqual([], missing_event_types())
+
+  @patch('arm.arguments.tor_controller')
+  def test_with_unrecognized_events(self, controller_mock):
+    controller = Mock()
+    controller.get_info.return_value = 'EVENT1 DEBUG INFO NOTICE WARN EVENT2 ERR EVENT3'
+    controller_mock.return_value = controller
+
+    self.assertEqual(['EVENT1', 'EVENT2', 'EVENT3'], missing_event_types())

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