ComponentTestBase: add dirs argument to _check_repo_state()
authorMarkus Lehtonen <markus.lehtonen@linux.intel.com>
Fri, 18 Jul 2014 12:37:48 +0000 (15:37 +0300)
committerMarkus Lehtonen <markus.lehtonen@linux.intel.com>
Fri, 14 Nov 2014 12:21:38 +0000 (14:21 +0200)
Make difference between regular files and directories, eliminating the
requirement of listing directories in the file list.

Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com>
tests/component/__init__.py
tests/component/rpm/test_import_srpm.py

index b509c3b..a6979ec 100644 (file)
@@ -145,7 +145,8 @@ class ComponentTestBase(object):
         return set(blobs)
 
     @classmethod
-    def _check_repo_state(cls, repo, current_branch, branches, files=None):
+    def _check_repo_state(cls, repo, current_branch, branches, files=None,
+                          dirs=None):
         """Check that repository is clean and given branches exist"""
         branch = repo.branch
         eq_(branch, current_branch)
@@ -154,20 +155,24 @@ class ComponentTestBase(object):
         assert_msg = "Branches: expected %s, found %s" % (branches,
                                                           local_branches)
         eq_(set(local_branches), set(branches), assert_msg)
-        if files is not None:
+        if files is not None or dirs is not None:
             # Get files of the working copy recursively
-            local = set()
+            local_f = set()
+            local_d = set()
             for dirpath, dirnames, filenames in os.walk(repo.path):
                 # Skip git dir(s)
                 if '.git' in dirnames:
                     dirnames.remove('.git')
                 for filename in filenames:
-                    local.add(os.path.relpath(os.path.join(dirpath, filename),
-                                              repo.path))
+                    local_f.add(os.path.relpath(os.path.join(dirpath, filename),
+                                                repo.path))
                 for dirname in dirnames:
-                    local.add(os.path.relpath(os.path.join(dirpath, dirname),
-                                              repo.path) + '/')
-            cls.check_files(files, local)
+                    local_d.add(os.path.relpath(os.path.join(dirpath, dirname),
+                                                repo.path) + '/')
+            if files is not None:
+                cls.check_files(files, local_f)
+            if dirs is not None:
+                cls.check_files(dirs, local_d)
 
     def _capture_log(self, capture=True):
         """ Capture log"""
index d0e7170..acd8443 100644 (file)
@@ -94,7 +94,7 @@ class TestImportPacked(ComponentTestBase):
         srpm = os.path.join(DATA_DIR, 'gbp-test-native-1.0-1.src.rpm')
         eq_(mock_import(['--native', srpm]), 0)
         # Check repository state
-        files = {'.gbp.conf', 'Makefile', 'README', 'dummy.sh', 'packaging/',
+        files = {'.gbp.conf', 'Makefile', 'README', 'dummy.sh',
                  'packaging/gbp-test-native.spec'}
         repo = GitRepository('gbp-test-native')
         self._check_repo_state(repo, 'master', ['master'], files)
@@ -195,11 +195,10 @@ class TestImportPacked(ComponentTestBase):
                     srpm]), 0)
         # Check repository state
         repo = GitRepository('gbp-test2')
-        files = {'Makefile', 'README', 'dummy.sh', 'packaging/',
-                 'packaging/bar.tar.gz', 'packaging/foo.txt',
-                 'packaging/gbp-test2.spec', 'packaging/gbp-test2-alt.spec',
-                 'packaging/my.patch', 'packaging/my2.patch',
-                 'packaging/my3.patch'}
+        files = {'Makefile', 'README', 'dummy.sh', 'packaging/bar.tar.gz',
+                 'packaging/foo.txt', 'packaging/gbp-test2.spec',
+                 'packaging/gbp-test2-alt.spec', 'packaging/my.patch',
+                 'packaging/my2.patch', 'packaging/my3.patch'}
         self._check_repo_state(repo, 'pack', ['pack', 'orig'], files)
         eq_(len(repo.get_commits()), 2)
         # Check packaging dir