Browse Source

Add tests for auto_restart

Mike Naberezny 11 years ago
parent
commit
002b6c195d
1 changed files with 28 additions and 0 deletions
  1. 28 0
      supervisor/tests/test_datatypes.py

+ 28 - 0
supervisor/tests/test_datatypes.py

@@ -557,3 +557,31 @@ class SignalNumberTests(unittest.TestCase):
         except ValueError, e:
             expected = "value BADSIG is not a valid signal name"
             self.assertEqual(e.args[0], expected)
+
+class AutoRestartTests(unittest.TestCase):
+    def _callFUT(self, arg):
+        from supervisor.datatypes import auto_restart
+        return auto_restart(arg)
+
+    def test_converts_truthy(self):
+        from supervisor.datatypes import RestartUnconditionally
+        from supervisor.datatypes import TRUTHY_STRINGS
+        for s in TRUTHY_STRINGS:
+            self.assertEqual(self._callFUT(s), RestartUnconditionally)
+
+    def test_converts_falsy(self):
+        from supervisor.datatypes import FALSY_STRINGS
+        for s in FALSY_STRINGS:
+            self.assertFalse(self._callFUT(s))
+
+    def test_converts_unexpected(self):
+        from supervisor.datatypes import RestartWhenExitUnexpected
+        for s in ('unexpected', 'UNEXPECTED'):
+            self.assertEqual(self._callFUT(s), RestartWhenExitUnexpected)
+
+    def test_raises_for_bad_value(self):
+        try:
+            self.assertEqual(self._callFUT('bad'))
+            self.fail()
+        except ValueError, e:
+            self.assertEqual(e.args[0], "invalid 'autorestart' value 'bad'")