o k`@sddlZddlZddlZddlZddlZddlZddlZddlmZm Z m Z e dej Z ddZd ddZd d d ZGd d d ejZdS)N)AdminCommandManager TracAdmin_runz( +)$cCsi}t|}t|dd0}d}|D]"}|}||}|r*|d}d||<q|||d7<qWd|S1s@wY|S)zReads the file, named file, which contains test results separated by the regular expression pattern. The test results are returned as a dictionary. utf-8)encodingNr )recompileopenrstripsearchgroups)filepatternexpectedcompiled_patternftestlinematchr1/usr/lib/python3/dist-packages/trac/admin/test.pyload_expected_resultss        rTc Cs0t|tr |d}n|durd}n t|tstdt|t|Y}tE}tj|ddd}tj|dddd}t j t j t j f}z|t _ |t _ t _ |}W|\t _ t _ t _ n |\t _ t _ t _ w| } Wdn1sqwYWdn1swYt| d} |r|td| fS|| fS) Nrz(input must be str, bytes or None, not %sr)rnewlineT)rr write_throughr) isinstancestrencodebytes ValueErrortypeioBytesIO TextIOWrappersysstdinstdoutstderrgetvalueSTRIP_TRAILING_SPACEsub) funcstrip_trailing_spaceinputrbufwbufr'r(_files return_valvaluerrr_execute0s6     $  r5csfdd}t|||S)Ncs"zWStyYdSwN)onecmd SystemExitrcmd tracadminrrr-Ns   zexecute_cmd..funcr5)r;r:r.r/r-rr9r execute_cmdMs r=c@speZdZdZeddZeddZeddZedd Z dd d Z dddZ eddZ ddZ ddZd S)TracAdminTestCaseBasezconsole-tests.txtcCstj|_dSr6)osenvironcopy)clsrrr setUpClassZsz TracAdminTestCaseBase.setUpClasscCs4ttjt|jD]}tj|=q tj|jdSr6)setr?r@update)rBnamerrr tearDownClass^s z#TracAdminTestCaseBase.tearDownClasscCs(tj|jjj}tjtj||j Sr6) r&modules __class__ __module____file__r?pathjoindirnameexpected_results_filename)self results_filerrrexpected_results_filedsz+TracAdminTestCaseBase.expected_results_filecCs t|jdS)Nz===== (test_[^ ]+) =====)rrR)rPrrrexpected_resultsjsz&TracAdminTestCaseBase.expected_resultsTNcCs(t|dr |j}nt}t||||dS)Nadmin)r.r/)hasattrrTrr=)rPr:r.r/rTrrrexecuteos zTracAdminTestCaseBase.executec stdd}|r||7}|j||dur|;fdd}d|f}dvrJtdttjddtj }| ||dS| |dS) Ncs>dddD}dddD}dt||ddS)NcSg|]}d|qSz%s r.0xrrr zLTracAdminTestCaseBase.assertExpectedResult..diff..rcSrYrZrr[rrrr^r_rractual)splitrMdifflib unified_diff) output_linesexpected_linesexpected_resultoutputrrdiffs  z8TracAdminTestCaseBase.assertExpectedResult..diffz %r != %r %sz[...]z.*z\Z) inspectstackrSr rrMmapescaperaDOTALL assertTrue assertEqual)rPrhargssuffix test_namerimsgmrrfrassertExpectedResultxs$ z*TracAdminTestCaseBase.assertExpectedResultcsfdd}t|S)Ncs ztWStyYdSwr6)rr8rrqrrr-s   z/TracAdminTestCaseBase.execute_run..funcr<)rBrqr-rrwr execute_runs z!TracAdminTestCaseBase.execute_runcGs0t|jt|}|dt||ddS)NrWr)renvget_command_helplistrplen)rPrqdocsrrrr{s z&TracAdminTestCaseBase.get_command_helpcGst|jt|Sr6)rrzcomplete_commandr|)rPrqrrrrsz&TracAdminTestCaseBase.complete_commandTN)NN)__name__rJ __qualname__rO classmethodrCrGpropertyrRrSrVrvrxr{rrrrrr>Vs         r>r)rbrjr#r?r r&unittesttrac.admin.consolerrrr MULTILINEr+rr5r=TestCaser>rrrrs