[Buildbot-commits] buildbot/buildbot/test test_vc.py,1.19,1.20

Brian Warner warner at users.sourceforge.net
Sat Apr 2 00:33:24 UTC 2005


Update of /cvsroot/buildbot/buildbot/buildbot/test
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11108/buildbot/test

Modified Files:
	test_vc.py 
Log Message:
rearrange probe-for-VC-program routine so the tests don't hang under
twisted-2.0


Index: test_vc.py
===================================================================
RCS file: /cvsroot/buildbot/buildbot/buildbot/test/test_vc.py,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -d -r1.19 -r1.20
--- test_vc.py	24 Nov 2004 22:02:01 -0000	1.19
+++ test_vc.py	2 Apr 2005 00:33:21 -0000	1.20
@@ -42,43 +42,62 @@
 # is running).
 
 
-RepositoryPath = None
-if os.environ.get("BUILDBOT_TEST_VC"):
-    p = os.path.join(os.path.expanduser(os.environ.get("BUILDBOT_TEST_VC")),
-                     "buildbot-test-vc-1")
-    if os.path.exists(os.path.join(p, "README")):
-        RepositoryPath = p
-        # some of them take a file: URI
-        RepositoryPath_URI = "file://" + RepositoryPath
-        # many VC systems can access the repository via HTTP
-        Repository_HTTP = "http://localhost:%d"
 
-have_arch, have_darcs, have_svn, have_cvs = False, False, False, False
-for p in os.environ['PATH'].split(":"):
-    if os.path.exists(os.path.join(p, 'tla')):
-        have_arch = True
-    if os.path.exists(os.path.join(p, 'darcs')):
-        have_darcs = True
-    if os.path.exists(os.path.join(p, 'svn')):
-        # we need svn to be compiled with the ra_local access module
-        from twisted.internet import utils
-        v = dr(utils.getProcessOutput('svn', ["--version"], env=os.environ))
-        if "handles 'file' schema" in v:
-            have_svn = True
-        else:
-            log.msg(("%s found but it does not support 'file:' schema, " +
-                     "skipping svn tests") % os.path.join(p, "svn"))
-    if os.path.exists(os.path.join(p, 'cvs')):
-        have_cvs = True
+class VCSupport:
+    """This holds everything we learn about the availability of VC tools on
+    the test host. A single instance of this is created when the first test
+    case is started, and remains available at the module level for all other
+    test cases."""
 
-if not have_svn:
-    log.msg("could not find usable 'svn', skipping Subversion tests")
-if not have_arch:
-    log.msg("could not find 'tla' on $PATH, skipping Arch tests")
-if not have_darcs:
-    log.msg("could not find 'darcs' on $PATH, skipping Darcs tests")
-if not have_cvs:
-    log.msg("could not find 'cvs' on $PATH, skipping CVS tests")
+    RepositoryPath = None
+    def __init__(self):
+        log.msg("test_vc now looking for VC programs")
+        if os.environ.get("BUILDBOT_TEST_VC"):
+            vcdir = os.path.expanduser(os.environ.get("BUILDBOT_TEST_VC"))
+            p = os.path.join(vcdir,
+                             "buildbot-test-vc-1")
+            if os.path.exists(os.path.join(p, "README")):
+                self.RepositoryPath = p
+                # some of them take a file: URI
+                self.RepositoryPath_URI = "file://" + self.RepositoryPath
+                # many VC systems can access the repository via HTTP
+                self.Repository_HTTP = "http://localhost:%d"
+
+        self.have = {'arch': False, 'darcs': False,
+                     'svn': False, 'cvs': False,
+                     }
+
+        for p in os.environ['PATH'].split(":"):
+            if os.path.exists(os.path.join(p, 'tla')):
+                self.have['arch'] = True
+            if os.path.exists(os.path.join(p, 'darcs')):
+                self.have['darcs'] = True
+            if os.path.exists(os.path.join(p, 'svn')):
+                # we need svn to be compiled with the ra_local access module
+                from twisted.internet import utils
+                log.msg("running svn --version..")
+                v = dr(utils.getProcessOutput('svn', ["--version"],
+                                              env=os.environ))
+                if "handles 'file' schema" in v:
+                    self.have['svn'] = True
+                else:
+                    log.msg(("%s found but it does not support 'file:' " +
+                             "schema, skipping svn tests") %
+                            os.path.join(p, "svn"))
+            if os.path.exists(os.path.join(p, 'cvs')):
+                self.have['cvs'] = True
+
+        if not self.have['svn']:
+            log.msg("could not find usable 'svn', skipping Subversion tests")
+        if not self.have['arch']:
+            log.msg("could not find 'tla' on $PATH, skipping Arch tests")
+        if not self.have['darcs']:
+            log.msg("could not find 'darcs' on $PATH, skipping Darcs tests")
+        if not self.have['cvs']:
+            log.msg("could not find 'cvs' on $PATH, skipping CVS tests")
+        log.msg("test_vc program scan done")
+
+VCS = None
 
 config_vc = """
 from buildbot.process import factory, step
@@ -140,21 +159,24 @@
         if self.sigchldHandler:
             signal.signal(signal.SIGCHLD, self.sigchldHandler)
 
-class SetupMixin:
+class SetupMixin(SignalMixin):
     master = None
     slave = None
-    serveHTTP = None
     httpServer = None
     httpPort = None
 
+    def setUpClass(self):
+        if VCS is None:
+            global VCS
+            VCS = VCSupport()
+        SignalMixin.setUpClass(self)
+        if not VCS.RepositoryPath:
+            raise unittest.SkipTest("provide "
+                                    "BUILDBOT_TEST_VC=path/to/repositories "
+                                    "to run this")
+
     def setUp(self):
-        if self.serveHTTP:
-            # launch an HTTP server to serve the repository files
-            from twisted.web import static, server
-            from twisted.internet import reactor
-            root = static.File(self.serveHTTP)
-            self.httpServer = reactor.listenTCP(0, server.Site(root))
-            self.httpPort = self.httpServer.getHost().port
+        self.serveHTTP()
         shutil.rmtree("basedir", ignore_errors=1)
         os.mkdir("basedir")
         self.master = master.BuildMaster("basedir")
@@ -162,6 +184,9 @@
         shutil.rmtree(self.slavebase, ignore_errors=1)
         os.mkdir("slavebase")
 
+    def serveHTTP(self):
+        pass
+
     def connectSlave(self):
         port = self.master.slavePort._port.getHost().port
         slave = bot.BuildSlave("localhost", port, "bot1", "sekrit",
@@ -301,28 +326,28 @@
             self.shouldNotExist(workdir, "newfile")
 
 
-class VC(SignalMixin, SetupMixin, unittest.TestCase):
+class VC(SetupMixin, unittest.TestCase):
 
     def testCVS(self):
-        if not have_cvs:
+        if not VCS.have['cvs']:
             raise unittest.SkipTest("CVS is not installed")
         self.do_vc("step.CVS", {
-            'cvsroot': RepositoryPath + "/CVS-Repository",
+            'cvsroot': VCS.RepositoryPath + "/CVS-Repository",
             'cvsmodule': "sample"},
                    metadir="CVS")
 
     def testSVN(self):
-        if not have_svn:
+        if not VCS.have['svn']:
             raise unittest.SkipTest("No usable Subversion was found")
         self.do_vc("step.SVN", {
-            'svnurl': RepositoryPath_URI + "/SVN-Repository/sample"},
+            'svnurl': VCS.RepositoryPath_URI + "/SVN-Repository/sample"},
                    metadir=".svn")
 
     def testDarcs(self):
-        if not have_darcs:
+        if not VCS.have['darcs']:
             raise unittest.SkipTest("Darcs is not installed")
         self.do_vc("step.Darcs", {
-            'repourl': RepositoryPath_URI + "/Darcs-Repository",
+            'repourl': VCS.RepositoryPath_URI + "/Darcs-Repository",
             },
                    testRetry=False)
         # Darcs has a metadir="_darcs", but it does not have an 'export'
@@ -332,10 +357,10 @@
         # Arch
 
     def testArch(self):
-        if not have_arch:
+        if not VCS.have['arch']:
             raise unittest.SkipTest("Arch (tla) is not installed")
         self.do_vc("step.Arch", {
-            'url': RepositoryPath + "/Arch-Repository",
+            'url': VCS.RepositoryPath + "/Arch-Repository",
             'version': "testvc--mainline--1",
             },
                    testRetry=False)
@@ -355,27 +380,34 @@
         # change it from the default, then 'tla update' won't work.
         os.system("tla register-archive -d test at buildbot.sf.net--testvc")
 
-class VC_HTTP(SignalMixin, SetupMixin, unittest.TestCase):
-    serveHTTP = RepositoryPath
+class VC_HTTP(SetupMixin, unittest.TestCase):
+    def serveHTTP(self):
+        # launch an HTTP server to serve the repository files
+        from twisted.web import static, server
+        from twisted.internet import reactor
+        root = static.File(VCS.RepositoryPath)
+        self.httpServer = reactor.listenTCP(0, server.Site(root))
+        self.httpPort = self.httpServer.getHost().port
 
     def testDarcsHTTP(self):
-        if not have_darcs:
+        if not VCS.have['darcs']:
             raise unittest.SkipTest("Darcs is not installed")
         self.do_vc("step.Darcs", {
-            'repourl': Repository_HTTP % self.httpPort + "/Darcs-Repository",
+            'repourl': (VCS.Repository_HTTP % self.httpPort +
+                        "/Darcs-Repository"),
             }, testRetry=False)
         # Darcs has a metadir="_darcs", but it does not have an 'export' mode
 
     def testArchHTTP(self):
-        if not have_arch:
+        if not VCS.have['arch']:
             raise unittest.SkipTest("Arch (tla) is not installed")
         self.do_vc("step.Arch", {
-            'url': Repository_HTTP % self.httpPort + "/Arch-Repository",
+            'url': VCS.Repository_HTTP % self.httpPort + "/Arch-Repository",
             'version': "testvc--mainline--1",
             }, testRetry=False)
         os.system("tla register-archive -d test at buildbot.sf.net--testvc")
 
-class Patch(SignalMixin, SetupMixin, unittest.TestCase):
+class Patch(SetupMixin, unittest.TestCase):
 
     def doPatch(self, vc, revision, **kwargs):
         m = self.master
@@ -419,18 +451,18 @@
 
 
     def testPatchCVS(self):
-        if not have_cvs:
+        if not VCS.have['cvs']:
             raise unittest.SkipTest("CVS is not installed")
         self.doPatch(vc=step.CVS,
-                     cvsroot= RepositoryPath + "/CVS-Repository",
+                     cvsroot= VCS.RepositoryPath + "/CVS-Repository",
                      cvsmodule="sample",
                      revision="today")
 
     def testPatchSVN(self):
-        if not have_svn:
+        if not VCS.have['svn']:
             raise unittest.SkipTest("No usable Subversion was found")
         self.doPatch(vc=step.SVN,
-                     svnurl= RepositoryPath_URI + "/SVN-Repository/sample",
+                     svnurl=VCS.RepositoryPath_URI + "/SVN-Repository/sample",
                      revision="HEAD")
 
 
@@ -482,9 +514,3 @@
         self.addChange(b, revision=67)
         s = step.SVN(svnurl=None, workdir=None, build=b)
         self.failUnlessEqual(s.computeSourceRevision(b.allChanges()), 67)
-
-
-if not RepositoryPath:
-    VC.skip = "provide BUILDBOT_TEST_VC=path/to/repositories to run this"
-    VC_HTTP.skip = "provide BUILDBOT_TEST_VC=path/to/repositories to run this"
-    Patch.skip = "provide BUILDBOT_TEST_VC=path/to/repositories to run this"





More information about the Commits mailing list