Package: cykooz.testing
cykooz.testing is collection of helper utilities for testing.UtilitiesDictA dict object that can be compared with other dict object
without regard to keys that did not presents in theDictinstance.>>>fromcykooz.testingimportDict>>>expected=Dict(a=1,b='foo')>>>d1={'a':1,'b':'foo','c':True}>>>d1==expectedTrue>>>d1!=expectedFalse>>>d2={'a':1,'c':True}>>>d2==expectedFalse>>>d1!=d2True>>>Dict({'a':1})Dict({'a':1})Short alias:>>>fromcykooz.testingimportD>>>{'a':1,'b':'foo'}==D({'a':1})TrueListA list object that can be compared with other list object
without regard to extra items contains in the other list object.>>>fromcykooz.testingimportList>>>expected=List([1,'foo'])>>>l1=[1,'foo',True]>>>l1==expectedTrue>>>l1!=expectedFalse>>>l2=[1,True]>>>l2==expectedFalse>>>l2!=expectedTrue>>>expected==[1]False>>>[{'a':1},{'b':2}]==List([Dict(),Dict()])TrueAlso supported comparing without regard of ordering of items.>>>expected=List([True,1],ignore_order=True)>>>l1=[1,'foo',True]>>>l1==expectedTrue>>>l1!=expectedFalse>>>[{'a':1},{'b':2}]==List([Dict(),Dict()],ignore_order=True)Traceback(mostrecentcalllast):...TypeError:unhashabletype:'Dict'Short alias:>>>fromcykooz.testingimportL>>>[1,'foo',True]==L([1,'foo'])TrueAnyValueInstance of this class is equal to any other values.>>>fromcykooz.testingimportAnyValue>>>v=AnyValue()>>>v==1True>>>1==vTrue>>>v!=1False>>>v=={'a':1,'b':'foo'}True>>>v==[1,2,3,'b']True>>>v==AnyValue()True>>>v<anyvalue>>>>{v:1}Traceback(mostrecentcalllast):...TypeError:unhashabletype:'AnyValue'>>>[v,v,v]==[1,2,'foo']True>>>[v,v,1]==[1,2,'foo']False>>>[v,v]==[1,2,'foo']False>>>{'a':v,'b':2}=={'a':1,'b':2}TrueShort alias:>>>fromcykooz.testingimportANY>>>1==ANYTrueRegExpStringInstance of this class is equal to any other values if it is matched
to give regexp pattern.>>>fromcykooz.testingimportRegExpString>>>v=RegExpString('first.*')>>>v==1False>>>1==vFalse>>>v!=1True>>>v=='first class'True>>>'first class'==vTrue>>>v!='first class'False>>>v<RegExpString:first.*>>>>{v:1}Traceback(mostrecentcalllast):...TypeError:unhashabletype:'RegExpString'>>>[v,v,v]==[1,2,'first class']False>>>[v,v,v]==['first class','first bus','first time']TrueShort alias:>>>fromcykooz.testingimportR>>>'first class'==R('first.*')TrueUrlA url object that can be compared with other url objects
without regard to the vagaries of encoding, escaping, and ordering
of parameters in query strings.>>>fromcykooz.testingimportUrl>>>url1=Url('https://domain.com/container?limit=6&offset=0')>>>url2=Url('https://domain.com/container?offset=0&limit=6')>>>url1==url2True>>>url2=Url('https://domain.com/container?limit=6')>>>url1==url2False>>>url1=='https://domain.com/container?offset=0&limit=6'True>>>'https://domain.com/container?offset=0&limit=6'==url1True>>>{'key':'https://domain.com/container?offset=0&limit=6'}=={'key':url1}TrueJsonAn instance of this class will be equal to any ‘bytes’ or ‘str’ value
if object decoded by JSON-decoder from this value is equal to the first
argument of this class.>>>fromcykooz.testingimportJson>>>v=Json({'foo':1,'bar':'hello'})>>>other='{"bar": "hello", "foo": 1}'>>>v==otherTrue>>>other==vTrue>>>other!=vFalse>>>v==1False>>>1==vFalse>>>v!=1True>>>v=='not json'False>>>'not json'==vFalse>>>v!='not json'True>>>v<Json:{'foo':1,'bar':'hello'}>>>>{v:1}Traceback(mostrecentcalllast):...TypeError:unhashabletype:'Json'>>>[v,v,v]==[other,2,'first class']False>>>[v,v,v]==[other,other,other]True>>>'"json str"'==Json('json str')TrueComplex example>>>fromcykooz.testingimportD,L,R,J,Url,ANY>>>some_value={...'created':'2020-04-14T12:34:00.002000+00:00',...'is_active':True,...'items':[...{'key':'a','value':1},...{'key':'b','value':2},...{'key':'c','value':3},...],...'source':'https://domain.com/item?p=0&t=total',...'response':'{"status": 200, "body": "OK"}',...'size':1024,...}>>>some_value==D({...'created':R('^2020-04.*'),...'is_active':True,...'items':L([...{'key':'a','value':1},...D({'value':ANY}),...]),...'source':Url('https://domain.com/item?t=total&p=0'),...'response':J({'status':200,'body':ANY}),...})TrueCHANGELOG1.2 (2021-08-27)ChangesAdded argumentignore_orderintoListhelper to
comparing of lists without regard of ordering of items.1.1.2 (2020-04-14)Bug FixesAdded new helper into__all__.1.1 (2020-04-14)FeaturesAdded new helperJson.1.0.3 (2020-03-20)Bug FixesFixed namespace declaration.1.0.1 (2019-07-12)Bug FixesFixed “Development Status” of package.1.0 (2019-07-12)FeaturesInitial release.