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

pedronis at codespeak.net pedronis at codespeak.net
Sun Jan 18 00:08:33 CET 2009


Author: pedronis
Date: Sun Jan 18 00:08:32 2009
New Revision: 61071

Modified:
   pypy/build/bot2/pypybuildbot/summary.py
   pypy/build/bot2/pypybuildbot/test/test_summary.py
Log:
trying support for categories



Modified: pypy/build/bot2/pypybuildbot/summary.py
==============================================================================
--- pypy/build/bot2/pypybuildbot/summary.py	(original)
+++ pypy/build/bot2/pypybuildbot/summary.py	Sun Jan 18 00:08:32 2009
@@ -254,7 +254,7 @@
 
     def __init__(self, status):
         self.sections = []
-        self.cur_branch=None
+        self.cur_cat_branch=None
         self.fixed_builder = False
         self.status = status
 
@@ -286,11 +286,26 @@
             anchors.append(html.a(text, href=host_agnostic(info['URL'])))
         return anchors
 
-    def start_branch(self, branch):
-        self.cur_branch = branch
-        branch_anchor = html.a(branch, href="/summary?branch=%s" % branch,
+    def start_cat_branch(self, cat_branch):
+        category, branch = cat_branch
+        branch = trunk_name(branch)
+
+        if category is None:
+            cat_branch = ('-', branch)
+        self.cur_cat_branch = cat_branch
+
+        category, branch = cat_branch
+
+        cat_anchor = html.a("{%s}" % category,
+                            href="/summary?category=%s" % category,
+                            class_="failSummary branch")
+
+        branch_anchor = html.a(branch,
+                               href="/summary?category=%s&branch=%s" %
+                               cat_branch,
                                class_="failSummary branch")
-        self.sections.append(html.h2(branch_anchor))
+        
+        self.sections.append(html.h2(cat_anchor," ",branch_anchor))
 
     def _builder_anchor(self, builder):
         if self.fixed_builder:
@@ -320,8 +335,9 @@
             pick = "builder=%s&builds=%d" % self._builder_num(outcome_set)
         else:
             pick = "recentrev=%d" % rev
-        rev_anchor = html.a(str(rev), href="/summary?branch=%s&%s" %
-                            (self.cur_branch, pick))
+        category, branch = self.cur_cat_branch
+        rev_anchor = html.a(str(rev), href="/summary?category=%s&branch=%s&%s" %
+                            (category, branch, pick))
         return rev_anchor
                             
     def add_section(self, outcome_sets):
@@ -485,6 +501,7 @@
 
 trunk_name = make_subst(None, "<trunk>")
 trunk_value = make_subst("<trunk>", None)
+nocat_value = make_subst("-", None)
 
 def safe_int(v):
     try:
@@ -494,10 +511,11 @@
 
 class Summary(HtmlResource):
 
-    def __init__(self):
+    def __init__(self, categories=[]):
         HtmlResource.__init__(self)
         self.putChild('longrepr', LongRepr())
         self._defaultBranchCache = {}
+        self.categories = categories
 
     def getTitle(self, request):
         status = self.getStatus(request)        
@@ -535,15 +553,16 @@
         return branch
 
     def recentRuns(self, status, only_recentrevs=None, only_branches=None,
-                                 only_builder=None, only_builds=None):
+                                 only_builder=None, only_builds=None,
+                                 only_categories=None):
         test_rev = make_test(only_recentrevs)
         test_branch = make_test(only_branches)
         test_builder = make_test(only_builder)
         fixed_builder = bool(only_builder)
         
-        branches = {}
+        cat_branches = {}
 
-        for builderName in status.getBuilderNames():
+        for builderName in status.getBuilderNames(only_categories):
             if not test_builder(builderName):
                 continue
             builderStatus = status.getBuilder(builderName)
@@ -565,7 +584,10 @@
                 if not test_rev(got_rev):
                     continue
 
-                runs, no_revision_builds = branches.setdefault(branch,
+
+                cat_branch = (builderStatus.category, branch)
+
+                runs, no_revision_builds = cat_branches.setdefault(cat_branch,
                                                                ({}, []))
 
                 if got_rev is None:
@@ -582,7 +604,7 @@
                     if builderName not in builds:
                         builds[builderName] = build.getNumber()
 
-        for branch, (runs, no_revision_builds) in branches.items():
+        for cat_branch, (runs, no_revision_builds) in cat_branches.items():
             self._prune_runs(runs, N)
             for label, runBuilds in runs.iteritems():
                 for builderName, buildNumber in runBuilds.items():
@@ -590,7 +612,7 @@
                     outcome_set = outcome_set_cache.get(status, key)
                     runBuilds[builderName] = outcome_set
                             
-        return branches
+        return cat_branches
 
     @staticmethod
     def _parse_builds(build_select):
@@ -608,6 +630,13 @@
                     if (build_start is not None and build_end is not None):
                         builds.update(range(build_start, build_end+1))
         return builds
+
+    def _cat_branch_key(self, (category, branch)):
+        try:
+            i = self.categories.index(category)
+            return (0, i, branch)
+        except ValueError:
+            return (1, category, branch)
                             
     def body(self, request):
         t0 = time.time()
@@ -630,19 +659,26 @@
             build_select = request.args.get('builds', None)
             if build_select is not None:
                 only_builds = self._parse_builds(build_select)
-
-        branches = self.recentRuns(status,
-                                   only_recentrevs=only_recentrevs,
-                                   only_branches=only_branches,
-                                   only_builder=only_builder,
-                                   only_builds=only_builds)
-
-        for branch, (runs, no_revision_builds) in sorted(branches.iteritems()):
+        only_categories = request.args.get('category', None)
+        if only_categories is not None:
+            only_categories = map(nocat_value, only_categories)
+
+        cat_branches = self.recentRuns(status,
+                                   only_recentrevs = only_recentrevs,
+                                   only_branches = only_branches,
+                                   only_builder = only_builder,
+                                   only_builds = only_builds,
+                                   only_categories = only_categories
+                                   )
+
+
+        sorting = sorted(cat_branches.iterkeys(), key=self._cat_branch_key)
+        for cat_branch in sorting:
+            runs, no_revision_builds = cat_branches[cat_branch]
             outcome_sets = []
             for label, by_build in runs.items():
                 outcome_sets.append(GatherOutcomeSet(by_build))
-            branch = trunk_name(branch)
-            page.start_branch(branch)
+            page.start_cat_branch(cat_branch)
             page.add_section(outcome_sets)
             page.add_no_revision_builds(status, no_revision_builds)
 

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	Sun Jan 18 00:08:32 2009
@@ -298,13 +298,13 @@
     def getStatus(self):
         return self.status
 
-def witness_branches(summary):
+def witness_cat_branch(summary):
     ref = [None]
     recentRuns = summary.recentRuns
     def witness(*args, **kwds):
-        branches = recentRuns(*args, **kwds)
-        ref[0] = branches
-        return branches
+        cat_branch = recentRuns(*args, **kwds)
+        ref[0] = cat_branch
+        return cat_branch
     summary.recentRuns = witness
 
     return lambda: ref[0]
@@ -354,12 +354,12 @@
 
     def test_sanity(self):
         s = summary.Summary()
-        res = witness_branches(s)
+        res = witness_cat_branch(s)
         req = FakeRequest([])
         s.body(req)
-        branches = res()
+        cat_branch = res()
 
-        assert branches == {}
+        assert cat_branch == {}
 
     def test_one_build_no_rev(self):
         builder = status_builder.BuilderStatus('builder0')
@@ -369,12 +369,12 @@
         builder.nextBuildNumber = len(builder.buildCache)
 
         s = summary.Summary()
-        res = witness_branches(s)        
+        res = witness_cat_branch(s)        
         req = FakeRequest([builder])
         out = s.body(req)
-        branches = res()
+        cat_branch = res()
 
-        assert branches == {None: ({}, [build])}
+        assert cat_branch == {(None, None): ({}, [build])}
 
     def test_one_build_no_logs(self):
         builder = status_builder.BuilderStatus('builder0')
@@ -385,12 +385,12 @@
         builder.nextBuildNumber = len(builder.buildCache)
 
         s = summary.Summary()
-        res = witness_branches(s)        
+        res = witness_cat_branch(s)        
         req = FakeRequest([builder])
         out = s.body(req)
-        branches = res()
+        cat_branch = res()
         
-        revs = branches[None][0]
+        revs = cat_branch[(None, None)][0]
         assert revs.keys() == [50000]
 
         assert '&lt;run&gt;' in out
@@ -410,12 +410,12 @@
         builder.nextBuildNumber = len(builder.buildCache)
 
         s = summary.Summary()
-        res = witness_branches(s)        
+        res = witness_cat_branch(s)        
         req = FakeRequest([builder])
         out = s.body(req)
-        branches = res()
+        cat_branch = res()
         
-        revs = branches[None][0]
+        revs = cat_branch[(None, None)][0]
         assert revs.keys() == [50000]
 
         assert 'step borken' in out
@@ -426,12 +426,12 @@
         add_builds(builder, [(60000, "F TEST1\n. b")])
 
         s = summary.Summary()
-        res = witness_branches(s)        
+        res = witness_cat_branch(s)        
         req = FakeRequest([builder])
         out = s.body(req)
-        branches = res()
+        cat_branch = res()
 
-        revs = branches[None][0]
+        revs = cat_branch[(None, None)][0]
         assert revs.keys() == [60000]
         outcome = revs[60000]['builder0']
         assert outcome.revision == 60000
@@ -445,12 +445,12 @@
                              (60001, "F TEST1\n. b")])
 
         s = summary.Summary()
-        res = witness_branches(s)        
+        res = witness_cat_branch(s)        
         req = FakeRequest([builder])
         out = s.body(req)
-        branches = res()
+        cat_branch = res()
 
-        revs = branches[None][0]
+        revs = cat_branch[(None, None)][0]
         assert sorted(revs.keys()) == [60000, 60001]        
         outcome = revs[60000]['builder0']
         assert outcome.revision == 60000
@@ -473,12 +473,12 @@
                              (60000, "F TEST1\n. b")])        
 
         s = summary.Summary()
-        res = witness_branches(s)        
+        res = witness_cat_branch(s)        
         req = FakeRequest([builder])
         out = s.body(req)
-        branches = res()
+        cat_branch = res()
 
-        revs = branches[None][0]
+        revs = cat_branch[(None, None)][0]
         assert sorted(revs.keys()) == [60000]
         outcome = revs[60000]['builder0']
         assert outcome.revision == 60000
@@ -492,13 +492,13 @@
                              (60001, "F TEST1\n. b")])
 
         s = summary.Summary()
-        res = witness_branches(s)        
+        res = witness_cat_branch(s)        
         req = FakeRequest([builder])
         req.args = {'recentrev': ['60000']}
         out = s.body(req)
-        branches = res()
+        cat_branch = res()
 
-        revs = branches[None][0]
+        revs = cat_branch[(None, None)][0]
         assert sorted(revs.keys()) == [60000]
         outcome = revs[60000]['builder0']
         assert outcome.revision == 60000
@@ -513,13 +513,13 @@
                              (60001, "F TEST1\n. b")])        
 
         s = summary.Summary()
-        res = witness_branches(s)        
+        res = witness_cat_branch(s)        
         req = FakeRequest([builder])
         req.args={'builder': ['builder0']}
         out = s.body(req)
-        branches = res()
+        cat_branch = res()
 
-        runs = branches[None][0]
+        runs = cat_branch[(None, None)][0]
         assert sorted(runs.keys()) == [(60000,0), (60000,1), (60001,2)]
         outcome = runs[(60000,0)]['builder0']
         assert outcome.revision == 60000
@@ -549,14 +549,14 @@
                              (60001, "F TEST1\n. b")])        
 
         s = summary.Summary()
-        res = witness_branches(s)        
+        res = witness_cat_branch(s)        
         req = FakeRequest([builder])
         req.args={'builder': ['builder0'],
                   'builds': ['0','2-2', '7']}
         out = s.body(req)
-        branches = res()
+        cat_branch = res()
 
-        runs = branches[None][0]
+        runs = cat_branch[(None, None)][0]
         assert sorted(runs.keys()) == [(60000,0), (60001,2)]
         outcome = runs[(60000,0)]['builder0']
         assert outcome.revision == 60000
@@ -595,3 +595,45 @@
         assert 'TEST2' in out
         assert 'pytest aborted' not in out        
         assert 'pytest2 aborted' in out
+
+    def test_category_sorting_key(self):
+        s = summary.Summary(['foo', 'bar'])
+
+        res = s._cat_branch_key(('foo', 'trunk'))
+        assert res == (0, 0, 'trunk')
+
+        res = s._cat_branch_key(('bar', 'trunk'))
+        assert res == (0, 1, 'trunk')
+
+        res = s._cat_branch_key((None, 'trunk'))
+        assert res == (1, None, 'trunk')
+
+        res = s._cat_branch_key(('dontknow', 'trunk'))
+        assert res == (1, 'dontknow', 'trunk')                        
+
+    def test_builders_with_categories(self):
+        builder1 = status_builder.BuilderStatus('builder_foo')
+        builder1.category = 'foo'
+        builder2 = status_builder.BuilderStatus('builder_bar')
+        builder2.category = 'bar'
+        builder3 = status_builder.BuilderStatus('builder_')
+        builder3.category = None            
+
+        add_builds(builder1, [(60000, "F TEST1\n")])
+        add_builds(builder2, [(60000, "F TEST2\n")])
+        add_builds(builder3, [(60000, "F TEST3\n")])            
+
+        s = summary.Summary(['foo', 'bar'])
+        req = FakeRequest([builder1, builder2, builder3])
+        out = s.body(req)
+
+        rel1 = out.index('TEST1')
+        rel2 = out.index('TEST2')
+        rel3 = out.index('TEST3')
+
+        assert rel3 > rel2 > rel1
+
+        assert "{foo}" in out
+        assert "{bar}" in out
+
+        



More information about the Pypy-commit mailing list