B @`@s^dZddlZddlZddlmZddlmZddlmZedZ ddZ Gd d d eZ dS) aThis module defines a nose plugin that allows the user to archive test data. Use the following command-line option with nosetests :: nosetests --with-testdata By default, a file named testdata.csv will be written to the working directory. If you need to change the name or location of the file, you can set the ``--testdata-file`` option. Here is an abbreviated version of what the CSV file might look like:: classname,name,time pyutilib.th.tests.test_pyunit.Tester,test_fail,0.00291109085083 pyutilib.th.tests.test_pyunit.Tester,test_pass,5.57899475098e-05 pyutilib.th.tests.test_pyunit.Tester2,test_pass,0.000113964080811 pyutilib.th.tests.test_pyunit.Tester3,test_fail,7.60555267334e-05 N)time)Plugin) text_typez[\000-\010\013\014\016-\037]cCstd|ddS)z)Replaces invalid CSV characters with '?'.?,_)CONTROL_CHARACTERSsubreplace)valuer =/tmp/pip-unpacked-wheel-bvjqrktv/pyutilib/th/nose_testdata.pycsv_safe!src@s`eZdZdZdZdZdZdZeZ ddZ dd Z d d Z d d Z ddZddZdddZdS)TestDataz6This plugin archives test data in standard CSV format.testdataizUTF-8NcCs t|drt|j}nd}|S)N_timerg)hasattrrr)selftakenr r r _timeTaken.s zTestData._timeTakencCs"t|}t|tr||j}|S)z-Escape a CSV attribute. Value can be unicode.)r isinstancerencodeencoding)rattrr r r _quoteattr8s  zTestData._quoteattrc CsLt||||jdddd|dddd|jd d d |d d dddS)z%Sets additional command line options.z--testdata-filestore testdata_fileFILEZNOSE_TESTDATA_FILEz testdata.csvznPath to CSV file to store the test data. Default is testdata.csv in the working directory [NOSE_TESTDATA_FILE])actiondestmetavardefaulthelpz--testdata-table store_truetestdata_tableZNOSE_TESTDATA_TABLEFzsIf this option is specified, then the CSV file is formatted as a table. By default, the format is a sparse list. )rrr!r"N)roptions add_optionget)rparserenvr r r r%?s  zTestData.optionscCsRt|||||_g|_|jr(d|_nd|_|jrNt|jd|_ |j ddS)zConfigures the testdata plugin.tablesparsewrN) r configureconfig reportdatar$formatZenabledopenr report_filedatakeysadd)rr%r.r r r r-UszTestData.configurec Cstjdddk r8d}dtjdtjdtjdf}nd}d}|jd krd d gtt|j}|j|d t |j |d xT|j D]J}g}x&|D]}| t|d|dqW|j|d |d qW|jn|j|dx|j D]|}xv|dD]j}|j||jt|dd t|d|jd t|d t|d||jd q WqW|jjdkr|d|d|jjdS)z"Writes a CSV file with test data. Z HUDSON_URLNzjob,build,node,z %s,%s,%s,ZJOB_NAMEZ BUILD_NUMBERZ NODE_NAMEr* classnamenamer zclassname,name,dataname,value rzF----------------------------------------------------------------------zCSV: %s)osenvironr'r0sortedlistr3r2writejoinmaprr/appendstrcloser. verbositywritelnr7)rstreamZ colprefixprefixkeysdatatmpkeyr r r reportbs:       $  zTestData.reportcCst|_i|j_dS)z+Initializes a timer before starting a test.N)rrtestr)rrNr r r startTestszTestData.startTestcCs|}|}x|jjD]}|j|qW|d|ddd}||dd}||jjd<|j |||jjfdS)z.Add success output to test data file. .Nr) ridrNrr3r4rr@splitr/rB)rrNZcaptrrRrLr6r7r r r addSuccesss zTestData.addSuccess)N)__name__ __module__ __qualname____doc__r7Zscorerr2setr3rrr%r-rMrOrTr r r r r&s  #r) rXr;rerZnose.plugins.basersixrcompilerrrr r r r s