��Qc @s�dZddlZddlZddlZddlZddlmZddlZddlmZm Z m
Z
mZmZd�Z
e
Zd�Zd�Zdd d
ddd
ddgZdd
ddd
dddd g Zdejfd��YZdejfd��YZdefd��YZdefd��YZdejfd��YZdefd��YZdefd��YZd�Zed kr�ejd!d"�ndS(#sF
TestCases for python DB duplicate and Btree key comparison function.
i�N(tStringIO(tdbtdbshelvettest_supporttget_new_environment_pathtget_new_database_pathcCs$||krdS||kr dSdS(Nii�i((tatb((s-/sys/lib/python2.7/bsddb/test/test_compare.pytcmps
cCst|j�|j��S(N(Rtlower(tlefttright((s-/sys/lib/python2.7/bsddb/test/test_compare.pyt
lowercase_cmpscCs|d�}|S(NcSs|||�S(N((R
Rtdelegate((s-/sys/lib/python2.7/bsddb/test/test_compare.pytreverses((RR((s-/sys/lib/python2.7/bsddb/test/test_compare.pytmake_reverse_comparatorsttCCCPRtaaaRtctccccetccccftCCtComparatorTestscBs,eZd�Zd�Zd�Zd�ZRS(c
Cs�|}ddl}|jdkr5|jd|�nvg}xg|D]_}xVt|�D];\}}|||�} | dkrU|j||�PqUqUW|j|�qBW|}|j||d|||f�dS(Ni�iiRis'comparator `%s' is not right: %s vs. %s(ii(tsystversion_infotsortt enumeratetinserttappendtassertEqual(
tselft
comparatort
expected_datatdataRtdata2titjtktr((s-/sys/lib/python2.7/bsddb/test/test_compare.pytcomparator_test_helper#s
cCs|jtt�dS(N(R(tlexical_cmpt_expected_lexical_test_data(R((s-/sys/lib/python2.7/bsddb/test/test_compare.pyttest_lexical_comparator8scCs+t}|j�|jtt�|�dS(N(R*RR(RR)(Rtrev((s-/sys/lib/python2.7/bsddb/test/test_compare.pyttest_reverse_lexical_comparator:s
cCs|jtt�dS(N(R(Rt_expected_lowercase_test_data(R((s-/sys/lib/python2.7/bsddb/test/test_compare.pyttest_lowercase_comparator?s (t__name__t
__module__R(R+R-R/(((s-/sys/lib/python2.7/bsddb/test/test_compare.pyR"s tAbstractBtreeKeyCompareTestCasecBs�eZdZdZejdks?ejdkrNejdkrNdd�Znd�Zd�Z d�Z
d�Zd �Zd
�Z
d�Zdd�Zd
�ZRS(iiiicCs|j||kd|�S(Ntmsg(t
assertTrue(RRRR3((s-/sys/lib/python2.7/bsddb/test/test_compare.pyt
assertLessIscCsc|jjd|_t�|_tj�}|j|jtjtj Btj
BtjB�||_dS(Ns.db(
t __class__R0tfilenameRthomeDirRtDBEnvtopent DB_CREATEt
DB_INIT_MPOOLtDB_INIT_LOCKt DB_THREADtenv(RR?((s-/sys/lib/python2.7/bsddb/test/test_compare.pytsetUpLscCsF|j�|jdk r2|jj�d|_ntj|j�dS(N(tcloseDBR?tNonetcloseRtrmtreeR8(R((s-/sys/lib/python2.7/bsddb/test/test_compare.pyttearDownUs
cCs>d}x1|D])}|jj|t|��|d}q
WdS(Nii(Rtputtstr(RR"R$titem((s-/sys/lib/python2.7/bsddb/test/test_compare.pytaddDataToDB\s
cCsHtj|j�|_|j|�|jj|jdtjtj�dS(Nttest(RtDBR?tsetupDBR:R7tDB_BTREER;(Rtkey_comparator((s-/sys/lib/python2.7/bsddb/test/test_compare.pytcreateDBbs
cCs|jj|�dS(N(Rtset_bt_compare(RRN((s-/sys/lib/python2.7/bsddb/test/test_compare.pyRLgscCs,|jdk r(|jj�d|_ndS(N(RRBRC(R((s-/sys/lib/python2.7/bsddb/test/test_compare.pyRAjs
cCsdS(N((R((s-/sys/lib/python2.7/bsddb/test/test_compare.pyt startTestoscCs*|dk r|j|�n|j�dS(N(RBt
check_resultsRA(Rtexpected((s-/sys/lib/python2.7/bsddb/test/test_compare.pyt
finishTestrscCs�|jj�}z�d}|j�}xm|r�|\}}|j|t|�d�|j|||d||||f�|d}|j�}q'W|j|t|�d�Wd|j�XdS(Nis#to many values returned from cursors&expected value `%s' at %d but got `%s'is¬ enough values returned from cursor(RtcursortfirstR5tlenRtnextRC(RRStcurstindextrectkeytignore((s-/sys/lib/python2.7/bsddb/test/test_compare.pyRRws
N(ii(ii(ii(R0R1RBR?RRRR5R@RERIRORLRARQRTRR(((s-/sys/lib/python2.7/bsddb/test/test_compare.pyR2Cs tBtreeKeyCompareTestCasecBs,eZd�Zd�Zd�Zd�ZRS(cCs5|j�|j|�|j|�|j|�dS(N(RQRORIRT(RR R"((s-/sys/lib/python2.7/bsddb/test/test_compare.pytrunCompareTest�s
cCs|jtt�dS(N(R_R)R*(R((s-/sys/lib/python2.7/bsddb/test/test_compare.pyttest_lexical_ordering�scCs+t}|j�|jtt�|�dS(N(R*RR_RR)(Rtexpected_rev_data((s-/sys/lib/python2.7/bsddb/test/test_compare.pyttest_reverse_lexical_ordering�s
cCsJ|j�d�}|j|�|jdddg�|jdg�dS(NcSsdS(Ni((tlR'((s-/sys/lib/python2.7/bsddb/test/test_compare.pytsocialist_comparator�sRRtd(RQRORIRT(RRd((s-/sys/lib/python2.7/bsddb/test/test_compare.pyttest_compare_function_useless�s
(R0R1R_R`RbRf(((s-/sys/lib/python2.7/bsddb/test/test_compare.pyR^�s tBtreeExceptionsTestCasecBsbeZd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Z d�Z
d �ZRS(
cCsD|j�|jt|jd�|jt|jd�|j�dS(Ntabc(RQtassertRaisest TypeErrorRORBRT(R((s-/sys/lib/python2.7/bsddb/test/test_compare.pyttest_raises_non_callable�s
cCs%|j�|jt�|j�dS(N(RQROR)RT(R((s-/sys/lib/python2.7/bsddb/test/test_compare.pyt!test_set_bt_compare_with_function�s
cCsdS(N((Rtresults((s-/sys/lib/python2.7/bsddb/test/test_compare.pyRR�scCs7|j�d�}|jt|j|�|j�dS(NcSsdS(Ni((RcR'((s-/sys/lib/python2.7/bsddb/test/test_compare.pytbad_comparator�s(RQRiRjRORT(RRn((s-/sys/lib/python2.7/bsddb/test/test_compare.pyttest_compare_function_incorrect�s
cCs�tj}t�t_z|�Wdtj}|t_|j�}|j|�sd|jd|�nXtjdkr�dt_t_ ndS(s�
Call method() while capturing sys.stderr output internally and
call self.fail() if successRe.search() does not match the stderr
output. This is used to test for uncatchable exceptions.
Nsunexpected stderr output:
ii(ii(
RtstderrRtgetvaluetsearchtfailRRBt
exc_tracebacktlast_traceback(Rtmethodt successRetstdErrttempterrorOut((s-/sys/lib/python2.7/bsddb/test/test_compare.pytverifyStderr�s cCsD|j�d�}|j|�|jdddg�|j�dS(NcSs||krdStd�dS(Nis!i'm a naughty comparison function(tRuntimeError(RcR'((s-/sys/lib/python2.7/bsddb/test/test_compare.pyRn�sRRR(RQRORIRT(RRn((s-/sys/lib/python2.7/bsddb/test/test_compare.pyt _test_compare_function_exception�s
cCs-|j|jtjdtjtjB��dS(Ns(^RuntimeError:.* naughty.*){2}(R{R}tretcompiletMtS(R((s-/sys/lib/python2.7/bsddb/test/test_compare.pyttest_compare_function_exception�scCsD|j�d�}|j|�|jdddg�|j�dS(NcSs||krdS|S(Ni((RcR'((s-/sys/lib/python2.7/bsddb/test/test_compare.pyRn�sRRR(RQRORIRT(RRn((s-/sys/lib/python2.7/bsddb/test/test_compare.pyt!_test_compare_function_bad_return�s
cCs-|j|jtjdtjtjB��dS(Ns"(^TypeError:.* return an int.*){2}(R{R�R~RR�R�(R((s-/sys/lib/python2.7/bsddb/test/test_compare.pyt test_compare_function_bad_return�scCs=d�}|j�|j|�|jt|jj|�dS(NcSsdS(Ni((RR((s-/sys/lib/python2.7/bsddb/test/test_compare.pyt
my_compare�s(RQRORiR|RRP(RR�((s-/sys/lib/python2.7/bsddb/test/test_compare.pyttest_cannot_assign_twice�s
(R0R1RkRlRRRoR{R}R�R�R�R�(((s-/sys/lib/python2.7/bsddb/test/test_compare.pyRg�s t AbstractDuplicateCompareTestCasecBs�eZdZdZejdks?ejdkrNejdkrNdd�Znd�Zd�Z d�Z
d�Zd �Zd
�Z
d�Zdd�Zd
�ZRS(iiiicCs|j||kd|�S(NR3(R4(RRRR3((s-/sys/lib/python2.7/bsddb/test/test_compare.pyR5scCsc|jjd|_t�|_tj�}|j|jtjtj Btj
BtjB�||_dS(Ns.db(
R6R0R7RR8RR9R:R;R<R=R>R?(RR?((s-/sys/lib/python2.7/bsddb/test/test_compare.pyR@scCsF|j�|jdk r2|jj�d|_ntj|j�dS(N(RAR?RBRCRRDR8(R((s-/sys/lib/python2.7/bsddb/test/test_compare.pyREs
cCs(x!|D]}|jjd|�qWdS(NR\(RRF(RR"RH((s-/sys/lib/python2.7/bsddb/test/test_compare.pyRIs
cCsHtj|j�|_|j|�|jj|jdtjtj�dS(NRJ(RRKR?RLR:R7RMR;(Rtdup_comparator((s-/sys/lib/python2.7/bsddb/test/test_compare.pyROs
cCs'|jjtj�|jj|�dS(N(Rt set_flagst
DB_DUPSORTtset_dup_compare(RR�((s-/sys/lib/python2.7/bsddb/test/test_compare.pyRLscCs,|jdk r(|jj�d|_ndS(N(RRBRC(R((s-/sys/lib/python2.7/bsddb/test/test_compare.pyRA#s
cCsdS(N((R((s-/sys/lib/python2.7/bsddb/test/test_compare.pyRQ(scCs*|dk r|j|�n|j�dS(N(RBRRRA(RRS((s-/sys/lib/python2.7/bsddb/test/test_compare.pyRT+scCs�|jj�}z�d}|j�}xm|r�|\}}|j|t|�d�|j|||d||||f�|d}|j�}q'W|j|t|�d�Wd|j�XdS(Nis#to many values returned from cursors&expected value `%s' at %d but got `%s'is¬ enough values returned from cursor(RRURVR5RWRRXRC(RRSRYRZR[R]R"((s-/sys/lib/python2.7/bsddb/test/test_compare.pyRR0s
N(ii(ii(ii(R0R1RBR?RRRR5R@RERIRORLRARQRTRR(((s-/sys/lib/python2.7/bsddb/test/test_compare.pyR��s tDuplicateCompareTestCasecBs#eZd�Zd�Zd�ZRS(cCs5|j�|j|�|j|�|j|�dS(N(RQRORIRT(RR R"((s-/sys/lib/python2.7/bsddb/test/test_compare.pyR_Ds
cCs|jtt�dS(N(R_R)R*(R((s-/sys/lib/python2.7/bsddb/test/test_compare.pyR`JscCs+t}|j�|jtt�|�dS(N(R*RR_RR)(RRa((s-/sys/lib/python2.7/bsddb/test/test_compare.pyRbMs
(R0R1R_R`Rb(((s-/sys/lib/python2.7/bsddb/test/test_compare.pyR�Cs tDuplicateExceptionsTestCasecBskeZd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Z d�Z
d �Zd
�ZRS(cCsD|j�|jt|jd�|jt|jd�|j�dS(NRh(RQRiRjRORBRT(R((s-/sys/lib/python2.7/bsddb/test/test_compare.pyRkTs
cCs%|j�|jt�|j�dS(N(RQROR)RT(R((s-/sys/lib/python2.7/bsddb/test/test_compare.pyt"test_set_dup_compare_with_functionZs
cCsdS(N((RRm((s-/sys/lib/python2.7/bsddb/test/test_compare.pyRR_scCs7|j�d�}|jt|j|�|j�dS(NcSsdS(Ni((RcR'((s-/sys/lib/python2.7/bsddb/test/test_compare.pyRnds(RQRiRjRORT(RRn((s-/sys/lib/python2.7/bsddb/test/test_compare.pyRobs
cCsP|j�d�}|j|�|jtj|jdddg�|j�dS(NcSsdS(Ni((RcR'((s-/sys/lib/python2.7/bsddb/test/test_compare.pyRdlsRRRe(RQRORiRtDBKeyExistErrorRIRT(RRd((s-/sys/lib/python2.7/bsddb/test/test_compare.pyRfjs
"cCs�tj}t�t_z|�Wdtj}|t_|j�}|j|�sd|jd|�nXtjdkr�dt_t_ ndS(s�
Call method() while capturing sys.stderr output internally and
call self.fail() if successRe.search() does not match the stderr
output. This is used to test for uncatchable exceptions.
Nsunexpected stderr output:
ii(ii(
RRpRRqRrRsRRBRtRu(RRvRwRxRyRz((s-/sys/lib/python2.7/bsddb/test/test_compare.pyR{ss cCsD|j�d�}|j|�|jdddg�|j�dS(NcSs||krdStd�dS(Nis!i'm a naughty comparison function(R|(RcR'((s-/sys/lib/python2.7/bsddb/test/test_compare.pyRn�sRRR(RQRORIRT(RRn((s-/sys/lib/python2.7/bsddb/test/test_compare.pyR}�s
cCs-|j|jtjdtjtjB��dS(Ns(^RuntimeError:.* naughty.*){2}(R{R}R~RR�R�(R((s-/sys/lib/python2.7/bsddb/test/test_compare.pyR��scCsD|j�d�}|j|�|jdddg�|j�dS(NcSs||krdS|S(Ni((RcR'((s-/sys/lib/python2.7/bsddb/test/test_compare.pyRn�sRRR(RQRORIRT(RRn((s-/sys/lib/python2.7/bsddb/test/test_compare.pyR��s
cCs-|j|jtjdtjtjB��dS(Ns"(^TypeError:.* return an int.*){2}(R{R�R~RR�R�(R((s-/sys/lib/python2.7/bsddb/test/test_compare.pyR��scCs=d�}|j�|j|�|jt|jj|�dS(NcSsdS(Ni((RR((s-/sys/lib/python2.7/bsddb/test/test_compare.pyR��s(RQRORiR|RR�(RR�((s-/sys/lib/python2.7/bsddb/test/test_compare.pyR��s
(
R0R1RkR�RRRoRfR{R}R�R�R�R�(((s-/sys/lib/python2.7/bsddb/test/test_compare.pyR�Ss cCs~tj�}|jtjt��|jtjt��|jtjt��|jtjt��|jtjt��|S(N( tunittestt TestSuitetaddTestt makeSuiteRRgR^R�R�(tres((s-/sys/lib/python2.7/bsddb/test/test_compare.pyt
test_suite�st__main__tdefaultTesttsuite(t__doc__RtosR~ttest_allt cStringIORR�RRRRRRR)RRR*R.tTestCaseRR2R^RgR�R�R�R�R0tmain(((s-/sys/lib/python2.7/bsddb/test/test_compare.pyt<module>s*$( !!GXFa
|