[Buildbot-commits] buildbot/buildbot/test test_vc.py,1.36,1.37

Brian Warner warner at users.sourceforge.net
Wed Aug 3 23:47:31 UTC 2005


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

Modified Files:
	test_vc.py 
Log Message:
Revision: arch at buildbot.sf.net--2004/buildbot--dev--0--patch-264
Creator:  Brian Warner <warner at monolith.lothar.com>

start work on 'try', document the 'buildbot' command-line tool

	* buildbot/trybuild.py: new file for 'try' utilities
	(getSourceStamp): run in a tree, find out the baserev+patch
	* buildbot/test/test_vc.py (VCBase.do_getpatch): test it,
	implemented for SVN and Darcs, still working on Arch. I don't know
	how to make CVS work yet.

	* docs/buildbot.texinfo: document the 'buildbot' command-line
	tool, including the not-yet-implemented 'try' feature, and the
	in-flux .buildbot/ options directory.


Index: test_vc.py
===================================================================
RCS file: /cvsroot/buildbot/buildbot/buildbot/test/test_vc.py,v
retrieving revision 1.36
retrieving revision 1.37
diff -u -d -r1.36 -r1.37
--- test_vc.py	20 Jul 2005 08:08:23 -0000	1.36
+++ test_vc.py	3 Aug 2005 23:47:29 -0000	1.37
@@ -13,7 +13,7 @@
 from twisted.python import log
 #log.startLogging(sys.stderr)
 
-from buildbot import master, interfaces
+from buildbot import master, interfaces, trybuild
 from buildbot.slave import bot
 from buildbot.status.builder import SUCCESS, FAILURE
 from buildbot.process import step, base
@@ -167,6 +167,29 @@
 }
 '''
 
+newfiles['fail_try'] = '''
+#include <stdio.h>
+
+int
+main(int argc, const char *argv[])
+{
+    printf("Hello world, %d\\n");
+    return 0;
+}
+'''
+
+newfiles['try_patch'] = '''
+@@ -4,6 +4,6 @@
+ int
+ main(int argc, const char *argv[])
+ {
+-    printf("Hello world, %d\\n", bogus);
++    printf("Hello world, %d\\n");
+     return 0;
+ }
+'''
+
+
 files['fixable.c'] = '''
 #include <stdio.h>
 
@@ -353,7 +376,8 @@
                 log.msg(" and stdout %s" % (out,))
                 log.msg(" and stderr %s" % (err,))
                 raise RuntimeError("command %s finished with exit code %d"
-                                   % (command, code))
+                                   % (command, code)
+                                   + ": see logs for stdout")
             return out
         d.addCallback(check)
         return d
@@ -366,6 +390,9 @@
         os.makedirs(basedir)
         for f in files.keys():
             open(os.path.join(basedir, f), "w").write(files[f])
+        # I don't actually need these quite yet, but may soon
+        #os.makedirs(os.path.join(basedir, "subdir"))
+        #open(os.path.join(basedir, "subdir", "subfile.c"),"w").write("sub\n")
 
     def doBuild(self, shouldSucceed=True, ss=None):
         c = interfaces.IControl(self.master)
@@ -662,6 +689,26 @@
         self.failUnlessIn("Hello world", data)
         self.shouldNotExist(self.workdir, "newbranchfile")
 
+    def do_getpatch(self, vctype, tmpdir):
+        workdir = os.path.join(self.repbase, tmpdir)
+        self.vctype = vctype
+        d = self.setup_try(tmpdir)
+        d.addCallback(self._doGetpatch_1, workdir)
+        return d
+    def _doGetpatch_1(self, res, workdir):
+        d = trybuild.getSourceStamp(self.vctype, workdir)
+        return d
+
+    def dumpPatch(self, patch):
+        # this exists to help me figure out the right 'patchlevel' value
+        # should be returned by trybuild.getSourceStamp
+        n = self.mktemp()
+        open(n,"w").write(patch)
+        d = self.runCommand(".", ["lsdiff", n])
+        def p(res): print "lsdiff:", res.strip().split("\n")
+        d.addCallback(p)
+        return d
+
 
     def tearDown(self):
         d = defer.succeed(None)
@@ -747,6 +794,15 @@
         shutil.rmtree(tmp)
     fix = deferredGenerator(fix)
 
+    def setup_try(self, tmpdir):
+        tmp = os.path.join(self.repbase, tmpdir)
+
+        w = self.do(self.repbase,
+                    "cvs -d %s checkout -d %s sample" % (self.cvsrep, tmpdir))
+        yield w; w.getResult()
+        open(os.path.join(tmp, "fail.c"), "w").write(newfiles['fail_try'])
+    setup_try = deferredGenerator(setup_try)
+
 
 class SVN(VCBase, unittest.TestCase):
     metadir = ".svn"
@@ -772,6 +828,26 @@
                            "sample/branch")
         return maybeWait(d)
 
+    def testTryGetPatch(self):
+        # extract the base revision and patch from a modified tree
+        d = self.do_getpatch("svn", "svn_trydir")
+        d.addCallback(self._testTryGetPatch_1)
+        return maybeWait(d)
+    def _testTryGetPatch_1(self, res):
+        baserev, (patchlevel, patch) = res
+        # because of the way SVN works, the baserev we get here will be the
+        # latest repository revision number, which could be either 3 or 4
+        # depending upon whether the other tests (specifically 'fix') have
+        # been run yet.
+        self.failUnless(baserev == 3 or baserev == 4,
+                        "baserev was not what we expected: %s" % baserev)
+        # regardless of whether the patch is taken against r3 or r4, our
+        # patch to fail.c will still be present
+        self.failUnlessIn(newfiles['try_patch'], patch,
+                          "did not see the expected patch in: %s" % patch)
+        self.failUnlessEqual(patchlevel, 0)
+        #return self.dumpPatch(patch)
+
     def createRepository(self):
         self.svnrep = os.path.join(self.repbase, "SVN-Repository")
         tmp = os.path.join(self.repbase, "svntmp")
@@ -784,7 +860,8 @@
 
         self.populate(tmp)
         w = self.do(tmp,
-                    "svn import -m sample_project_files %s" % self.svnurl_trunk)
+                    "svn import -m sample_project_files %s" %
+                    self.svnurl_trunk)
         yield w; w.getResult()
         shutil.rmtree(tmp)
 
@@ -815,6 +892,15 @@
         shutil.rmtree(tmp)
     fix = deferredGenerator(fix)
 
+    def setup_try(self, tmpdir):
+        tmp = os.path.join(self.repbase, tmpdir)
+        w = self.do(self.repbase,
+                    "svn checkout %s %s" % (self.svnurl_trunk, tmpdir))
+        yield w; w.getResult()
+        open(os.path.join(tmp, "fail.c"), "w").write(newfiles['fail_try'])
+    setup_try = deferredGenerator(setup_try)
+        
+
 class Darcs(VCBase, unittest.TestCase):
     metadir = None
     # Darcs has a metadir="_darcs", but it does not have an 'export'
@@ -857,6 +943,24 @@
                        testRetry=False)
         return maybeWait(d)
 
+    def testTryGetPatch(self):
+        # extract the base revision and patch from a modified tree
+        d = self.do_getpatch("darcs", "darcs_trydir")
+        d.addCallback(self._testTryGetPatch_1)
+        return maybeWait(d)
+    def _testTryGetPatch_1(self, res):
+        baserev, (patchlevel, patch) = res
+        self.failUnlessIn("[initial_import\ntest at buildbot.sf.net**", baserev,
+                             "baserev was not what we expected: %s" % baserev)
+        # the number of revisions depends upon whether we've run the 'fix'
+        # method yet or not.
+        self.failUnless(baserev.count("[") in (1,2))
+        self.failUnlessIn("initial_import\ntest at buildbot.sf.net**", baserev)
+        self.failUnlessIn(newfiles['try_patch'], patch,
+                          "did not see the expected patch in: %s" % patch)
+        self.failUnlessEqual(patchlevel, 1)
+        #return self.dumpPatch(patch)
+
     def createRepository(self):
         self.darcs_base = os.path.join(self.repbase, "Darcs-Repository")
         self.rep_trunk = os.path.join(self.darcs_base, "trunk")
@@ -904,6 +1008,17 @@
         shutil.rmtree(tmp)
     fix = deferredGenerator(fix)
 
+    def setup_try(self, tmpdir):
+        tmp = os.path.join(self.repbase, tmpdir)
+        os.makedirs(tmp)
+        w = self.do(tmp, "darcs initialize")
+        yield w; w.getResult()
+        w = self.do(tmp, "darcs pull -a %s" % self.rep_trunk)
+        yield w; w.getResult()
+
+        open(os.path.join(tmp, "fail.c"), "w").write(newfiles['fail_try'])
+    setup_try = deferredGenerator(setup_try)
+
 
 class Arch(VCBase, unittest.TestCase):
     metadir = None
@@ -996,6 +1111,24 @@
         d.addCallback(lambda res: self.unregisterRepository("tla"))
         return maybeWait(d)
 
+    def testArchTryGetPatch(self):
+        raise unittest.SkipTest("not yet implemented")
+        # extract the base revision and patch from a modified tree
+        self.archcmd = "tla"
+        d = self.unregisterRepository("tla")
+        d.addCallback(lambda res:
+                      self.do_getpatch("tla", "tla_trydir"))
+        d.addCallback(self._testArchTryGetPatch_1)
+        return maybeWait(d)
+    def _testArchTryGetPatch_1(self, res):
+        baserev, (patchlevel, patch) = res
+        rev = "test at buildbot.sf.net--testvc/testvc--mainline--1--patch-1"
+        self.failUnlessEqual(baserev, rev)
+        self.failUnlessIn(newfiles['try_patch'], patch,
+                          "did not see the expected patch in: %s" % patch)
+        self.failUnlessEqual(patchlevel, 1)
+        return self.dumpPatch(patch)
+
     def testBazaar(self):
         # NOTE: if you have baz archive caching turned on, this may get
         # confused. You can use 'baz cache-config --disable' to turn it off.
@@ -1291,6 +1424,42 @@
         yield w; w.getResult()
         shutil.rmtree(tmp)
     fix = deferredGenerator(fix)
+
+    def setup_try(self, tmpdir):
+        tmp = os.path.join(self.repbase, tmpdir)
+        a = "test at buildbot.sf.net--testvc"
+
+        cmd = "%s archives %s" % (self.archcmd, a)
+        w = self.do(self.repbase, cmd)
+        yield w; out = w.getResult()
+        assert out
+        lines = out.split("\n")
+        coordinates = lines[1].strip()
+
+        # now register the read-write location
+        w = waitForDeferred(self.registerRepository(self.archcmd,
+                                                    self.archrep))
+        yield w; w.getResult()
+
+        # the 'get' syntax is different between tla and baz. baz, while
+        # claiming to honor an --archive argument, in fact ignores it. The
+        # correct invocation is 'baz get archive/revision newdir'.
+        if self.archcmd == 'tla':
+            cmd = "tla get -A %s testvc--mainline--1 %s" % (a, tmpdir)
+        else:
+            cmd = "baz get %s/testvc--mainline--1 %s" % (a, tmpdir)
+        w = self.do(self.repbase, cmd)
+                    
+        yield w; w.getResult()
+
+        open(os.path.join(tmp, "fail.c"), "w").write(newfiles['fail_try'])
+
+        # now re-register the original coordinates
+        #w = waitForDeferred(self.registerRepository(self.archcmd,
+        #                                            coordinates))
+        #yield w; w.getResult()
+        #shutil.rmtree(tmp)
+    setup_try = deferredGenerator(setup_try)
     
 
 class Sources(unittest.TestCase):





More information about the Commits mailing list