]> git.apps.os.sepia.ceph.com Git - teuthology.git/commitdiff
test: move fs fakes to a common file
authorJosh Durgin <jdurgin@redhat.com>
Fri, 20 Nov 2015 22:13:07 +0000 (14:13 -0800)
committerJosh Durgin <jdurgin@redhat.com>
Wed, 9 Dec 2015 21:04:54 +0000 (13:04 -0800)
This will be useful for other tests shortly.

Signed-off-by: Josh Durgin <jdurgin@redhat.com>
teuthology/test/fake_fs.py [new file with mode: 0644]
teuthology/test/test_suite.py

diff --git a/teuthology/test/fake_fs.py b/teuthology/test/fake_fs.py
new file mode 100644 (file)
index 0000000..e3f0990
--- /dev/null
@@ -0,0 +1,67 @@
+
+def make_fake_fstools(fake_filesystem):
+    """
+    Build a fake listdir() and isfile(), to be used instead of
+    os.listir() and os.isfile()
+
+    An example fake_filesystem value:
+        >>> fake_fs = {
+            'a_directory': {
+                'another_directory': {
+                    'a_file': None,
+                    'another_file': None,
+                },
+                'random_file': None,
+                'yet_another_directory': {
+                    'empty_directory': {},
+                },
+            },
+        }
+
+        >>> fake_listdir = make_fake_listdir(fake_fs)
+        >>> fake_listdir('a_directory/yet_another_directory')
+        ['empty_directory']
+        >>> fake_isfile('a_directory/yet_another_directory')
+        False
+
+    :param fake_filesystem: A dict representing a filesystem layout
+    """
+    assert isinstance(fake_filesystem, dict)
+
+    def fake_listdir(path, fsdict=False):
+        if fsdict is False:
+            fsdict = fake_filesystem
+
+        remainder = path.strip('/') + '/'
+        subdict = fsdict
+        while '/' in remainder:
+            next_dir, remainder = remainder.split('/', 1)
+            if next_dir not in subdict:
+                raise OSError(
+                    '[Errno 2] No such file or directory: %s' % next_dir)
+            subdict = subdict.get(next_dir)
+            if not isinstance(subdict, dict):
+                raise OSError('[Errno 20] Not a directory: %s' % next_dir)
+            if subdict and not remainder:
+                return subdict.keys()
+        return []
+
+    def fake_isfile(path, fsdict=False):
+        if fsdict is False:
+            fsdict = fake_filesystem
+
+        components = path.strip('/').split('/')
+        subdict = fsdict
+        for component in components:
+            if component not in subdict:
+                raise OSError(
+                    '[Errno 2] No such file or directory: %s' % component)
+            subdict = subdict.get(component)
+        if subdict is None:
+            return True
+        else:
+            return False
+
+    def fake_isdir(path, fsdict=False):
+        return not fake_isfile(path)
+    return fake_listdir, fake_isfile, fake_isdir
index e1ecd4ce77f0dca3da33cf5a573af0b8630630ab..a0a5b0875971dcc42c667b0c7f9e60b8452ba05a 100644 (file)
@@ -3,6 +3,7 @@ from datetime import datetime
 
 from mock import patch, Mock, DEFAULT
 
+from fake_fs import make_fake_fstools
 from teuthology import suite
 from scripts.suite import main
 from teuthology.config import config
@@ -358,74 +359,6 @@ class TestDistroDefaults(object):
                                                               'rpm')
 
 
-def make_fake_fstools(fake_filesystem):
-    """
-    Build a fake listdir() and isfile(), to be used instead of
-    os.listir() and os.isfile()
-
-    An example fake_filesystem value:
-        >>> fake_fs = {
-            'a_directory': {
-                'another_directory': {
-                    'a_file': None,
-                    'another_file': None,
-                },
-                'random_file': None,
-                'yet_another_directory': {
-                    'empty_directory': {},
-                },
-            },
-        }
-
-        >>> fake_listdir = make_fake_listdir(fake_fs)
-        >>> fake_listdir('a_directory/yet_another_directory')
-        ['empty_directory']
-        >>> fake_isfile('a_directory/yet_another_directory')
-        False
-
-    :param fake_filesystem: A dict representing a filesystem layout
-    """
-    assert isinstance(fake_filesystem, dict)
-
-    def fake_listdir(path, fsdict=False):
-        if fsdict is False:
-            fsdict = fake_filesystem
-
-        remainder = path.strip('/') + '/'
-        subdict = fsdict
-        while '/' in remainder:
-            next_dir, remainder = remainder.split('/', 1)
-            if next_dir not in subdict:
-                raise OSError(
-                    '[Errno 2] No such file or directory: %s' % next_dir)
-            subdict = subdict.get(next_dir)
-            if not isinstance(subdict, dict):
-                raise OSError('[Errno 20] Not a directory: %s' % next_dir)
-            if subdict and not remainder:
-                return subdict.keys()
-        return []
-
-    def fake_isfile(path, fsdict=False):
-        if fsdict is False:
-            fsdict = fake_filesystem
-
-        components = path.strip('/').split('/')
-        subdict = fsdict
-        for component in components:
-            if component not in subdict:
-                raise OSError(
-                    '[Errno 2] No such file or directory: %s' % component)
-            subdict = subdict.get(component)
-        if subdict is None:
-            return True
-        else:
-            return False
-
-    def fake_isdir(path, fsdict=False):
-        return not fake_isfile(path)
-    return fake_listdir, fake_isfile, fake_isdir
-
-
 class TestBuildMatrix(object):
     def fragment_occurences(self, jobs, fragment):
         # What fraction of jobs contain fragment?