Browse Source

Add a test that processes_from_section() shows filename on error

Mike Naberezny 10 years ago
parent
commit
700fb74191
1 changed files with 24 additions and 1 deletions
  1. 24 1
      supervisor/tests/test_options.py

+ 24 - 1
supervisor/tests/test_options.py

@@ -1120,7 +1120,7 @@ class ServerOptionsTests(unittest.TestCase):
         try:
         try:
             instance.processes_from_section(config, 'program:foo', None)
             instance.processes_from_section(config, 'program:foo', None)
             self.fail('nothing raised')
             self.fail('nothing raised')
-        except ValueError as exc:
+        except ValueError, exc:
             self.assertTrue(exc.args[0].startswith(
             self.assertTrue(exc.args[0].startswith(
                 'program section program:foo does not specify a command'))
                 'program section program:foo does not specify a command'))
 
 
@@ -1216,6 +1216,29 @@ class ServerOptionsTests(unittest.TestCase):
             self.fail('instance.processes_from_section should '
             self.fail('instance.processes_from_section should '
                       'raise a ValueError')
                       'raise a ValueError')
 
 
+    def test_processes_from_section_shows_conf_filename_on_valueerror(self):
+        instance = self._makeOne()
+        text = lstrip("""\
+        [program:foo]
+        ;no command
+        """)
+        f = tempfile.NamedTemporaryFile(mode="w+")
+        try:
+            f.write(text)
+            f.flush()
+            from supervisor.options import UnhosedConfigParser
+            config = UnhosedConfigParser()
+            config.read(f.name)
+            instance.processes_from_section(config, 'program:foo', None)
+        except ValueError, e:
+            self.assertEqual(e.args[0],
+                "program section program:foo does not specify a command "
+                "in section 'program:foo' (file: %s)" % f.name)
+        else:
+            self.fail('nothing raised')
+        finally:
+            f.close()
+
     def test_processes_from_autolog_without_rollover(self):
     def test_processes_from_autolog_without_rollover(self):
         instance = self._makeOne()
         instance = self._makeOne()
         text = lstrip("""\
         text = lstrip("""\