[Buildbot-commits] buildbot/buildbot/test test_properties.py, 1.13, 1.14 test_steps.py, 1.47, 1.48 test_vc.py, 1.87, 1.88

Brian Warner warner at users.sourceforge.net
Thu May 22 22:12:59 UTC 2008


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

Modified Files:
	test_properties.py test_steps.py test_vc.py 
Log Message:
[project @ #124:properties-class.patch]
Add and use a Properties class, refactor the way properties are rendered,
and update unit tests accordingly.

Original author: dustin at v.igoro.us
Date: 2008-04-12 20:58:59+00:00

Index: test_properties.py
===================================================================
RCS file: /cvsroot/buildbot/buildbot/buildbot/test/test_properties.py,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -d -r1.13 -r1.14
--- test_properties.py	22 May 2008 22:11:36 -0000	1.13
+++ test_properties.py	22 May 2008 22:12:57 -0000	1.14
@@ -6,7 +6,8 @@
 
 from buildbot.sourcestamp import SourceStamp
 from buildbot.process import base
-from buildbot.steps.shell import ShellCommand, WithProperties
+from buildbot.process.properties import WithProperties, Properties
+from buildbot.steps.shell import ShellCommand
 from buildbot.status import builder
 from buildbot.slave.commands import rmdirRecursive
 from buildbot.test.runutils import RunMixin
@@ -26,7 +27,97 @@
 class FakeScheduler:
     name = "fakescheduler"
 
-class Interpolate(unittest.TestCase):
+class TestProperties(unittest.TestCase):
+    def setUp(self):
+        self.props = Properties()
+
+    def testDictBehavior(self):
+        self.props.setProperty("do-tests", 1, "scheduler")
+        self.props.setProperty("do-install", 2, "scheduler")
+
+        self.assert_(self.props.has_key('do-tests'))
+        self.failUnlessEqual(self.props['do-tests'], 1)
+        self.failUnlessEqual(self.props['do-install'], 2)
+        self.assertRaises(KeyError, lambda : self.props['do-nothing'])
+        self.failUnlessEqual(self.props.getProperty('do-install'), (2, 'scheduler'))
+
+    def testEmpty(self):
+        # test the special case for Null
+        self.props.setProperty("x", None, "hi")
+        self.failUnlessEqual(self.props.getProperty('x'), (None, 'hi'))
+        self.failUnlessEqual(self.props['x'], '')
+
+    def testUpdate(self):
+        self.props.setProperty("x", 24, "old")
+        newprops = { 'a' : 1, 'b' : 2 }
+        self.props.update(newprops, "new")
+
+        self.failUnlessEqual(self.props.getProperty('x'), (24, 'old'))
+        self.failUnlessEqual(self.props.getProperty('a'), (1, 'new'))
+
+    def testUpdateFromProperties(self):
+        self.props.setProperty("x", 24, "old")
+        newprops = Properties()
+        newprops.setProperty('a', 1, "new")
+        newprops.setProperty('b', 2, "new")
+        self.props.updateFromProperties(newprops)
+
+        self.failUnlessEqual(self.props.getProperty('x'), (24, 'old'))
+        self.failUnlessEqual(self.props.getProperty('a'), (1, 'new'))
+
+    # render() is pretty well tested by TestWithProperties
+
+class TestWithProperties(unittest.TestCase):
+    def setUp(self):
+        self.props = Properties()
+
+    def testBasic(self):
+        # test basic substitution with WithProperties
+        self.props.setProperty("revision", "47", "test")
+        command = WithProperties("build-%s.tar.gz", "revision")
+        self.failUnlessEqual(self.props.render(command),
+                             "build-47.tar.gz")
+
+    def testDict(self):
+        # test dict-style substitution with WithProperties
+        self.props.setProperty("other", "foo", "test")
+        command = WithProperties("build-%(other)s.tar.gz")
+        self.failUnlessEqual(self.props.render(command),
+                             "build-foo.tar.gz")
+
+    def testEmpty(self):
+        # None should render as ''
+        self.props.setProperty("empty", None, "test")
+        command = WithProperties("build-%(empty)s.tar.gz")
+        self.failUnlessEqual(self.props.render(command),
+                             "build-.tar.gz")
+
+    def testRecursiveList(self):
+        self.props.setProperty("x", 10, "test")
+        self.props.setProperty("y", 20, "test")
+        command = [ WithProperties("%(x)s %(y)s"), "and",
+                    WithProperties("%(y)s %(x)s") ]
+        self.failUnlessEqual(self.props.render(command),
+                             ["10 20", "and", "20 10"])
+
+    def testRecursiveTuple(self):
+        self.props.setProperty("x", 10, "test")
+        self.props.setProperty("y", 20, "test")
+        command = ( WithProperties("%(x)s %(y)s"), "and",
+                    WithProperties("%(y)s %(x)s") )
+        self.failUnlessEqual(self.props.render(command),
+                             ("10 20", "and", "20 10"))
+
+    def testRecursiveDict(self):
+        self.props.setProperty("x", 10, "test")
+        self.props.setProperty("y", 20, "test")
+        command = { WithProperties("%(x)s %(y)s") : 
+                    WithProperties("%(y)s %(x)s") }
+        self.failUnlessEqual(self.props.render(command),
+                             {"10 20" : "20 10"})
+
+class BuildProperties(unittest.TestCase):
+    """Test the properties that a build should have."""
     def setUp(self):
         self.builder = FakeBuilder()
         self.builder_status = builder.BuilderStatus("fakebuilder")
@@ -36,89 +127,21 @@
         os.mkdir(self.builder_status.basedir)
         self.build_status = self.builder_status.newBuild()
         req = base.BuildRequest("reason", SourceStamp(branch="branch2",
-                                                      revision=1234))
+                                                      revision="1234"))
         self.build = base.Build([req])
         self.build.setBuilder(self.builder)
         self.build.setupStatus(self.build_status)
         self.build.setupSlaveBuilder(FakeSlaveBuilder())
 
-    def testWithProperties(self):
-        self.build.setProperty("revision", 47)
-        self.failUnlessEqual(self.build_status.getProperty("revision"), 47)
-        c = ShellCommand(workdir=dir,
-                         command=["tar", "czf",
-                                  WithProperties("build-%s.tar.gz",
-                                                 "revision"),
-                                  "source"])
-        c.setBuild(self.build)
-        cmd = c._interpolateProperties(c.command)
-        self.failUnlessEqual(cmd,
-                             ["tar", "czf", "build-47.tar.gz", "source"])
+    def testProperties(self):
+        # if not started from a scheduler, the 'scheduler' property
+        # should be 'none'
         self.failUnlessEqual(self.build.getProperty("scheduler"), "none")
-
-    def testWorkdir(self):
-        self.build.setProperty("revision", 47)
-        self.failUnlessEqual(self.build_status.getProperty("revision"), 47)
-        c = ShellCommand(command=["tar", "czf", "foo.tar.gz", "source"])
-        c.setBuild(self.build)
-        workdir = WithProperties("workdir-%d", "revision")
-        workdir = c._interpolateWorkdir(workdir)
-        self.failUnlessEqual(workdir, "workdir-47")
-
-    def testWithPropertiesDict(self):
-        self.build.setProperty("other", "foo")
-        self.build.setProperty("missing", None)
-        c = ShellCommand(workdir=dir,
-                         command=["tar", "czf",
-                                  WithProperties("build-%(other)s.tar.gz"),
-                                  "source"])
-        c.setBuild(self.build)
-        cmd = c._interpolateProperties(c.command)
-        self.failUnlessEqual(cmd,
-                             ["tar", "czf", "build-foo.tar.gz", "source"])
-
-    def testWithPropertiesEmpty(self):
-        self.build.setProperty("empty", None)
-        c = ShellCommand(workdir=dir,
-                         command=["tar", "czf",
-                                  WithProperties("build-%(empty)s.tar.gz"),
-                                  "source"])
-        c.setBuild(self.build)
-        cmd = c._interpolateProperties(c.command)
-        self.failUnlessEqual(cmd,
-                             ["tar", "czf", "build-.tar.gz", "source"])
-
-    def testSourceStamp(self):
-        c = ShellCommand(workdir=dir,
-                         command=["touch",
-                                  WithProperties("%s-dir", "branch"),
-                                  WithProperties("%s-rev", "revision"),
-                                  ])
-        c.setBuild(self.build)
-        cmd = c._interpolateProperties(c.command)
-        self.failUnlessEqual(cmd,
-                             ["touch", "branch2-dir", "1234-rev"])
-
-    def testSlaveName(self):
-        c = ShellCommand(workdir=dir,
-                         command=["touch",
-                                  WithProperties("%s-slave", "slavename"),
-                                  ])
-        c.setBuild(self.build)
-        cmd = c._interpolateProperties(c.command)
-        self.failUnlessEqual(cmd,
-                             ["touch", "bot12-slave"])
-
-    def testBuildNumber(self):
-        c = ShellCommand(workdir=dir,
-                         command=["touch",
-                                  WithProperties("build-%d", "buildnumber"),
-                                  WithProperties("builder-%s", "buildername"),
-                                  ])
-        c.setBuild(self.build)
-        cmd = c._interpolateProperties(c.command)
-        self.failUnlessEqual(cmd,
-                             ["touch", "build-5", "builder-fakebuilder"])
+        self.failUnlessEqual(self.build.getProperty("branch"), "branch2")
+        self.failUnlessEqual(self.build.getProperty("revision"), "1234")
+        self.failUnlessEqual(self.build.getProperty("slavename"), "bot12")
+        self.failUnlessEqual(self.build.getProperty("buildnumber"), 5)
+        self.failUnlessEqual(self.build.getProperty("buildername"), "fakebuilder")
 
 class SchedulerTest(unittest.TestCase):
     def setUp(self):

Index: test_steps.py
===================================================================
RCS file: /cvsroot/buildbot/buildbot/buildbot/test/test_steps.py,v
retrieving revision 1.47
retrieving revision 1.48
diff -u -d -r1.47 -r1.48
--- test_steps.py	23 Dec 2007 08:35:31 -0000	1.47
+++ test_steps.py	22 May 2008 22:12:57 -0000	1.48
@@ -236,13 +236,13 @@
         s = makeBuildStep("test_steps.Steps.test_getProperty")
         bs = s.step_status.getBuild()
 
-        s.setProperty("prop1", "value1")
-        s.setProperty("prop2", "value2")
+        s.setProperty("prop1", "value1", "test")
+        s.setProperty("prop2", "value2", "test")
         self.failUnlessEqual(s.getProperty("prop1"), "value1")
         self.failUnlessEqual(bs.getProperty("prop1"), "value1")
         self.failUnlessEqual(s.getProperty("prop2"), "value2")
         self.failUnlessEqual(bs.getProperty("prop2"), "value2")
-        s.setProperty("prop1", "value1a")
+        s.setProperty("prop1", "value1a", "test")
         self.failUnlessEqual(s.getProperty("prop1"), "value1a")
         self.failUnlessEqual(bs.getProperty("prop1"), "value1a")
 
@@ -601,7 +601,7 @@
 line 23: warning: we are now on line 23
 ending line
 """
-        step.setProperty("warnings-count", 10)
+        step.setProperty("warnings-count", 10, "test")
         log = step.addLog("stdio")
         log.addStdout(output)
         log.finish()

Index: test_vc.py
===================================================================
RCS file: /cvsroot/buildbot/buildbot/buildbot/test/test_vc.py,v
retrieving revision 1.87
retrieving revision 1.88
diff -u -d -r1.87 -r1.88
--- test_vc.py	30 Mar 2008 01:30:00 -0000	1.87
+++ test_vc.py	22 May 2008 22:12:57 -0000	1.88
@@ -541,8 +541,8 @@
         self.shouldExist(self.workdir, "subdir", "subdir.c")
         if self.metadir:
             self.shouldExist(self.workdir, self.metadir)
-        self.failUnlessEqual(bs.getProperty("revision"), None)
-        self.failUnlessEqual(bs.getProperty("branch"), None)
+        self.failUnlessEqual(bs.getProperty("revision"), '')
+        self.failUnlessEqual(bs.getProperty("branch"), '')
         self.checkGotRevisionIsLatest(bs)
 
         self.touch(self.workdir, "newfile")
@@ -565,8 +565,8 @@
         self.shouldExist(self.workdir, "subdir", "subdir.c")
         if self.metadir:
             self.shouldExist(self.workdir, self.metadir)
-        self.failUnlessEqual(bs.getProperty("revision"), self.helper.trunk[0])
-        self.failUnlessEqual(bs.getProperty("branch"), None)
+        self.failUnlessEqual(bs.getProperty("revision"), self.helper.trunk[0] or '')
+        self.failUnlessEqual(bs.getProperty("branch"), '')
         self.checkGotRevision(bs, self.helper.trunk[0])
         # leave the tree at HEAD
         return self.doBuild()
@@ -585,7 +585,7 @@
                            "version=%d" % self.helper.version)
         if self.metadir:
             self.shouldExist(self.workdir, self.metadir)
-        self.failUnlessEqual(bs.getProperty("revision"), None)
+        self.failUnlessEqual(bs.getProperty("revision"), '')
         self.checkGotRevisionIsLatest(bs)
 
         self.touch(self.workdir, "newfile")
@@ -609,7 +609,7 @@
         self.shouldContain(self.workdir, "version.c",
                            "version=%d" % self.helper.version)
         self.shouldExist(self.workdir, "newfile")
-        self.failUnlessEqual(bs.getProperty("revision"), None)
+        self.failUnlessEqual(bs.getProperty("revision"), '')
         self.checkGotRevisionIsLatest(bs)
 
         # now "update" to an older revision
@@ -623,7 +623,7 @@
         self.shouldContain(self.workdir, "version.c",
                            "version=%d" % (self.helper.version-1))
         self.failUnlessEqual(bs.getProperty("revision"),
-                             self.helper.trunk[-2])
+                             self.helper.trunk[-2] or '')
         self.checkGotRevision(bs, self.helper.trunk[-2])
 
         # now update to the newer revision
@@ -637,7 +637,7 @@
         self.shouldContain(self.workdir, "version.c",
                            "version=%d" % self.helper.version)
         self.failUnlessEqual(bs.getProperty("revision"),
-                             self.helper.trunk[-1])
+                             self.helper.trunk[-1] or '')
         self.checkGotRevision(bs, self.helper.trunk[-1])
 
 
@@ -674,7 +674,7 @@
         self.shouldNotExist(self.workdir, "newfile")
         self.touch(self.workdir, "newfile")
         self.touch(self.vcdir, "newvcfile")
-        self.failUnlessEqual(bs.getProperty("revision"), None)
+        self.failUnlessEqual(bs.getProperty("revision"), '')
         self.checkGotRevisionIsLatest(bs)
 
         d = self.doBuild() # copy rebuild clobbers new files
@@ -687,7 +687,7 @@
         self.shouldNotExist(self.workdir, "newfile")
         self.shouldExist(self.vcdir, "newvcfile")
         self.shouldExist(self.workdir, "newvcfile")
-        self.failUnlessEqual(bs.getProperty("revision"), None)
+        self.failUnlessEqual(bs.getProperty("revision"), '')
         self.checkGotRevisionIsLatest(bs)
         self.touch(self.workdir, "newfile")
 
@@ -698,7 +698,7 @@
     def _do_vctest_export_1(self, bs):
         self.shouldNotExist(self.workdir, self.metadir)
         self.shouldNotExist(self.workdir, "newfile")
-        self.failUnlessEqual(bs.getProperty("revision"), None)
+        self.failUnlessEqual(bs.getProperty("revision"), '')
         #self.checkGotRevisionIsLatest(bs)
         # VC 'export' is not required to have a got_revision
         self.touch(self.workdir, "newfile")
@@ -709,7 +709,7 @@
     def _do_vctest_export_2(self, bs):
         self.shouldNotExist(self.workdir, self.metadir)
         self.shouldNotExist(self.workdir, "newfile")
-        self.failUnlessEqual(bs.getProperty("revision"), None)
+        self.failUnlessEqual(bs.getProperty("revision"), '')
         #self.checkGotRevisionIsLatest(bs)
         # VC 'export' is not required to have a got_revision
 
@@ -744,7 +744,7 @@
         data = open(subdir_c, "r").read()
         self.failUnlessIn("Hello patched subdir.\\n", data)
         self.failUnlessEqual(bs.getProperty("revision"),
-                             self.helper.trunk[-1])
+                             self.helper.trunk[-1] or '')
         self.checkGotRevision(bs, self.helper.trunk[-1])
 
         # make sure that a rebuild does not use the leftover patched workdir
@@ -758,7 +758,7 @@
                                 "subdir", "subdir.c")
         data = open(subdir_c, "r").read()
         self.failUnlessIn("Hello subdir.\\n", data)
-        self.failUnlessEqual(bs.getProperty("revision"), None)
+        self.failUnlessEqual(bs.getProperty("revision"), '')
         self.checkGotRevisionIsLatest(bs)
 
         # now make sure we can patch an older revision. We need at least two
@@ -783,7 +783,7 @@
         data = open(subdir_c, "r").read()
         self.failUnlessIn("Hello patched subdir.\\n", data)
         self.failUnlessEqual(bs.getProperty("revision"),
-                             self.helper.trunk[-2])
+                             self.helper.trunk[-2] or '')
         self.checkGotRevision(bs, self.helper.trunk[-2])
 
         # now check that we can patch a branch
@@ -802,8 +802,8 @@
         data = open(subdir_c, "r").read()
         self.failUnlessIn("Hello patched subdir.\\n", data)
         self.failUnlessEqual(bs.getProperty("revision"),
-                             self.helper.branch[-1])
-        self.failUnlessEqual(bs.getProperty("branch"), self.helper.branchname)
+                             self.helper.branch[-1] or '')
+        self.failUnlessEqual(bs.getProperty("branch"), self.helper.branchname or '')
         self.checkGotRevision(bs, self.helper.branch[-1])
 
 





More information about the Commits mailing list