#NEWLINE# @ task #NEWLINE# @ depends ( 'prepare' ) #NEWLINE# @ description ( 'Run Cram command line tests' ) #NEWLINE# def run_cram_tests( project , logger ) : #NEWLINE# #INDENT# logger . info ( 'Running Cram command line tests' ) #NEWLINE# cram_tests = list ( _find_files ( project ) ) #NEWLINE# if ( ( not cram_tests ) or ( len ( cram_tests ) == 0 ) ) : #NEWLINE# #INDENT# if project . get_property ( 'cram_fail_if_no_tests' ) : #NEWLINE# #INDENT# raise BuildFailedException ( 'No Cram tests found!' ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return #NEWLINE# #UNINDENT# #UNINDENT# command_and_arguments = _cram_command_for ( project ) #NEWLINE# command_and_arguments . extend ( cram_tests ) #NEWLINE# report_file = _report_file ( dist_dir ) #NEWLINE# env = os . environ . copy ( ) #NEWLINE# if project . get_property ( 'cram_run_test_from_target' ) : #NEWLINE# #INDENT# dist_dir = project . expand_path ( '$dir_dist' ) #NEWLINE# _prepend_path ( env , 'PYTHONPATH' , dist_dir ) #NEWLINE# script_dir_dist = project . get_property ( 'dir_dist_scripts' ) #NEWLINE# _prepend_path ( env , 'PATH' , os . path . join ( dist_dir , script_dir_dist ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# source_dir = project . expand_path ( '$dir_source_main_python' ) #NEWLINE# _prepend_path ( env , 'PYTHONPATH' , source_dir ) #NEWLINE# script_dir = project . expand_path ( '$dir_source_main_scripts' ) #NEWLINE# _prepend_path ( env , 'PATH' , script_dir ) #NEWLINE# #UNINDENT# return_code = execute_command ( command_and_arguments , report_file , env = env , error_file_name = report_file ) #NEWLINE# report = read_file ( report_file ) #NEWLINE# result = report [ ( - 1 ) ] [ 2 : ] . strip ( ) #NEWLINE# if ( return_code != 0 ) : #NEWLINE# #INDENT# logger . error ( 'Cram tests failed!' ) #NEWLINE# if project . get_property ( 'verbose' ) : #NEWLINE# #INDENT# for line in report : #NEWLINE# #INDENT# logger . error ( line . rstrip ( ) ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# logger . error ( result ) #NEWLINE# #UNINDENT# logger . error ( "See: '{0}' for details" . format ( report_file ) ) #NEWLINE# raise BuildFailedException ( 'Cram tests failed!' ) #NEWLINE# #UNINDENT# logger . info ( 'Cram tests were fine' ) #NEWLINE# logger . info ( result )