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
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
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
def testSinglePrimitive(self): self.assertEqual(makeString( 2 ),"2")
def testSingleList(self): self.assertEqual(makeString( [2,3] ),"(\n 2\n 3\n)\n")
def testSingleTupleProxy(self): self.assertEqual(makeString( TupleProxy((2,3)) )," 2 3 ")
def __str__(self): return makeString({self.id:self.getDict(wrapStrings=True)})
def testSinglePrimitive(self): self.assertEqual(makeString( 2 ),"2")
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
def makeComment(self,data): s=makeString(data) s="\n old Value: "+s s=s.replace("\n","\n//") return s
def testSingleQuote(self): self.assertEqual(makeString( "heres ; nothing" ),'"heres ; nothing"') self.assertEqual(makeString( 'heres ; "nothing"' ),"'heres ; \"nothing\"'")
def testTupleInDict(self): self.assertEqual(makeString({"a":(2,3)} ),"a 2 3 ;\n")
def testTupleWithDict(self): self.assertEqual(makeString( (2,{"a":2}) )," 2 {\n a 2;\n } ")
def testTupleWithList(self): self.assertEqual(makeString( (2,[3,4]) )," 2 (\n 3\n 4\n )\n")
def __str__(self): return makeString({self.id: self.getDict(wrapStrings=True)})
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
def testSingleTupleProxy(self): self.assertEqual(makeString( TupleProxy((2,3)) )," 2 3 ")
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
def testSingleList(self): self.assertEqual(makeString( [2,3] ),"(\n 2\n 3\n)\n")