genhtml: Correct navigation between pages
authorMichal Sojka <sojkam1@fel.cvut.cz>
Thu, 9 Dec 2010 13:01:49 +0000 (14:01 +0100)
committerMichal Sojka <sojkam1@fel.cvut.cz>
Thu, 9 Dec 2010 13:01:49 +0000 (14:01 +0100)
gw-tests/genhtml/genhtml-test.py
gw-tests/genhtml/genhtml.py

index 68d3131..cb93f32 100644 (file)
@@ -4,8 +4,8 @@ from genhtml import *
 @wvtest
 def Dimension_and_DimValue():
     d = Dimension('kern', 'Kernel')
-    d.addValue('2.6.31')
-    d.addValue('2.6.30')
+    DimValue(d, '2.6.31')
+    DimValue(d, '2.6.30')
     l=[]
     for v in d:
         WVPASSEQ(v.__class__, DimValue)
@@ -60,7 +60,25 @@ def Three_Dimensions_in_Tests():
     WVPASSEQ([d.__class__.__name__ for d in t.space.iterRemainingDimensions([dt])], ['DimensionKern', 'Dimension']) 
     WVPASSEQ([d.__class__.__name__ for d in t.space.iterRemainingDimensions([dt, dd])], ['DimensionKern'])
 
-    WVPASSEQ(str([v for v in Space(dt, dk).iterValues()]), "[[DimValue(DimensionTest, 1), DimValue(DimensionKern, 'a')]]")
-    dt.addValue(2)
-    dk.addValue('b')
-    WVPASSEQ(str([v for v in Space(dt, dk).iterValues()]), "[[DimValue(DimensionTest, 1), DimValue(DimensionKern, 'a')], [DimValue(DimensionTest, 2), DimValue(DimensionKern, 'a')], [DimValue(DimensionTest, 1), DimValue(DimensionKern, 'b')], [DimValue(DimensionTest, 2), DimValue(DimensionKern, 'b')]]")
+    WVPASSEQ(str([v for v in Space(dt, dk).iterValues()]), "[[DimValue(Dimension(test), 1), DimValue(Dimension(gwkern), 'a')]]")
+    DimValue(dt, 2)
+    DimValue(dk, 'b')
+    WVPASSEQ(str([v for v in Space(dt, dk).iterValues()]), "[[DimValue(Dimension(test), 1), DimValue(Dimension(gwkern), 'a')], [DimValue(Dimension(test), 2), DimValue(Dimension(gwkern), 'a')], [DimValue(Dimension(test), 1), DimValue(Dimension(gwkern), 'b')], [DimValue(Dimension(test), 2), DimValue(Dimension(gwkern), 'b')]]")
+
+@wvtest                
+def SpaceTests():
+    d1 = Dimension(1)
+    d2 = Dimension(2)
+    d3 = Dimension(3)
+    s = Space(d1, d2, d3)
+    WVPASSEQ(str(s), "[Dimension(1), Dimension(2), Dimension(3)]")
+    v11 = DimValue(d1, 'one-one')
+    v12 = DimValue(d1, 'one-two')
+    v21 = DimValue(d2, 'two-one')
+    v22 = DimValue(d2, 'two-two')
+    v31 = DimValue(d3, 'three-one')
+    WVPASSEQ(str(DimValues([v11, v21])), "[DimValue(Dimension(1), 'one-one'), DimValue(Dimension(2), 'two-one')]")
+    WVPASSEQ(str(DimValues([v11, v21]) - d1), "[DimValue(Dimension(2), 'two-one')]")
+    WVPASSEQ(str(DimValues([v11, v21]) - d2), "[DimValue(Dimension(1), 'one-one')]")
+    WVPASSEQ(str(DimValues([v21, v31]) + v11), "[DimValue(Dimension(2), 'two-one'), DimValue(Dimension(3), 'three-one'), DimValue(Dimension(1), 'one-one')]")
+    WVPASSEQ(str(s.reorder(DimValues([v21, v31, v11]))), "[DimValue(Dimension(1), 'one-one'), DimValue(Dimension(2), 'two-one'), DimValue(Dimension(3), 'three-one')]")
index 1ba9f7f..76eee7b 100755 (executable)
@@ -9,10 +9,11 @@ class DimValue:
     def __init__(self, dim, value):
        self.dim = dim
        self.value = value
+        self.dim.addValue(self)
     def __str__(self):
         return self.dim.val2str(self.value)
     def __repr__(self):
-       return "DimValue("+str(self.dim.__class__.__name__) + ", "+repr(self.value)+")"
+       return "DimValue(%s, %s)" % (repr(self.dim), repr(self.value))
     def htmlTableHeading(self):
        return self.dim.htmlTableHeading(self.value)
 
@@ -22,7 +23,9 @@ class DimValues(list):
             if self[i].dim == val.dim:
                 self[i] = val
     def __add__(self, val):
-        return DimValues(self).append(val)
+        ret = DimValues(self)
+        ret.append(val)
+        return ret
     def __sub__(self, dim):
         result = DimValues(self)
         for v in self:
@@ -50,7 +53,11 @@ class Dimension(dict):
     def addValue(self, *values):
        for value in values:
            if value not in self:
-               self[value] = DimValue(self, value)
+                if isinstance(value, DimValue):
+                    self[value.value] = value
+                else:
+                    raise Exception("Unsupported usage of addValue")
+                    #self[value] = DimValue(self, value)
        self.sortedKeys = self.keys()
        self.sortedKeys.sort()
     def val2str(self, v):
@@ -188,7 +195,7 @@ class Tests(dict):
            raise KeyError("The number coordinates do not match the number of dimensions: " + str(coordinates))
        self[tuple(coordinates)] = test
        for i in xrange(len(coordinates)):
-           self.space[i].addValue(coordinates[i])
+            DimValue(self.space[i], coordinates[i])
 
     def populate(self, rootpath):
        for root, dirs, files in os.walk(rootpath):
@@ -202,7 +209,7 @@ class Tests(dict):
        for pair in self.space.iterDimensionPairs():
            remDims = Space(*tuple([d for d in self.space.iterRemainingDimensions(pair)]))
            for vals in remDims.iterValues():
-               page = Page(pair, remDims, vals, self)
+               page = Page(pair, vals, self)
                page.generate()
        try:
            os.remove("index.html")
@@ -212,15 +219,14 @@ class Tests(dict):
        #os.system("source-highlight -d --output-dir=. ../*.sh")
 
 class Page:
-    def __init__(self, dimPair, dimOther, valsOther, tests):
+    def __init__(self, dimPair, valsOther, tests):
        self.dimy, self.dimx = dimPair
-       self.dimOther = dimOther
-       self.valsOther = valsOther
+       self.dimOther = [v.dim for v in valsOther]
+       self.valsOther = tests.space.reorder(valsOther)
        self.tests = tests
-    def getName(self, dimy=None, dimx=None, valsOther=None):
-       return "%s-vs-%s-for-%s.html"%(dimx or self.dimy.type,
-                                       dimy or self.dimx.type,
-                                       "-".join([v.value for v in valsOther or self.valsOther]))
+    def getName(self):
+       return "%s-vs-%s-for-%s.html"%(self.dimy.type, self.dimx.type,
+                                       "-".join([v.value for v in self.valsOther]))
     def generate(self):
        html = open(self.getName(), "w")
        title = "CAN gateway timing analysis" 
@@ -242,9 +248,9 @@ th, td { border: 1px solid lightgray; padding: 4px;}
        for d in self.dimOther:
             print >>html, "%s: " % d
             print >>html, "<a href='%s'>X axis</a>, " % \
-                self.getName(dimx=d,
-                             valsOther=self.valsOther - d + self.dimx.getValue(0))
-            print >>html, "<a href='%s'>Y axis</a>;&nbsp;&nbsp;" % self.getName(dimy=d)
+                Page((self.dimy, d), self.valsOther - d + self.dimx.getValue(0), self.tests).getName()
+            print >>html, "<a href='%s'>Y axis</a>;&nbsp;&nbsp;" % \
+                Page((d, self.dimx), self.valsOther - d + self.dimy.getValue(0), self.tests).getName()
             links = []
             for v in d.values():
                 if v in self.valsOther:
@@ -252,7 +258,7 @@ th, td { border: 1px solid lightgray; padding: 4px;}
                 else:
                     vv = DimValues(self.valsOther)
                     vv.replace(v)
-                    links.append("<a href='%s'>%s</a>"%(urllib.quote(self.getName(valsOther=vv)), str(v)))
+                    links.append("<a href='%s'>%s</a>"%(urllib.quote(Page((self.dimy, self.dimx), vv, self.tests).getName()), str(v)))
             print >>html, " | ".join(links)
             print >>html, "<br>"
             try: