<s> from datetime import datetime <EOL> import os <EOL> import sys <EOL> import uuid <EOL> import pytz <EOL> import subunit <EOL> from cafe . common . reporting . base_report import BaseReport <EOL> class SubunitReport ( BaseReport ) : <EOL> def generate_report ( self , result_parser , all_results = None , path = None ) : <EOL> """<STR_LIT>""" <EOL> result_path = path or os . getcwd ( ) <EOL> if os . path . isdir ( result_path ) : <EOL> result_path += "<STR_LIT>" <EOL> with open ( result_path , '<STR_LIT:wb>' ) as result_file : <EOL> output = subunit . v2 . StreamResultToBytes ( result_file ) <EOL> output . startTestRun ( ) <EOL> for result in all_results : <EOL> test_result = result . __dict__ <EOL> if test_result . get ( '<STR_LIT>' ) is not None : <EOL> test_result [ '<STR_LIT:result>' ] = "<STR_LIT>" <EOL> elif test_result . get ( '<STR_LIT>' ) is not None : <EOL> test_result [ '<STR_LIT:result>' ] = "<STR_LIT>" <EOL> elif test_result . get ( '<STR_LIT>' ) is not None : <EOL> test_result [ '<STR_LIT:result>' ] = "<STR_LIT>" <EOL> else : <EOL> test_result [ '<STR_LIT:result>' ] = "<STR_LIT:success>" <EOL> if test_result [ '<STR_LIT>' ] == "<STR_LIT>" : <EOL> test_id = "<STR_LIT>" . format ( <EOL> test_result [ '<STR_LIT>' ] , <EOL> test_result [ '<STR_LIT>' ] ) <EOL> else : <EOL> test_id = "<STR_LIT>" . format ( <EOL> test_result [ '<STR_LIT>' ] , <EOL> test_result [ '<STR_LIT>' ] ) <EOL> kwargs = { <EOL> "<STR_LIT>" : datetime . now ( pytz . UTC ) , <EOL> "<STR_LIT>" : unicode ( test_id ) } <EOL> output . status ( ** kwargs ) <EOL> kwargs [ "<STR_LIT>" ] = test_result [ '<STR_LIT:result>' ] <EOL> kwargs [ "<STR_LIT>" ] = bytes ( test_result . get ( <EOL> '<STR_LIT>' ) or test_result . get ( '<STR_LIT>' ) or "<STR_LIT:0>" ) <EOL> kwargs [ "<STR_LIT>" ] = "<STR_LIT>" <EOL> kwargs [ "<STR_LIT>" ] = unicode ( "<STR_LIT>" ) <EOL> output . status ( ** kwargs ) <EOL> output . stopTestRun ( ) </s>
