浏览代码

Add tests for existing_dirpath

Mike Naberezny 11 年之前
父节点
当前提交
9def673186
共有 1 个文件被更改,包括 45 次插入0 次删除
  1. 45 0
      supervisor/tests/test_datatypes.py

+ 45 - 0
supervisor/tests/test_datatypes.py

@@ -345,6 +345,51 @@ class ExistingDirectoryTests(unittest.TestCase):
         finally:
             datatypes.here = None
 
+class ExistingDirpathTests(unittest.TestCase):
+    def _callFUT(self, arg):
+        return datatypes.existing_dirpath(arg)
+
+    def test_returns_existing_dirpath(self):
+        self.assertEqual(self._callFUT(__file__), __file__)
+
+    def test_returns_dirpath_if_relative(self):
+        self.assertEqual(self._callFUT('foo'), 'foo')
+
+    def test_raises_if_dir_does_not_exist(self):
+        path = os.path.join(os.path.dirname(__file__), 'nonexistant', 'foo')
+        try:
+            self._callFUT(path)
+            self.fail()
+        except ValueError, e:
+            expected = ('The directory named as part of the path %s '
+                        'does not exist.' % path)
+            self.assertEqual(e.args[0], expected)
+
+    def test_raises_if_exists_but_not_a_dir(self):
+        path = os.path.join(os.path.dirname(__file__),
+                            os.path.basename(__file__), 'foo')
+        try:
+            self._callFUT(path)
+            self.fail()
+        except ValueError, e:
+            expected = ('The directory named as part of the path %s '
+                        'does not exist.' % path)
+            self.assertEqual(e.args[0], expected)
+
+    def test_expands_home(self):
+        home = os.path.expanduser('~')
+        if os.path.exists(home):
+            path = self._callFUT('~/foo')
+            self.assertEqual(os.path.join(home, 'foo'), path)
+
+    def test_expands_here(self):
+        datatypes.here = os.path.dirname(__file__)
+        try:
+            expected = os.path.join(datatypes.here, 'foo')
+            self.assertEqual(self._callFUT('%(here)s/foo'), expected)
+        finally:
+            datatypes.here = None
+
 class LoggingLevelTests(unittest.TestCase):
     def _callFUT(self, arg):
         return datatypes.logging_level(arg)