def test_should_expect_at_least_one_results_file(self): try: TestResults.parse_args(self.parser, '--type foo --input bar --results'.split()) except SystemExit: return self.fail('Parser accepts zero results files')
def test_type_should_not_be_optional(self): try: TestResults.parse_args(self.parser, '--input foo --results bar'.split()) except ValueError: return self.fail('Parser does not fail when a test type is not present')
def test_results_should_not_be_optional(self): try: TestResults.parse_args(self.parser, '--type foo --input bar'.split()) except ValueError: return self.fail('Parser does not fail when results files are not present')
def test_should_not_check_if_non_present_input_files_are_missing(self): input_files = copy.copy(self.input_files) del input_files['Text2.txt'] try: TestResults.compute_test_pairs(self.job, input_files, self.format) except ValueError: self.fail("compute_test_pairs shouldn't throw ValueError if non-present job file is not in input_files")
def test_should_allow_more_than_one_results_file(self): try: TestResults.parse_args( self.parser, '--type foo --input file --results these files'.split()) except SystemExit: self.fail("Parser doesn't accept multiple results files")
def test_only_one_type_allowed(self): try: TestResults.parse_args( self.parser, '--type two words --input foo --results bar'.split()) except SystemExit: # TODO: Wrap argparse behavior return self.fail('Parser accepts more than one test type')
def test_should_throw_valueerror_if_too_few_input_files(self): input_files = copy.copy(self.input_files) del input_files['Text3.txt'] try: TestResults.compute_test_pairs(self.job, input_files, self.format) except ValueError: return self.fail('compute_test_pairs should throw ValueError if an input file is not in input_files')
def test_should_not_check_if_non_present_input_files_are_missing(self): input_files = copy.copy(self.input_files) del input_files['Text2.txt'] try: TestResults.compute_test_pairs(self.job, input_files, self.format) except ValueError: self.fail( "compute_test_pairs shouldn't throw ValueError if non-present job file is not in input_files" )
def test_should_throw_valueerror_if_too_few_input_files(self): input_files = copy.copy(self.input_files) del input_files['Text3.txt'] try: TestResults.compute_test_pairs(self.job, input_files, self.format) except ValueError: return self.fail( 'compute_test_pairs should throw ValueError if an input file is not in input_files' )
def setUp(self): self.job = { 'Text1.txt': { 'text': 'first', 'present': True }, 'Text2.txt': { 'text': 'second', 'present': False }, 'Text3.txt': { 'text': 'third', 'present': True } } self.input_files = { 'Text1.txt': { 'fullpath': '/Text1.txt', 'text': '' }, 'Text2.txt': { 'fullpath': '/Text2.txt', 'text': '' }, 'Text3.txt': { 'fullpath': '/Text3.txt', 'text': '' }, } self.results = TestResults.compute_test_pairs(self.job, self.input_files, self.format)
def test_should_keep_file_false_if_not_in_inputs(self): files = TestResults.match_files(['Text1.txt'], self.results_files) if any([ files['Text2.txt']['present'] is not False, files['Text3.txt']['present'] is not False ]): self.fail('match_files should keep entries set to False if not present in input_files')
def test_should_not_add_files_in_wrong_element(self): results = TestResults.parse_docuscope_results( [self.ds_wrong_tag_results_file]) if len(results.keys()) > 1: self.fail( 'parse_docuscope_results added files not in AnnotatedText elements' )
def test_should_handle_one_file(self): results = TestResults.parse_docuscope_results([self.ds_results_file]) keys = results.keys() if any([ 'Text1.txt' not in keys, 'Text2.txt' not in keys, 'Text3.txt' not in keys ]): self.fail("parse_docuscope_results didn't add expected files for one input file")
def test_should_keep_file_false_if_not_in_inputs(self): files = TestResults.match_files(['Text1.txt'], self.results_files) if any([ files['Text2.txt']['present'] is not False, files['Text3.txt']['present'] is not False ]): self.fail( 'match_files should keep entries set to False if not present in input_files' )
def test_should_handle_one_file(self): results = TestResults.parse_docuscope_results([self.ds_results_file]) keys = results.keys() if any([ 'Text1.txt' not in keys, 'Text2.txt' not in keys, 'Text3.txt' not in keys ]): self.fail( "parse_docuscope_results didn't add expected files for one input file" )
def test_should_handle_multiples_files(self): results = TestResults.parse_docuscope_results( [self.ds_results_file, self.ds_results_file_2]) keys = results.keys() if any([ 'Text1.txt' not in keys, 'Text2.txt' not in keys, 'Text3.txt' not in keys, 'Text4.txt' not in keys, 'Text5.txt' not in keys ]): self.fail( "parse_docuscope_results didn't add expected files for multiple input files" )
def test_should_handle_multiples_files(self): results = TestResults.parse_docuscope_results([self.ds_results_file, self.ds_results_file_2]) keys = results.keys() if any([ 'Text1.txt' not in keys, 'Text2.txt' not in keys, 'Text3.txt' not in keys, 'Text4.txt' not in keys, 'Text5.txt' not in keys ]): self.fail("parse_docuscope_results didn't add expected files for multiple input files")
def setUp(self): self.job = { 'Text1.txt': {'text': 'first', 'present': True}, 'Text2.txt': {'text': 'second', 'present': False}, 'Text3.txt': {'text': 'third', 'present': True} } self.input_files = { 'Text1.txt': {'fullpath': '/Text1.txt', 'text': ''}, 'Text2.txt': {'fullpath': '/Text2.txt', 'text': ''}, 'Text3.txt': {'fullpath': '/Text3.txt', 'text': ''}, } self.results = TestResults.compute_test_pairs(self.job, self.input_files, self.format)
def setUp(self): self.test_pairs = { 'Text1.txt': { 'name': 'Text1.txt', 'ground_truth': 'foo', 'test_input': 'foo' }, 'Text2.txt': { 'name': 'Text2.txt', 'ground_truth': 'foo', 'test_input': 'bar' } } self.results = TestResults.compare_test_pairs(self.test_pairs, self.compare)
def __init__(self, testingDirectory='', dataSetDirectory='', debug=False): # keep data containers in this base class as some are used in the functions of this class. self._tests = [] # list of test objects self._testNames = {} # dict of test file names (a list of names per component) self._testParamValues = {} self._generateOriginals = False # bool for generating original data set self._debug = debug # create testing directory if not isinstance(testingDirectory, _np.str): raise TypeError("Testing directory is not a string") else: if testingDirectory == '': pass elif _os.getcwd().split('/')[-1] == testingDirectory: pass # check for directory and make it if not: elif _os.path.exists(testingDirectory): _os.chdir(testingDirectory) elif not _os.path.exists(testingDirectory): _os.system("mkdir " + testingDirectory) _os.chdir(testingDirectory) # make dirs for gmad files, results, bdsim output, and failed outputs if not _os.path.exists('Tests'): _os.system("mkdir Tests") if not _os.path.exists('Results'): _os.system("mkdir Results") if not _os.path.exists('BDSIMOutput'): _os.system("mkdir BDSIMOutput") _os.chdir('BDSIMOutput') if not _os.path.exists('FailedTests'): _os.system("mkdir FailedTests") _os.chdir('../') # set directory of existing data set that the tests will be compared to self._dataSetDirectory = '' if isinstance(dataSetDirectory, _np.str): self._dataSetDirectory = dataSetDirectory self.Analysis = TestResults.Analysis() # results instance
def test_should_not_change_input_files(self): input_files = ['Text1.txt'] old_input = copy.copy(input_files) TestResults.match_files(input_files, self.results_files) if old_input != input_files: self.fail('match_files should not change input_files')
def test_should_not_change_results_files(self): old_results = copy.copy(self.results_files) TestResults.match_files(['Text1.txt'], self.results_files) if old_results != self.results_files: self.fail('match_files should not change results_files')
def setUp(self): self.input_files = [ '/foo/bar/Text1.txt', 'bar/baz/Text2.txt', 'Text3.txt', '../Text4.txt' ] self.results = TestResults.parse_input_files(self.input_files)
import Globals import PhaseSpace import Writer import TestResults from pybdsim import Writer as _pybdsimWriter from pybdsim import Options as _options # data type with multiple entries that can be handled by the functions. multiEntryTypes = [tuple, list, _np.ndarray] GlobalData = Globals.Globals() # result utility functions for checking output log files. # Needed by Run function, so instantiate here. ResultUtils = TestResults.ResultsUtilities() def _runBDSIM(inputDict, timeout): # Start the BDSIM process process = Popen([GlobalData._bdsimExecutable, "--file=" + inputDict['testFile'], "--output=rootevent", "--outfile="+inputDict['outputFile'], "--batch", "--seed=2017"], stdout=open(inputDict['bdsimLogFile'], 'a'), stderr=open(inputDict['bdsimLogFile'], 'a'))
def test_should_add_text(self): results = TestResults.parse_docuscope_results([self.ds_results_file]) # TODO: This test doesn't check as much as it should if any(map(lambda x: 'text' not in x, results.values())): self.fail('parse_docuscope_results should add "text" key')
def test_should_do_nothing_if_missing_file_attribute(self): results = TestResults.parse_docuscope_results([self.ds_wrong_attr_results_file]) # TODO: Bad test if len(results.keys()) != 1: self.fail("parse_docuscope_results didn't add files correctly")
def test_should_do_nothing_if_missing_file_attribute(self): results = TestResults.parse_docuscope_results( [self.ds_wrong_attr_results_file]) # TODO: Bad test if len(results.keys()) != 1: self.fail("parse_docuscope_results didn't add files correctly")
def test_should_set_file_true_if_in_inputs(self): files = TestResults.match_files(['Text1.txt'], self.results_files) if files['Text1.txt']['present'] is not True: self.fail('match_files should set entries to True if present in input_files')
def test_only_one_type_allowed(self): try: TestResults.parse_args(self.parser, '--type two words --input foo --results bar'.split()) except SystemExit: # TODO: Wrap argparse behavior return self.fail('Parser accepts more than one test type')
def test_should_allow_more_than_one_results_file(self): try: TestResults.parse_args(self.parser, '--type foo --input file --results these files'.split()) except SystemExit: self.fail("Parser doesn't accept multiple results files")
def setUp(self): self.input_files = ['/foo/bar/Text1.txt', 'bar/baz/Text2.txt', 'Text3.txt', '../Text4.txt'] self.results = TestResults.parse_input_files(self.input_files)
def test_should_add_present_status(self): results = TestResults.parse_docuscope_results([self.ds_results_file]) if any(map(lambda x: 'present' not in x, results.values())): self.fail('parse_docuscope_results should add "present" key')
def test_should_copy_results(self): if self.results_files != TestResults.match_files([], self.results_files): self.fail('match_files should return results_files if input_files empty')
def test_should_copy_results(self): if self.results_files != TestResults.match_files([], self.results_files): self.fail( 'match_files should return results_files if input_files empty')
def test_should_set_file_true_if_in_inputs(self): files = TestResults.match_files(['Text1.txt'], self.results_files) if files['Text1.txt']['present'] is not True: self.fail( 'match_files should set entries to True if present in input_files' )
def test_should_not_add_files_in_wrong_element(self): results = TestResults.parse_docuscope_results([self.ds_wrong_tag_results_file]) if len(results.keys()) > 1: self.fail('parse_docuscope_results added files not in AnnotatedText elements')
def setUp(self): self.parser = TestResults.make_parser()