[pypy-svn] r76912 - in pypy/build/bot2/pypybuildbot: . test

antocuni at codespeak.net antocuni at codespeak.net
Tue Sep 7 12:51:45 CEST 2010


Author: antocuni
Date: Tue Sep  7 12:51:44 2010
New Revision: 76912

Modified:
   pypy/build/bot2/pypybuildbot/builds.py
   pypy/build/bot2/pypybuildbot/summary.py
   pypy/build/bot2/pypybuildbot/test/test_builds.py
   pypy/build/bot2/pypybuildbot/test/test_summary.py
Log:
- rename TestRunnerCmd into PytestCmd

- make it working properly for steps which run more than one py.test (e.g., the Translated one)

- write tests :-)



Modified: pypy/build/bot2/pypybuildbot/builds.py
==============================================================================
--- pypy/build/bot2/pypybuildbot/builds.py	(original)
+++ pypy/build/bot2/pypybuildbot/builds.py	Tue Sep  7 12:51:44 2010
@@ -55,10 +55,12 @@
         #self.command = ['cp', '/tmp/pypy-c', '.']
 
 
-class TestRunnerCmd(ShellCmd):
+class PytestCmd(ShellCmd):
 
     def commandComplete(self, cmd):
         from pypybuildbot.summary import RevisionOutcomeSet
+        if 'pytestLog' not in cmd.logs:
+            return
         pytestLog = cmd.logs['pytestLog']
         outcome = RevisionOutcomeSet(None)
         outcome.populate(pytestLog)
@@ -78,7 +80,11 @@
         except KeyError:
             return
         else:
-            builder.summary_by_branch_and_revision[(branch, rev)] = summary
+            d = builder.summary_by_branch_and_revision
+            key = (branch, rev)
+            if key in d:
+                summary += d[key]
+            d[key] = summary
         builder.saveYourself()
 
 # ________________________________________________________________
@@ -107,7 +113,7 @@
 
         setup_steps(platform, self)
 
-        self.addStep(TestRunnerCmd(
+        self.addStep(PytestCmd(
             description="pytest",
             command=["python", "testrunner/runner.py",
                      "--logfile=testrun.log",
@@ -137,7 +143,7 @@
         if app_tests:
             if app_tests == True:
                 app_tests = []
-            self.addStep(TestRunnerCmd(
+            self.addStep(PytestCmd(
                 description="app-level (-A) test",
                 command=["python", "testrunner/runner.py",
                          "--logfile=pytest-A.log",
@@ -149,7 +155,7 @@
                 env={"PYTHONPATH": ['.']}))
 
         if lib_python:
-            self.addStep(ShellCmd(
+            self.addStep(PytestCmd(
                 description="lib-python test",
                 command=["python", "pypy/test_all.py",
                          "--pypy=pypy/translator/goal/pypy-c",
@@ -158,7 +164,7 @@
 
         if pypyjit:
             # upload nightly build, if we're running jit tests
-            self.addStep(ShellCmd(
+            self.addStep(PytestCmd(
                 description="pypyjit tests",
                 command=["python", "pypy/test_all.py",
                          "--pypy=pypy/translator/goal/pypy-c",

Modified: pypy/build/bot2/pypybuildbot/summary.py
==============================================================================
--- pypy/build/bot2/pypybuildbot/summary.py	(original)
+++ pypy/build/bot2/pypybuildbot/summary.py	Tue Sep  7 12:51:44 2010
@@ -33,9 +33,18 @@
     def is_ok(self):
         return self.F == 0
 
+    def to_tuple(self):
+        return self.p, self.F, self.s, self.x
+
     def __str__(self):
         return '%d, %d F, %d s, %d x' % (self.p, self.F, self.s, self.x)
 
+    def __add__(self, other):
+        return self.__class__(self.p + other.p,
+                              self.F + other.F,
+                              self.s + other.s,
+                              self.x + other.x)
+
 class RevisionOutcomeSet(object):
 
     def __init__(self, rev, key=None, run_info=None):

Modified: pypy/build/bot2/pypybuildbot/test/test_builds.py
==============================================================================
--- pypy/build/bot2/pypybuildbot/test/test_builds.py	(original)
+++ pypy/build/bot2/pypybuildbot/test/test_builds.py	Tue Sep  7 12:51:44 2010
@@ -1,4 +1,5 @@
 import py
+from cStringIO import StringIO
 from pypybuildbot import builds
 
 class FakeProperties(object):
@@ -60,3 +61,73 @@
     rebuilt.start()
     assert pth.join('mstr').check(dir=True)
     assert rebuilt.masterdest == str(pth.join('mstr', 'trunk', 'base-123'))
+
+class TestPytestCmd(object):
+    
+    class Fake(object):
+        def __init__(self, **kwds):
+            self.__dict__.update(kwds)
+
+    class FakeBuildStatus(Fake):
+        def getProperties(self):
+            return self.properties
+
+    class FakeBuilder(Fake):
+        def saveYourself(self):
+            pass
+
+    def _create(self, log, rev, branch):
+        if isinstance(log, str):
+            log = StringIO(log)
+        step = builds.PytestCmd()
+        step.build = self.Fake()
+        step.build.build_status = self.FakeBuildStatus(properties={'got_revision': rev,
+                                                                   'branch': branch})
+        step.build.build_status.builder = builder = self.FakeBuilder()
+        cmd = self.Fake(logs={'pytestLog': log})
+        return step, cmd, builder
+
+    def test_no_log(self):
+        step = builds.PytestCmd()
+        cmd = self.Fake(logs={})
+        assert step.commandComplete(cmd) is None
+
+    def test_empty_log(self):
+        step, cmd, builder = self._create(log='', rev='123', branch='trunk')
+        step.commandComplete(cmd)
+        summary = builder.summary_by_branch_and_revision[('trunk', '123')]
+        assert summary.to_tuple() == (0, 0, 0, 0)
+
+    def test_summary(self):
+        log = """F a/b.py:test_one
+. a/b.py:test_two
+s a/b.py:test_three
+S a/c.py:test_four
+"""
+        step, cmd, builder = self._create(log=log, rev='123', branch='trunk')
+        step.commandComplete(cmd)
+        summary = builder.summary_by_branch_and_revision[('trunk', '123')]
+        assert summary.to_tuple() == (1, 1, 2, 0)
+
+    def test_branch_is_None(self): 
+        step, cmd, builder = self._create(log='', rev='123', branch=None)
+        step.commandComplete(cmd)
+        assert ('trunk', '123') in builder.summary_by_branch_and_revision
+
+    def test_trailing_slash(self):
+        step, cmd, builder = self._create(log='', rev='123', branch='branch/foo/')
+        step.commandComplete(cmd)
+        assert ('branch/foo', '123') in builder.summary_by_branch_and_revision
+        
+    def test_multiple_logs(self):
+        log = """F a/b.py:test_one
+. a/b.py:test_two
+s a/b.py:test_three
+S a/c.py:test_four
+"""
+        step, cmd, builder = self._create(log=log, rev='123', branch='trunk')
+        step.commandComplete(cmd)
+        cmd.logs['pytestLog'] = StringIO(log) # "reopen" the file
+        step.commandComplete(cmd)
+        summary = builder.summary_by_branch_and_revision[('trunk', '123')]
+        assert summary.to_tuple() == (2, 2, 4, 0)

Modified: pypy/build/bot2/pypybuildbot/test/test_summary.py
==============================================================================
--- pypy/build/bot2/pypybuildbot/test/test_summary.py	(original)
+++ pypy/build/bot2/pypybuildbot/test/test_summary.py	Tue Sep  7 12:51:44 2010
@@ -9,6 +9,13 @@
 
 class TestOutcomes(object):
 
+    def test_OutcomeSummary(self):
+        s = summary.OutcomeSummary(1, 2, 3, 4)
+        assert s.to_tuple() == (1, 2, 3, 4)
+        assert str(s) == '1, 2 F, 3 s, 4 x'
+        s2 = s+s
+        assert s2.to_tuple() == (2, 4, 6, 8)
+
     def test_populate(self):
         rev_outcome_set = summary.RevisionOutcomeSet(50000, ('foo', 40))
 



More information about the Pypy-commit mailing list