Ejemplo n.º 1
0
 def compare(self, src, dst, depth, name):
     if type(src) != type(dst):
         print_(
             f.diff + ">><<", name, ": Types differ" + f.reset + "\n+" +
             f.src + ">>Source:" + f.reset + "\n", makeString(src),
             "\n" + f.dst + "<<Destination:" + f.reset + "\n",
             makeString(dst) + f.reset)
         self.pling = True
     elif type(src) in [tuple, list, TupleProxy]:
         self.compareIterable(src, dst, depth, name)
     elif isinstance(
             src,
         (str, float, bool, BoolProxy) + integer_types) or src == None:
         self.comparePrimitive(src, dst, depth, name)
     elif src.__class__ in [Dimension, Tensor, SymmTensor, Vector]:
         self.comparePrimitive(src, dst, depth, name)
     elif src.__class__ == Field:
         self.compareField(src, dst, depth, name)
     elif type(src) in [DictProxy, dict]:
         self.compareDict(src, dst, depth, name)
     else:
         warning("Type of", name, "=", type(src), "unknown")
         if self.opts.debug:
             try:
                 print_("Class of", name, "=", src.__class__, "unknown")
             except:
                 pass
Ejemplo n.º 2
0
    def compareDict(self, src, dst, depth, name):
        for n in src:
            if not n in dst:
                print_(f.src + ">>>>", self.dictString(name, n),
                       ": Missing from destination\n" + f.reset,
                       makeString(src[n]))
                self.pling = True
            else:
                if self.opts.debug:
                    print_("Comparing", self.dictString(name, n))
                self.compare(src[n], dst[n], depth + 1,
                             self.dictString(name, n))

        for n in dst:
            if not n in src:
                print_(f.dst + "<<<<", self.dictString(name, n),
                       ": Missing from source\n" + f.reset, makeString(dst[n]))
                self.pling = True
Ejemplo n.º 3
0
    def compareIterable(self, src, dst, depth, name):
        nr = min(len(src), len(dst))

        for i in range(nr):
            if self.opts.debug:
                print_("Comparing", self.iterString(name, i))
            self.compare(src[i], dst[i], depth + 1, self.iterString(name, i))

        if nr < len(src):
            print_(f.src + ">>>>", self.iterString(name, nr), "to",
                   self.iterString(name,
                                   len(src) - 1),
                   "missing from destination\n" + f.reset,
                   makeString(src[nr:]))
            self.pling = True
        elif nr < len(dst):
            print_(f.dst + "<<<<", self.iterString(name, nr), "to",
                   self.iterString(name,
                                   len(dst) - 1),
                   "missing from source\n" + f.reset, makeString(dst[nr:]))
            self.pling = True
Ejemplo n.º 4
0
 def testSinglePrimitive(self):
     self.assertEqual(makeString( 2 ),"2")
Ejemplo n.º 5
0
 def testSingleList(self):
     self.assertEqual(makeString( [2,3] ),"(\n  2\n  3\n)\n")
Ejemplo n.º 6
0
 def testSingleTupleProxy(self):
     self.assertEqual(makeString( TupleProxy((2,3)) ),"  2   3 ")
 def __str__(self):
     return makeString({self.id:self.getDict(wrapStrings=True)})
Ejemplo n.º 8
0
 def testSinglePrimitive(self):
     self.assertEqual(makeString( 2 ),"2")
Ejemplo n.º 9
0
 def compareIterable(self,src,dst,depth,name):
     nr=min(len(src),len(dst))
     
     for i in range(nr):
         if self.opts.debug:
             print "Comparing",self.iterString(name,i)
         self.compare(src[i],dst[i],depth+1,self.iterString(name,i))
         
     if nr<len(src):
         print f.src+">>>>",self.iterString(name,nr),"to",self.iterString(name,len(src)-1),"missing from destination\n"+f.reset,makeString(src[nr:])
         self.pling=True
     elif nr<len(dst):
         print f.dst+"<<<<",self.iterString(name,nr),"to",self.iterString(name,len(dst)-1),"missing from source\n"+f.reset,makeString(dst[nr:])
         self.pling=True
Ejemplo n.º 10
0
 def makeComment(self,data):
     s=makeString(data)
     s="\n old Value: "+s
     s=s.replace("\n","\n//")
     return s
Ejemplo n.º 11
0
 def testSingleQuote(self):
     self.assertEqual(makeString( "heres ; nothing" ),'"heres ; nothing"')
     self.assertEqual(makeString( 'heres ; "nothing"' ),"'heres ; \"nothing\"'")
Ejemplo n.º 12
0
 def testTupleInDict(self):
     self.assertEqual(makeString({"a":(2,3)} ),"a     2     3 ;\n")
Ejemplo n.º 13
0
 def testTupleWithDict(self):
     self.assertEqual(makeString( (2,{"a":2}) ),"  2 {\n    a 2;\n  } ")
Ejemplo n.º 14
0
 def testTupleWithList(self):
     self.assertEqual(makeString( (2,[3,4]) ),"  2    (\n    3\n    4\n  )\n")
Ejemplo n.º 15
0
 def __str__(self):
     return makeString({self.id: self.getDict(wrapStrings=True)})
Ejemplo n.º 16
0
 def compare(self,src,dst,depth,name):
     if type(src)!=type(dst):
         print f.diff+">><<",name,": Types differ"+f.reset+"\n+"+f.src+">>Source:"+f.reset+"\n",makeString(src),"\n"+f.dst+"<<Destination:"+f.reset+"\n",makeString(dst)+f.reset
         self.pling=True
     elif type(src) in [tuple,list,TupleProxy]:
         self.compareIterable(src,dst,depth,name)
     elif type(src) in [str,float,int,long,type(None)]:
         self.comparePrimitive(src,dst,depth,name)
     elif src.__class__ in [Dimension,Tensor,SymmTensor,Vector]:
         self.comparePrimitive(src,dst,depth,name)            
     elif src.__class__==Field:
         self.compareField(src,dst,depth,name)            
     elif type(src) in [DictProxy,dict]:
         self.compareDict(src,dst,depth,name)            
     else:
         warning("Type of",name,"=",type(src),"unknown")
         if self.opts.debug:
             try:
                 print "Class of",name,"=",src.__class__,"unknown"
             except:
                 pass
Ejemplo n.º 17
0
 def testSingleTupleProxy(self):
     self.assertEqual(makeString( TupleProxy((2,3)) ),"  2   3 ")
Ejemplo n.º 18
0
 def compareDict(self,src,dst,depth,name):
     for n in src:
         if not n in dst:
             print f.src+">>>>",self.dictString(name,n),": Missing from destination\n"+f.reset,makeString(src[n])
             self.pling=True
         else:
             if self.opts.debug:
                 print "Comparing",self.dictString(name,n)
             self.compare(src[n],dst[n],depth+1,self.dictString(name,n))
             
     for n in dst:
         if not n in src:
             print f.dst+"<<<<",self.dictString(name,n),": Missing from source\n"+f.reset,makeString(dst[n])
             self.pling=True
Ejemplo n.º 19
0
 def testSingleList(self):
     self.assertEqual(makeString( [2,3] ),"(\n  2\n  3\n)\n")