Переглянути джерело

Add tests for UnhosedConfigParser

Mike Naberezny 10 роки тому
батько
коміт
8ff1707e25
1 змінених файлів з 38 додано та 0 видалено
  1. 38 0
      supervisor/tests/test_options.py

+ 38 - 0
supervisor/tests/test_options.py

@@ -2489,6 +2489,44 @@ class SignalReceiverTests(unittest.TestCase):
         self.assertEqual(sr.get_signal(), signal.SIGCHLD)
         self.assertEqual(sr.get_signal(), signal.SIGCHLD)
         self.assertEqual(sr.get_signal(), None)
         self.assertEqual(sr.get_signal(), None)
 
 
+class UnhosedConfigParserTests(unittest.TestCase):
+    def _getTargetClass(self):
+        from supervisor.options import UnhosedConfigParser
+        return UnhosedConfigParser
+
+    def _makeOne(self, *args, **kw):
+        return self._getTargetClass()(*args, **kw)
+
+    def test_section_to_file_initially_empty(self):
+        config = self._makeOne()
+        self.assertEqual(config.section_to_file, {})
+
+    def test_section_to_file_read_one_file(self):
+        f = tempfile.NamedTemporaryFile()
+        try:
+            f.write("[foo]\n")
+            f.flush()
+            config = self._makeOne()
+            config.read([f.name])
+        finally:
+            f.close()
+        self.assertEqual(config.section_to_file['foo'], f.name)
+
+    def test_section_to_file_read_multiple_files(self):
+        f1 = tempfile.NamedTemporaryFile()
+        f2 = tempfile.NamedTemporaryFile()
+        try:
+            f1.write("[foo]\n")
+            f1.flush()
+            f2.write("[bar]\n")
+            f2.flush()
+            config = self._makeOne()
+            config.read([f1.name, f2.name])
+        finally:
+            f1.close()
+            f2.close()
+        self.assertEqual(config.section_to_file['foo'], '???')
+
 class UtilFunctionsTests(unittest.TestCase):
 class UtilFunctionsTests(unittest.TestCase):
     def test_make_namespec(self):
     def test_make_namespec(self):
         from supervisor.options import make_namespec
         from supervisor.options import make_namespec