def test_importTrialTypes(self): filename = join(fixturesPath, 'dataTest.xlsx') expected_cond = utils.OrderedDict([('text', 'red'), ('congruent', 1), ('corrAns', 1), ('letterColor', 'red'), ('n', 2)]) conds = utils.importTrialTypes(filename) assert conds[0] == expected_cond
def test_importConditions(self): standard_files = [] standard_files.append(join(fixturesPath, 'trialTypes.xlsx')) #standard_files.append(join(fixturesPath, 'trialTypes.xls')) # xls is depreciated standard_files.append(join(fixturesPath, 'trialTypes.csv')) standard_files.append(join(fixturesPath, 'trialTypes_eu.csv')) standard_files.append(join(fixturesPath, 'trialTypes.tsv')) # some extra formats (expected fails) fileName_pkl = join(fixturesPath, 'trialTypes.pkl') fileName_docx = join(fixturesPath, 'trialTypes.docx') expected_cond = utils.OrderedDict([('text', 'red'), ('congruent', 1), ('corrAns', 1), ('letterColor', 'red'), ('n', 2), ('float', 1.1)]) # check import worked for standard file formats for filename in standard_files: conds = utils.importConditions(filename) assert conds[0] == expected_cond, ( "Did not correctly import for '{}': " "expected({}) != imported({})".format(filename, expected_cond, conds[0])) # test for None in filename with _assertValidVarNames assert utils.importConditions(fileName=None) == [] assert utils.importConditions(fileName=None, returnFieldNames=True) == ([], []) # Test value error for non-existent file with pytest.raises(ValueError) as errMsg: utils.importConditions(fileName='raiseErrorfileName') assert 'Conditions file not found: %s' % os.path.abspath( 'raiseErrorfileName') in str(errMsg.value) if PY3: conds = utils.importConditions(fileName_pkl) assert conds[0] == expected_cond else: with pytest.raises((IOError)) as errMsg: utils.importConditions(fileName_pkl) assert ('Could not open %s as conditions' % fileName_pkl) == str( errMsg.value) # trialTypes.pkl saved in list of list format (see trialTypes.docx) # test assertion for invalid file type with pytest.raises(IOError) as errMsg: utils.importConditions(fileName_docx) assert ('Your conditions file should be an ' 'xlsx, csv, dlm, tsv or pkl file') == str(errMsg.value) # test random selection of conditions all_conditions = utils.importConditions(standard_files[0]) assert len(all_conditions) == 6 num_selected_conditions = 1001 selected_conditions = utils.importConditions( standard_files[0], selection=(np.concatenate( ([0.9], np.random.random(num_selected_conditions - 1) * len(all_conditions))))) assert selected_conditions[0] == expected_cond assert len(selected_conditions) == num_selected_conditions
def test_importConditions(self): fileName_xlsx = os.path.join(fixturesPath, 'trialTypes.xlsx') fileName_xls = os.path.join(fixturesPath, 'trialTypes.xls') fileName_csv = os.path.join(fixturesPath, 'trialTypes.csv') fileName_pkl = os.path.join(fixturesPath, 'trialTypes.pkl') fileName_docx = os.path.join(fixturesPath, 'trialTypes.docx') expected_cond = utils.OrderedDict([('text', 'red'), ('congruent', 1), ('corrAns', 1), ('letterColor', 'red'), ('n', 2), ('float', 1.1)]) conds = utils.importConditions(fileName_xlsx) assert conds[0] == expected_cond # test for None in filename with _assertValidVarNames assert utils.importConditions(fileName=None) == [] assert utils.importConditions(fileName=None, returnFieldNames=True) == ([], []) # Test value error for non-existent file with pytest.raises(ValueError) as errMsg: utils.importConditions(fileName='raiseErrorfileName') assert 'Conditions file not found: %s' % os.path.abspath( 'raiseErrorfileName') in str(errMsg.value) # Check file extensions in nested pandasToDictList() conds = utils.importConditions(fileName_csv) assert conds[0] == expected_cond conds = utils.importConditions(fileName_xls) assert conds[0] == expected_cond if PY3: conds = utils.importConditions(fileName_pkl) assert conds[0] == expected_cond else: with pytest.raises((IOError)) as errMsg: utils.importConditions(fileName_pkl) assert ('Could not open %s as conditions' % fileName_pkl) == str( errMsg.value) # trialTypes.pkl saved in list of list format (see trialTypes.docx) # test assertion for invalid file type with pytest.raises(IOError) as errMsg: utils.importConditions(fileName_docx) assert ('Your conditions file should be an ' 'xlsx, csv or pkl file') == str(errMsg.value)