소스 검색

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(), 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):
     def test_make_namespec(self):
         from supervisor.options import make_namespec