[PATCH 08/20] tests: Factor out some code

Mathieu Bridon bochecha at fedoraproject.org
Wed Oct 29 12:57:06 UTC 2014


This code will be reused by other test cases.
---
 test/commands/__init__.py   | 76 ++++++++++++++++++++++++++++++++++++++++++++
 test/commands/test_clone.py | 77 +++------------------------------------------
 2 files changed, 80 insertions(+), 73 deletions(-)

diff --git a/test/commands/__init__.py b/test/commands/__init__.py
index e69de29..e55545b 100644
--- a/test/commands/__init__.py
+++ b/test/commands/__init__.py
@@ -0,0 +1,76 @@
+import os
+import shutil
+import subprocess
+import tempfile
+import unittest
+
+
+class CommandTestCase(unittest.TestCase):
+    def setUp(self):
+        self.path = tempfile.mkdtemp(prefix='rpkg-tests.')
+        self.gitroot = os.path.join(self.path, 'gitroot')
+
+        self.module = 'module1'
+
+        self.anongiturl = 'file://%s/%%(module)s' % self.gitroot
+        self.branchre = r'master|rpkg-tests-.+'
+        self.quiet = False
+
+        # TODO: Figure out how to handle this
+        self.lookaside = 'TODO'
+        self.lookasidehash = 'md5'
+        self.lookaside_cgi = 'TODO'
+        self.gitbaseurl = 'TODO'
+        self.kojiconfig = 'TODO'
+        self.build_client = 'TODO'
+        self.user = 'TODO'
+        self.dist = 'TODO'
+        self.target = 'TODO'
+
+    def tearDown(self):
+        shutil.rmtree(self.path)
+
+    def make_new_git(self, module, branches=None):
+        """Make a new git repo, so that tests can clone it
+
+        This is not a test method.
+        """
+        if branches is None:
+            branches = []
+
+        # Create a bare Git repository
+        moduledir = os.path.join(self.gitroot, module)
+        os.makedirs(moduledir)
+        subprocess.check_call(['git', 'init', '--bare'], cwd=moduledir,
+                              stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+
+        # Clone it, and do the minimal Dist Git setup
+        cloneroot = os.path.join(self.path, 'clonedir')
+        os.makedirs(cloneroot)
+        subprocess.check_call(['git', 'clone', 'file://%s' % moduledir],
+                              cwd=cloneroot, stdout=subprocess.PIPE,
+                              stderr=subprocess.PIPE)
+        clonedir = os.path.join(cloneroot, module)
+        open(os.path.join(clonedir, '.gitignore'), 'w').close()
+        open(os.path.join(clonedir, 'sources'), 'w').close()
+        subprocess.check_call(['git', 'add', '.gitignore', 'sources'],
+                              cwd=clonedir, stdout=subprocess.PIPE,
+                              stderr=subprocess.PIPE)
+        subprocess.check_call(['git', 'commit', '-m',
+                               'Initial setup of the repo'], cwd=clonedir,
+                              stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+        subprocess.check_call(['git', 'push', 'origin', 'master'],
+                              cwd=clonedir, stdout=subprocess.PIPE,
+                              stderr=subprocess.PIPE)
+
+        # Add the requested branches
+        for branch in branches:
+            subprocess.check_call(['git', 'branch', branch], cwd=clonedir,
+                                  stdout=subprocess.PIPE,
+                                  stderr=subprocess.PIPE)
+            subprocess.check_call(['git', 'push', 'origin', branch],
+                                  cwd=clonedir, stdout=subprocess.PIPE,
+                                  stderr=subprocess.PIPE)
+
+        # Drop the clone
+        shutil.rmtree(cloneroot)
diff --git a/test/commands/test_clone.py b/test/commands/test_clone.py
index f5a8030..0ed3ecf 100644
--- a/test/commands/test_clone.py
+++ b/test/commands/test_clone.py
@@ -1,80 +1,11 @@
 import os
 import shutil
-import subprocess
 import tempfile
-import unittest
-
-
-class CommandCloneTestCase(unittest.TestCase):
-    def setUp(self):
-        self.path = tempfile.mkdtemp(prefix='rpkg-tests.')
-        self.gitroot = os.path.join(self.path, 'gitroot')
-
-        self.module = 'module1'
-
-        self.anongiturl = 'file://%s/%%(module)s' % self.gitroot
-        self.branchre = r'master|rpkg-tests-.+'
-        self.quiet = False
-
-        # TODO: Figure out how to handle this
-        self.lookaside = 'TODO'
-        self.lookasidehash = 'md5'
-        self.lookaside_cgi = 'TODO'
-        self.gitbaseurl = 'TODO'
-        self.kojiconfig = 'TODO'
-        self.build_client = 'TODO'
-        self.user = 'TODO'
-        self.dist = 'TODO'
-        self.target = 'TODO'
-
-    def tearDown(self):
-        shutil.rmtree(self.path)
-
-    def make_new_git(self, module, branches=None):
-        """Make a new git repo, so that tests can clone it
-
-        This is not a test method.
-        """
-        if branches is None:
-            branches = []
-
-        # Create a bare Git repository
-        moduledir = os.path.join(self.gitroot, module)
-        os.makedirs(moduledir)
-        subprocess.check_call(['git', 'init', '--bare'], cwd=moduledir,
-                              stdout=subprocess.PIPE, stderr=subprocess.PIPE)
-
-        # Clone it, and do the minimal Dist Git setup
-        cloneroot = os.path.join(self.path, 'clonedir')
-        os.makedirs(cloneroot)
-        subprocess.check_call(['git', 'clone', 'file://%s' % moduledir],
-                              cwd=cloneroot, stdout=subprocess.PIPE,
-                              stderr=subprocess.PIPE)
-        clonedir = os.path.join(cloneroot, module)
-        open(os.path.join(clonedir, '.gitignore'), 'w').close()
-        open(os.path.join(clonedir, 'sources'), 'w').close()
-        subprocess.check_call(['git', 'add', '.gitignore', 'sources'],
-                              cwd=clonedir, stdout=subprocess.PIPE,
-                              stderr=subprocess.PIPE)
-        subprocess.check_call(['git', 'commit', '-m',
-                               'Initial setup of the repo'], cwd=clonedir,
-                              stdout=subprocess.PIPE, stderr=subprocess.PIPE)
-        subprocess.check_call(['git', 'push', 'origin', 'master'],
-                              cwd=clonedir, stdout=subprocess.PIPE,
-                              stderr=subprocess.PIPE)
-
-        # Add the requested branches
-        for branch in branches:
-            subprocess.check_call(['git', 'branch', branch], cwd=clonedir,
-                                  stdout=subprocess.PIPE,
-                                  stderr=subprocess.PIPE)
-            subprocess.check_call(['git', 'push', 'origin', branch],
-                                  cwd=clonedir, stdout=subprocess.PIPE,
-                                  stderr=subprocess.PIPE)
-
-        # Drop the clone
-        shutil.rmtree(cloneroot)
 
+from . import CommandTestCase
+
+
+class CommandCloneTestCase(CommandTestCase):
     def test_clone_anonymous(self):
         self.make_new_git(self.module)
 
-- 
2.1.0



More information about the rel-eng mailing list