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, 18 Jul 2014 13:10:37 +0000 (16:10 +0300)
Change-Id: I01a421921c8783864d2a5c06d3299fc1ec5d13eb
Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com>
tests/component/__init__.py
tests/component/rpm/test_import_orig_rpm.py
tests/component/rpm/test_import_srpm.py
tests/component/rpm/test_pq_rpm.py

index 57d8692..31911e4 100644 (file)
@@ -147,7 +147,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)
@@ -156,20 +157,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 27cfab4..a85366b 100644 (file)
@@ -298,7 +298,7 @@ class TestImportOrig(ImportOrigTestBase):
         # Guessing from the original archive should succeed
         eq_(mock_import(['--no-interactive', '--merge', orig],
                         stdin_data=''), 0)
-        files = ['.gbp.conf', 'Makefile', 'README', 'dummy.sh', 'packaging/',
+        files = ['.gbp.conf', 'Makefile', 'README', 'dummy.sh',
                  'packaging/gbp-test-native.spec']
         self._check_repo_state(repo, 'master', ['master', 'upstream'], files)
         eq_(len(repo.get_commits(until='master')), 1)
index 6993391..4811794 100644 (file)
@@ -55,7 +55,7 @@ class TestImportPacked(ComponentTestBase):
         # Check repository state
         repo = GitRepository('gbp-test')
         files =  set(['Makefile', 'README', 'bar.tar.gz', 'dummy.sh', 'foo.txt',
-                  'gbp-test.spec', 'my.patch', 'mydir/', 'mydir/myfile.txt'])
+                  'gbp-test.spec', 'my.patch', 'mydir/myfile.txt'])
         self._check_repo_state(repo, 'master', ['master', 'upstream'], files)
         # Four commits: upstream, packaging files, one patch and the removal
         # of imported patches
@@ -68,8 +68,8 @@ class TestImportPacked(ComponentTestBase):
         # Check repository state
         repo = GitRepository('gbp-test2')
         files = set(['Makefile', 'README', 'bar.tar.gz', 'dummy.sh', 'foo.txt',
-                 'gbp-test2.spec', 'gbp-test2-alt.spec', 'my.patch', 'mydir/',
-                 'mydir/myfile.txt'])
+                     'gbp-test2.spec', 'gbp-test2-alt.spec', 'my.patch',
+                     'mydir/myfile.txt'])
         self._check_repo_state(repo, 'master', ['master', 'upstream'], files)
 
         # Four commits: upstream, packaging files, one patch and the removal
@@ -97,7 +97,7 @@ class TestImportPacked(ComponentTestBase):
         eq_(mock_import(['--native', srpm]), 0)
         # Check repository state
         files = set(['.gbp.conf', 'Makefile', 'README', 'dummy.sh',
-                     'packaging/', 'packaging/gbp-test-native.spec'])
+                     'packaging/gbp-test-native.spec'])
         repo = GitRepository('gbp-test-native')
         self._check_repo_state(repo, 'master', ['master'], files)
         # Only one commit: the imported source tarball
@@ -121,7 +121,7 @@ class TestImportPacked(ComponentTestBase):
         repo = GitRepository('gbp-test')
         files =  set(['Makefile', 'README', 'AUTHORS', 'NEWS', 'bar.tar.gz',
                     'dummy.sh', 'foo.txt', 'gbp-test.spec', 'my.patch',
-                    'mydir/', 'mydir/myfile.txt'])
+                    'mydir/myfile.txt'])
         self._check_repo_state(repo, 'master', ['master', 'upstream'], files)
         # Four commits: upstream, packaging files, three patches and the removal
         # of imported patches
@@ -147,7 +147,7 @@ class TestImportPacked(ComponentTestBase):
         # Import new version
         eq_(mock_import([srpms[2]]), 0)
         files = set(['Makefile', 'README', 'bar.tar.gz', 'dummy.sh', 'foo.txt',
-                 'gbp-test.spec', 'my.patch', 'mydir/', 'mydir/myfile.txt'])
+                 'gbp-test.spec', 'my.patch', 'mydir/myfile.txt'])
         self._check_repo_state(repo, 'master', ['master', 'upstream'], files)
         eq_(len(repo.get_commits()), 11)
         eq_(len(repo.get_commits(until='upstream')), 2)
@@ -195,7 +195,7 @@ class TestImportPacked(ComponentTestBase):
         # Check repository state
         repo = GitRepository('gbp-test')
         files = set(['Makefile', 'dummy.sh', 'bar.tar.gz', 'foo.txt',
-                 'gbp-test.spec', 'my.patch', 'mydir/', 'mydir/myfile.txt'])
+                 'gbp-test.spec', 'my.patch', 'mydir/myfile.txt'])
         self._check_repo_state(repo, 'master', ['master', 'upstream'], files)
 
     def test_misc_options(self):
@@ -213,11 +213,10 @@ class TestImportPacked(ComponentTestBase):
                     srpm]), 0)
         # Check repository state
         repo = GitRepository('gbp-test2')
-        files = set(['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 = set(['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
index 8b6f414..ba6229d 100644 (file)
@@ -77,7 +77,7 @@ class TestPqRpm(RpmRepoTestBase):
         branches = repo.get_local_branches() + ['development/master']
         # Test import
         eq_(mock_pq(['import']), 0)
-        files = ['AUTHORS', 'dummy.sh', 'Makefile', 'NEWS', 'README', 'mydir/',
+        files = ['AUTHORS', 'dummy.sh', 'Makefile', 'NEWS', 'README',
                  'mydir/myfile.txt', '.gbp.conf']
         branches.append('development/master')
         self._check_repo_state(repo, 'development/master', branches, files)
@@ -106,8 +106,8 @@ class TestPqRpm(RpmRepoTestBase):
         repo.set_branch('master-orphan')
         # Import
         eq_(mock_pq(['import']), 0)
-        files = ['dummy.sh', 'Makefile', 'README', 'mydir/',
-                 'mydir/myfile.txt', '.gbp.conf']
+        files = ['dummy.sh', 'Makefile', 'README', 'mydir/myfile.txt',
+                 '.gbp.conf']
         self._check_repo_state(repo, 'development/master-orphan', branches,
                                files)
 
@@ -203,7 +203,7 @@ class TestPqRpm(RpmRepoTestBase):
         # Import
         eq_(mock_pq(['import']), 0)
         pq_files = ['AUTHORS', 'dummy.sh', 'Makefile', 'NEWS', 'README',
-                    'mydir/', 'mydir/myfile.txt', '.gbp.conf']
+                    'mydir/myfile.txt', '.gbp.conf']
         branches.append('development/master')
         self._check_repo_state(repo, 'development/master', branches, pq_files)
 
@@ -258,13 +258,13 @@ class TestPqRpm(RpmRepoTestBase):
             tmp_patch.file.flush()
             eq_(mock_pq(['apply', tmp_patch.name]), 0)
         self._check_repo_state(repo, 'development/master', branches,
-                               upstr_files + ['mydir/', 'mydir/myfile.txt'])
+                               upstr_files + ['mydir/myfile.txt'])
 
     def test_convert(self):
         """Basic test for convert action"""
         repo = self.init_test_repo('gbp-test2')
         branches = repo.get_local_branches() + ['master-orphan']
-        files = ['packaging/', 'packaging/bar.tar.gz', 'packaging/foo.txt',
+        files = ['packaging/bar.tar.gz', 'packaging/foo.txt',
                  'packaging/gbp-test2.spec', 'packaging/gbp-test2-alt.spec',
                  'packaging/my.patch', 'packaging/0001-My-addition.patch',
                  '.gbp.conf']
@@ -531,9 +531,9 @@ class TestPqRpm(RpmRepoTestBase):
         """Test the --new-packaging-dir cmdline option"""
         repo = self.init_test_repo('gbp-test2')
         branches = repo.get_local_branches() + ['master-orphan']
-        files = ['rpm/', 'rpm/bar.tar.gz', 'rpm/foo.txt',
-                 'rpm/gbp-test2.spec', 'rpm/gbp-test2-alt.spec',
-                 'rpm/my.patch', 'rpm/0001-My-addition.patch']
+        files = ['rpm/bar.tar.gz', 'rpm/foo.txt', 'rpm/gbp-test2.spec',
+                 'rpm/gbp-test2-alt.spec', 'rpm/my.patch',
+                 'rpm/0001-My-addition.patch']
         # Drop already-existing master-orphan branch
         repo.delete_branch('master-orphan')
         # Try convert
@@ -545,7 +545,7 @@ class TestPqRpm(RpmRepoTestBase):
         """Test the --retain-history cmdline option"""
         repo = self.init_test_repo('gbp-test2')
         branches = repo.get_local_branches() + ['master-orphan']
-        files = ['packaging/', 'packaging/bar.tar.gz', 'packaging/foo.txt',
+        files = ['packaging/bar.tar.gz', 'packaging/foo.txt',
                  'packaging/gbp-test2.spec', 'packaging/gbp-test2-alt.spec',
                  'packaging/my.patch', 'packaging/0001-My-addition.patch',
                  '.gbp.conf']