How to use test_bad_input method in green

Best Python code snippet using green

test_BadInput.py

Source:test_BadInput.py Github

copy

Full Screen

1import unittest2import os3from unittest.mock import patch4import MSParser5from MSOrganiser import no_concatenate_workflow6from MSDataOutput import MSDataOutput_Excel7from MSDataOutput import MSDataOutput_csv8NO_MS_FILE_JSONFILENAME = os.path.join(os.path.dirname(__file__),"testdata", 9 "test_bad_input", 'No_MS_File.json')10NO_OUTPUT_DIRECTORY_JSONFILENAME = os.path.join(os.path.dirname(__file__),"testdata", 11 "test_bad_input", 'No_Output_Directory.json')12NO_OUTPUT_OPTIONS_JSONFILENAME = os.path.join(os.path.dirname(__file__),"testdata", 13 "test_bad_input", 'No_Output_Options.json')14NO_ANNOT_FILE_JSONFILENAME = os.path.join(os.path.dirname(__file__),"testdata", 15 "test_bad_input", 'No_Annot_File.json')16INPUT_FOLDERNAME = os.path.join(os.path.dirname(__file__),"testdata", 17 "test_bad_input", 'input_folder.csv')18VALID_WIDETABLEFORM_FILENAME = os.path.join(os.path.dirname(__file__),"testdata", 19 "test_bad_input", 'Valid_WideTableForm.csv')20VALID_COMPOUNDTABLEFORM_FILENAME = os.path.join(os.path.dirname(__file__),"testdata", 21 "test_bad_input", 'Valid_CompoundTableForm.csv')22NO_DATAFILENAME_WIDETABLEFORM_FILENAME = os.path.join(os.path.dirname(__file__),"testdata", 23 "test_bad_input", 'NoDataFileColumn_WideTableForm.csv')24NO_DATAFILENAME_COMPOUNDTABLEFORM_FILENAME = os.path.join(os.path.dirname(__file__),"testdata", 25 "test_bad_input", 'NoDataFileColumn_CompoundTableForm.csv')26NO_NAME_COMPOUNDTABLEFORM_FILENAME = os.path.join(os.path.dirname(__file__),"testdata", 27 "test_bad_input", 'NoName_CompoundTableForm_Qualifier.csv')28INVALID_AGILENT_DATAFORM_FILENAME = os.path.join(os.path.dirname(__file__),"testdata", 29 "test_bad_input", 'Invalid_WideTableForm.csv')30INVALID_AGILENT_DATAFORM_FILENAME2 = os.path.join(os.path.dirname(__file__),"testdata", 31 "test_bad_input", 'Invalid_WideTableForm2.csv')32EMPTY_WIDETABLEFORM_FILENAME = os.path.join(os.path.dirname(__file__),"testdata", 33 "test_bad_input", 'Empty_WideTableForm.csv')34WRONG_EXTENTION_ANNOTATION_FILENAME = os.path.join(os.path.dirname(__file__),"testdata", 35 "test_bad_input", 'Valid_WideTableForm_Annot.csv')36INPUT_ANNOTATION_FOLDERNAME = os.path.join(os.path.dirname(__file__),"testdata", 37 "test_bad_input", 'input_annotation_folder')38class Bad_Input_Json_Test(unittest.TestCase):39 # See https://realpython.com/lessons/mocking-print-unit-tests/40 # for more details on mock41 def test_invalid_json_file(self):42 """Check if the software is able to detect invalid json file43 """44 # Replace the print function in MSParser.py file to a mock45 self.patcher = patch('MSParser.print')46 mock_print = self.patcher.start()47 #Read the parser48 with self.assertRaises(SystemExit) as cm:49 stored_args = MSParser.parse_MSOrganiser_args(args_json_file_path = NO_MS_FILE_JSONFILENAME,50 testing = True)51 # Ensure that the system ends with a -1 to indicate an error52 self.assertEqual(cm.exception.code, -1)53 # Ensure that the error was due to no MS file input54 mock_print.assert_called_with('Please key in at least one input MS file.',55 flush = True)56 #Read the parser57 with self.assertRaises(SystemExit) as cm:58 stored_args = MSParser.parse_MSOrganiser_args(args_json_file_path = NO_OUTPUT_DIRECTORY_JSONFILENAME,59 testing = True)60 # Ensure that the system ends with a -1 to indicate an error61 self.assertEqual(cm.exception.code, -1)62 # Ensure that the error was due to no output directory input63 mock_print.assert_called_with('Please key in at least one output directory.',64 flush = True)65 #Read the parser66 with self.assertRaises(SystemExit) as cm:67 stored_args = MSParser.parse_MSOrganiser_args(args_json_file_path = NO_OUTPUT_OPTIONS_JSONFILENAME,68 testing = True)69 # Ensure that the system ends with a -1 to indicate an error70 self.assertEqual(cm.exception.code, -1)71 # Ensure that the error was due to no output option input72 mock_print.assert_called_with('Please key in at least one result to output.',73 flush = True)74 #Read the parser75 with self.assertRaises(SystemExit) as cm:76 stored_args = MSParser.parse_MSOrganiser_args(args_json_file_path = NO_ANNOT_FILE_JSONFILENAME,77 testing = True)78 # Ensure that the system ends with a -1 to indicate an error79 self.assertEqual(cm.exception.code, -1)80 # Ensure that the error was due to no annotation file input when81 # normArea by ISTD or normConc by ISTD or both are selected 82 # in Output_Options83 mock_print.assert_called_with("Please key in an annotation file when \'normArea by ISTD\' " + 84 "or \'normConc by ISTD\' are selected in Output_Options.",85 flush = True)86 self.patcher.stop()87class Bad_Input_File_Test(unittest.TestCase):88 # See https://realpython.com/lessons/mocking-print-unit-tests/89 # for more details on mock90 def test_wrong_file_extention(self):91 """Check if the software is able to detect wrong input file extention92 """93 # Replace the print function in MSAnalysis.py file to a mock94 self.patcher = patch('MSAnalysis.print')95 mock_print = self.patcher.start()96 stored_args = {97 'MS_Files': ["wrong_extention"], 98 'MS_FileType': 'Agilent Wide Table in csv', 99 'Output_Directory': 'D:\\MSOrganiser', 100 'Output_Options': ['Area', 'normArea by ISTD', 'normConc by ISTD'], 101 'Annot_File': "", 102 'Output_Format': 'Excel', 103 'Concatenate': 'No Concatenate', 104 'Transpose_Results': False, 105 'Allow_Multiple_ISTD': False, 106 'Long_Table': False, 107 'Long_Table_Annot': False, 108 'Testing': False109 }110 mock_print = self.patcher.start()111 MS_FileType_list = ['Agilent Wide Table in csv', 112 'Agilent Compound Table in csv',113 'Multiquant Long Table in txt']114 MS_Files_list = ['no_csv_extention', 115 'no_csv_extention',116 'no_txt_extention']117 for i in range(len(MS_FileType_list)):118 stored_args['MS_FileType'] = MS_FileType_list[i]119 stored_args['MS_Files'] = [MS_Files_list[i]]120 right_extention = ""121 if MS_FileType_list[i] in ['Agilent Wide Table in csv', 'Agilent Compound Table in csv']:122 right_extention = ".csv"123 elif MS_FileType_list[i] in ['Multiquant Long Table in txt']:124 right_extention = ".txt"125 with self.assertRaises(SystemExit) as cm:126 [file_data_list, file_name] = no_concatenate_workflow(stored_args,testing = True)127 # Ensure that the system ends with a -1 to indicate an error128 self.assertEqual(cm.exception.code, -1)129 # Ensure that the error was due to wrong file extention130 mock_print.assert_called_with('Input file path ' + 131 '\'' + MS_Files_list[i] + '\' ' + 132 'must have a '+ right_extention + ' ' + 133 'extention.',134 flush = True)135 self.patcher.stop()136 def test_input_file_is_a_folder(self):137 """Check if the software is able to detect a folder input when a system138 file input is expected139 """140 # Replace the print function in MSRawData.py file to a mock141 self.patcher = patch('MSRawData.print')142 mock_print = self.patcher.start()143 stored_args = {144 'MS_Files': [INPUT_FOLDERNAME], 145 'MS_FileType': 'Agilent Wide Table in csv', 146 'Output_Directory': 'D:\\MSOrganiser', 147 'Output_Options': ['Area', 'normArea by ISTD', 'normConc by ISTD'], 148 'Annot_File': "", 149 'Output_Format': 'Excel', 150 'Concatenate': 'No Concatenate', 151 'Transpose_Results': False, 152 'Allow_Multiple_ISTD': False, 153 'Long_Table': False, 154 'Long_Table_Annot': False, 155 'Testing': False156 }157 with self.assertRaises(SystemExit) as cm:158 [file_data_list, file_name] = no_concatenate_workflow(stored_args,testing = True)159 # Ensure that the system ends with a -1 to indicate an error160 self.assertEqual(cm.exception.code, -1)161 # Ensure that the error was due to input of a folder instead of a file162 mock_print.assert_called_with('Input file path ' + '\'' + INPUT_FOLDERNAME + '\'' +163 ' does not lead to a system file. ' + 164 'Please check if the input file path is a system file and not a folder.',165 flush = True)166 self.patcher.stop()167 def test_input_file_cannot_be_found(self):168 """Check if the software is able to detect if the input file exists.169 If not, gives an error and inform the user about this issue.170 """171 # Replace the print function in MSRawData.py file to a mock172 self.patcher = patch('MSRawData.print')173 mock_print = self.patcher.start()174 stored_args = {175 'MS_Files': ["non_existing_file.csv"], 176 'MS_FileType': 'Agilent Wide Table in csv', 177 'Output_Directory': 'D:\\MSOrganiser', 178 'Output_Options': ['Area', 'normArea by ISTD', 'normConc by ISTD'], 179 'Annot_File': "", 180 'Output_Format': 'Excel', 181 'Concatenate': 'No Concatenate', 182 'Transpose_Results': False, 183 'Allow_Multiple_ISTD': False, 184 'Long_Table': False, 185 'Long_Table_Annot': False, 186 'Testing': False187 }188 with self.assertRaises(SystemExit) as cm:189 [file_data_list, file_name] = no_concatenate_workflow(stored_args,testing = True)190 # Ensure that the system ends with a -1 to indicate an error191 self.assertEqual(cm.exception.code, -1)192 # Ensure that the error was due to input of a csv file that does not exists193 mock_print.assert_called_with('Input file path ' + '\'non_existing_file.csv\'' +194 ' could not be found. ' +195 'Please check if the input file path.',196 flush = True)197 self.patcher.stop()198 def test_input_file_empty(self):199 """Check if the software is able to detect if the Agilent input file in200 Wide Table Form is empty and gives an error201 """202 # Replace the print function in MSRawData.py file to a mock203 self.patcher = patch('MSRawData.print')204 mock_print = self.patcher.start()205 stored_args = {206 'MS_Files': [EMPTY_WIDETABLEFORM_FILENAME], 207 'MS_FileType': 'Agilent Wide Table in csv', 208 'Output_Directory': 'D:\\MSOrganiser', 209 'Output_Options': ['Area'], 210 'Annot_File': "", 211 'Output_Format': 'Excel', 212 'Concatenate': 'No Concatenate', 213 'Transpose_Results': False, 214 'Allow_Multiple_ISTD': False, 215 'Long_Table': False, 216 'Long_Table_Annot': False, 217 'Testing': False218 }219 with self.assertRaises(SystemExit) as cm:220 [file_data_list, file_name] = no_concatenate_workflow(stored_args,testing = True)221 # Ensure that the system ends with a -1 to indicate an error222 self.assertEqual(cm.exception.code, -1)223 # Ensure that the error was due to empty input data224 mock_print.assert_called_with(EMPTY_WIDETABLEFORM_FILENAME +225 ' is an empty file. Please check the input file.',226 flush = True)227 self.patcher.stop()228 def test_input_invalid_output_option(self):229 """Check if the software is able to detect if the input output options are valid.230 If not, gives an error and inform the user about this issue.231 """232 # Replace the print function in MSRawData.py file to a mock233 self.patcher = patch('MSRawData.print')234 mock_print = self.patcher.start()235 stored_args = {236 'MS_Files': [VALID_WIDETABLEFORM_FILENAME], 237 'MS_FileType': 'Agilent Wide Table in csv', 238 'Output_Directory': 'D:\\MSOrganiser', 239 'Output_Options': ['Invalid Output Option', 'Area'], 240 'Annot_File': "", 241 'Output_Format': 'Excel', 242 'Concatenate': 'No Concatenate', 243 'Transpose_Results': False, 244 'Allow_Multiple_ISTD': False, 245 'Long_Table': False, 246 'Long_Table_Annot': False, 247 'Testing': False248 }249 with self.assertRaises(SystemExit) as cm:250 [file_data_list, file_name] = no_concatenate_workflow(stored_args,testing = True)251 # Ensure that the system ends with a -1 to indicate an error252 self.assertEqual(cm.exception.code, -1)253 # Ensure that the error was due to an invalid output option254 mock_print.assert_called_with('Output option Invalid Output Option ' + 255 'is not a valid column in MassHunter or not ' + 256 'available as a valid output for this program.',257 flush=True)258 stored_args = {259 'MS_Files': [VALID_COMPOUNDTABLEFORM_FILENAME], 260 'MS_FileType': 'Agilent Compound Table in csv', 261 'Output_Directory': 'D:\\MSOrganiser', 262 'Output_Options': ['Invalid Output Option', 'Area'], 263 'Annot_File': "", 264 'Output_Format': 'Excel', 265 'Concatenate': 'No Concatenate', 266 'Transpose_Results': False, 267 'Allow_Multiple_ISTD': False, 268 'Long_Table': False, 269 'Long_Table_Annot': False, 270 'Testing': False271 }272 with self.assertRaises(SystemExit) as cm:273 [file_data_list, file_name] = no_concatenate_workflow(stored_args,testing = True)274 # Ensure that the system ends with a -1 to indicate an error275 self.assertEqual(cm.exception.code, -1)276 # Ensure that the error was due to an invalid output option277 mock_print.assert_called_with('Output option Invalid Output Option ' + 278 'is not a valid column in MassHunter or not ' + 279 'available as a valid output for this program.',280 flush=True)281 self.patcher.stop()282 def test_invalid_agilent_dataform(self):283 """Check if the software is able to detect if the Agilent input file is284 neither in Wide Table or Compound Table Form.285 """286 # Replace the print function in MSRawData.py file to a mock287 self.patcher = patch('MSRawData.print')288 mock_print = self.patcher.start()289 stored_args = {290 'MS_Files': [INVALID_AGILENT_DATAFORM_FILENAME], 291 'MS_FileType': 'Agilent Wide Table in csv', 292 'Output_Directory': 'D:\\MSOrganiser', 293 'Output_Options': ['Area'], 294 'Annot_File': "", 295 'Output_Format': 'Excel', 296 'Concatenate': 'No Concatenate', 297 'Transpose_Results': False, 298 'Allow_Multiple_ISTD': False, 299 'Long_Table': False, 300 'Long_Table_Annot': False, 301 'Testing': False302 }303 with self.assertRaises(SystemExit) as cm:304 [file_data_list, file_name] = no_concatenate_workflow(stored_args,testing = True)305 # Ensure that the system ends with a -1 to indicate an error306 self.assertEqual(cm.exception.code, -1)307 # Ensure that the error was due to invalid Agilent input file 308 # which is neither in Wide Table or Compound Table Form.309 mock_print.assert_called_with(INVALID_AGILENT_DATAFORM_FILENAME + ' ' +310 'is missing \"Sample\" at first row and column in Wide Table form ' + 311 'or missing \"Compound Method\" at first row and column in Compound Table form. ' +312 'Please check the input file.',313 flush=True)314 #self.patcher.stop()315 stored_args = {316 'MS_Files': [INVALID_AGILENT_DATAFORM_FILENAME2], 317 'MS_FileType': 'Agilent Wide Table in csv', 318 'Output_Directory': 'D:\\MSOrganiser', 319 'Output_Options': ['Area'], 320 'Annot_File': "", 321 'Output_Format': 'Excel', 322 'Concatenate': 'No Concatenate', 323 'Transpose_Results': False, 324 'Allow_Multiple_ISTD': False, 325 'Long_Table': False, 326 'Long_Table_Annot': False, 327 'Testing': False328 }329 with self.assertRaises(SystemExit) as cm:330 [file_data_list, file_name] = no_concatenate_workflow(stored_args,testing = True)331 # Ensure that the system ends with a -1 to indicate an error332 self.assertEqual(cm.exception.code, -1)333 # Ensure that the error was due to invalid Agilent input file 334 # which is neither in Wide Table or Compound Table Form.335 mock_print.assert_called_with(INVALID_AGILENT_DATAFORM_FILENAME2 + ' ' +336 'is missing \"Sample\" at first row and column in Wide Table form ' + 337 'or missing \"Compound Method\" at first row and column in Compound Table form. ' +338 'Please check the input file.',339 flush=True)340 self.patcher.stop()341 342 def test_input_agilent_file_no_data_file(self):343 """Check if the software is able to detect if the Agilent input file in344 Wide Table Form or Compound Table Form have a Data File column 345 """346 # Replace the print function in MSRawData.py file to a mock347 self.patcher = patch('MSRawData.print')348 mock_print = self.patcher.start()349 stored_args = {350 'MS_Files': [NO_DATAFILENAME_WIDETABLEFORM_FILENAME], 351 'MS_FileType': 'Agilent Wide Table in csv', 352 'Output_Directory': 'D:\\MSOrganiser', 353 'Output_Options': ['Area'], 354 'Annot_File': "", 355 'Output_Format': 'Excel', 356 'Concatenate': 'No Concatenate', 357 'Transpose_Results': False, 358 'Allow_Multiple_ISTD': False, 359 'Long_Table': False, 360 'Long_Table_Annot': False, 361 'Testing': False362 }363 with self.assertRaises(SystemExit) as cm:364 [file_data_list, file_name] = no_concatenate_workflow(stored_args,testing = True)365 # Ensure that the system ends with a -1 to indicate an error366 self.assertEqual(cm.exception.code, -1)367 # Ensure that the error was due to no Data File column in the Agilent Wide Table Form in csv368 mock_print.assert_called_with('\'' + os.path.basename(NO_DATAFILENAME_WIDETABLEFORM_FILENAME) + '\' ' +369 'has no column containing \"Data File\". ' + 370 'Please check the input file.',371 flush = True)372 stored_args = {373 'MS_Files': [NO_DATAFILENAME_COMPOUNDTABLEFORM_FILENAME], 374 'MS_FileType': 'Agilent Compound Table in csv', 375 'Output_Directory': 'D:\\MSOrganiser', 376 'Output_Options': ['Area'], 377 'Annot_File': "", 378 'Output_Format': 'Excel', 379 'Concatenate': 'No Concatenate', 380 'Transpose_Results': False, 381 'Allow_Multiple_ISTD': False, 382 'Long_Table': False, 383 'Long_Table_Annot': False, 384 'Testing': False385 }386 with self.assertRaises(SystemExit) as cm:387 [file_data_list, file_name] = no_concatenate_workflow(stored_args,testing = True)388 # Ensure that the system ends with a -1 to indicate an error389 self.assertEqual(cm.exception.code, -1)390 # Ensure that the error was due to no Data File column in the Agilent Compound Table Form in csv391 mock_print.assert_called_with('\'' + os.path.basename(NO_DATAFILENAME_COMPOUNDTABLEFORM_FILENAME) + '\' ' +392 'has no column containing \"Data File\". ' + 393 'Please check the input file.',394 flush = True)395 self.patcher.stop()396 def test_input_agilent_compound_table_file_no_name(self):397 """Check if the software is able to detect if the Agilent input file in398 Compound Table Form have a Name column 399 """400 stored_args = {401 'MS_Files': [NO_NAME_COMPOUNDTABLEFORM_FILENAME], 402 'MS_FileType': 'Agilent Compound Table in csv', 403 'Output_Directory': 'D:\\MSOrganiser', 404 'Output_Options': ['Area'], 405 'Annot_File': "", 406 'Output_Format': 'Excel', 407 'Concatenate': 'No Concatenate', 408 'Transpose_Results': False, 409 'Allow_Multiple_ISTD': False, 410 'Long_Table': False, 411 'Long_Table_Annot': False, 412 'Testing': False413 }414 # Replace the print function in MSRawData.py file to a mock415 self.patcher = patch('MSRawData.print')416 mock_print = self.patcher.start()417 with self.assertRaises(SystemExit) as cm:418 [file_data_list, file_name] = no_concatenate_workflow(stored_args,testing = True)419 # Ensure that the system ends with a -1 to indicate an error420 self.assertEqual(cm.exception.code, -1)421 # Ensure that the error was due to no Name column422 # in Compound Method Table for423 # Agilent Compound Table Form in csv424 mock_print.assert_called_with('\'' + os.path.basename(NO_NAME_COMPOUNDTABLEFORM_FILENAME) + '\' ' +425 'has no column contaning \"Name\" in Compound Method Table. ' + 426 'Please check the input file.',427 flush = True)428 self.patcher.stop()429 def test_input_valid_output_option_agilent_no_data_excel(self):430 """Check if the software is able to detect if the input output option is valid431 but the output option is not found in the input file when creating an excel file432 """433 # Replace the print function in MSDataOutput.py file to a mock434 self.patcher = patch('MSDataOutput.print')435 mock_print = self.patcher.start()436 output_directory = os.path.join(os.path.dirname(__file__),"testdata", "test_bad_input")437 stored_args = {438 'MS_Files': [VALID_WIDETABLEFORM_FILENAME], 439 'MS_FileType': 'Agilent Wide Table in csv', 440 'Output_Directory': output_directory, 441 'Output_Options': ['Area', 'S/N'], 442 'Annot_File': "", 443 'Output_Format': 'Excel', 444 'Concatenate': 'No Concatenate', 445 'Transpose_Results': False, 446 'Allow_Multiple_ISTD': False, 447 'Long_Table': False, 448 'Long_Table_Annot': False, 449 'Testing': False450 }451 [file_data_list, file_name] = no_concatenate_workflow(stored_args,testing = True)452 #print(file_name)453 #print(file_data_list[0][0][1])454 #print(file_data_list[0][0][0])455 DfOutput = MSDataOutput_Excel(stored_args['Output_Directory'], VALID_WIDETABLEFORM_FILENAME, 456 result_name = "Results" ,457 logger = None, ingui = True)458 DfOutput.start_writer()459 DfOutput.df_to_file("Area",file_data_list[0][0][0],460 transpose=stored_args['Transpose_Results'],461 allow_multiple_istd = False)462 DfOutput.df_to_file("S/N",file_data_list[0][0][1],463 transpose=stored_args['Transpose_Results'],464 allow_multiple_istd = False)465 DfOutput.end_writer(testing = True)466 # Ensure that the warning was due to no data available for that output option467 mock_print.assert_called_with('S/N has no data. Please check the input file.',468 flush=True)469 self.patcher.stop()470 def test_input_valid_output_option_agilent_no_data_csv(self):471 """Check if the software is able to detect if the input output option is valid472 but the output option is not found in the input file when creating a csv file473 """474 # Replace the print function in MSDataOutput.py file to a mock475 self.patcher = patch('MSDataOutput.print')476 mock_print = self.patcher.start()477 output_directory = os.path.join(os.path.dirname(__file__),"testdata", "test_bad_input")478 stored_args = {479 'MS_Files': [VALID_WIDETABLEFORM_FILENAME], 480 'MS_FileType': 'Agilent Wide Table in csv', 481 'Output_Directory': output_directory, 482 'Output_Options': ['S/N'], 483 'Annot_File': "", 484 'Output_Format': 'Excel', 485 'Concatenate': 'No Concatenate', 486 'Transpose_Results': False, 487 'Allow_Multiple_ISTD': False, 488 'Long_Table': True, 489 'Long_Table_Annot': False, 490 'Testing': False491 }492 [file_data_list, file_name] = no_concatenate_workflow(stored_args,testing = True)493 DfOutput = MSDataOutput_csv(stored_args['Output_Directory'], VALID_WIDETABLEFORM_FILENAME, 494 result_name = "" , logger = None, ingui = True)495 DfOutput.start_writer()496 DfOutput.df_to_file("S/N",file_data_list[0][0][0],497 transpose=stored_args['Transpose_Results'],498 allow_multiple_istd = False)499 500 # Ensure that the warning was due to no data available for that output option501 mock_print.assert_called_with('S/N has no data. Please check the input file.',502 flush=True)503 #self.patcher.stop()504 DfLongOutput = MSDataOutput_csv(stored_args['Output_Directory'], VALID_WIDETABLEFORM_FILENAME, 505 result_name = "" , logger = None, ingui=True)506 DfLongOutput.start_writer()507 DfLongOutput.df_to_file("Long_Table",file_data_list[0][0][1])508 # Ensure that the warning was due to no data available for that output option509 mock_print.assert_called_with('Long_Table has no data. Please check the input file.',510 flush=True)511 self.patcher.stop()512class Bad_Annotation_Test(unittest.TestCase):513 # See https://realpython.com/lessons/mocking-print-unit-tests/514 # for more details on mock515 def test_input_annotation_cannot_be_found(self):516 """Check if the software is able to detect if the input annotation file exists.517 If not, gives an error and inform the user about this issue.518 """519 # Replace the print function in Annotation.py file to a mock520 self.patcher = patch('Annotation.print')521 mock_print = self.patcher.start()522 output_directory = os.path.join(os.path.dirname(__file__),"testdata", "test_bad_input")523 stored_args = {524 'MS_Files': [VALID_WIDETABLEFORM_FILENAME], 525 'MS_FileType': 'Agilent Wide Table in csv', 526 'Output_Directory': output_directory, 527 'Output_Options': ['Area', 'normArea by ISTD'], 528 'Annot_File': "non_existing_annot_file.xlsm", 529 'Output_Format': 'Excel', 530 'Concatenate': 'No Concatenate', 531 'Transpose_Results': False, 532 'Allow_Multiple_ISTD': False, 533 'Long_Table': False, 534 'Long_Table_Annot': False, 535 'Testing': False536 }537 with self.assertRaises(SystemExit) as cm:538 [file_data_list, file_name] = no_concatenate_workflow(stored_args,testing = True)539 # Ensure that the system ends with a -1 to indicate an error540 self.assertEqual(cm.exception.code, -1)541 # Ensure that the error was due to no Data File column in the Agilent Wide Table Form in csv542 mock_print.assert_called_with('Input annotation ' + '\'non_existing_annot_file.xlsm\'' +543 ' could not be found. ' +544 'Please check the input file path.',545 flush = True)546 self.patcher.stop()547 def test_input_annotation_wrong_file_extention(self):548 """Check if the software is able to detect if the input annotation file549 has the wrong file extension550 """551 # Replace the print function in Annotation.py file to a mock552 self.patcher = patch('Annotation.print')553 mock_print = self.patcher.start()554 output_directory = os.path.join(os.path.dirname(__file__),"testdata", "test_bad_input")555 stored_args = {556 'MS_Files': [VALID_WIDETABLEFORM_FILENAME], 557 'MS_FileType': 'Agilent Wide Table in csv', 558 'Output_Directory': output_directory, 559 'Output_Options': ['Area', 'normArea by ISTD'], 560 'Annot_File': WRONG_EXTENTION_ANNOTATION_FILENAME, 561 'Output_Format': 'Excel', 562 'Concatenate': 'No Concatenate', 563 'Transpose_Results': False, 564 'Allow_Multiple_ISTD': False, 565 'Long_Table': False, 566 'Long_Table_Annot': False, 567 'Testing': False568 }569 with self.assertRaises(SystemExit) as cm:570 [file_data_list, file_name] = no_concatenate_workflow(stored_args,testing = True)571 # Ensure that the system ends with a -1 to indicate an error572 self.assertEqual(cm.exception.code, -1)573 # Ensure that the error was due to no Data File column in the Agilent Wide Table Form in csv574 mock_print.assert_called_with('This program no longer accepts csv file as input for the annotation file. Please use the excel template file given.',575 flush = True)576 self.patcher.stop()577 def test_input_annotation_is_a_folder(self):578 """Check if the software is able to detect a folder input when a system579 file input is expected580 """581 # Replace the print function in Annotation.py file to a mock582 self.patcher = patch('Annotation.print')583 mock_print = self.patcher.start()584 stored_args = {585 'MS_Files': [VALID_WIDETABLEFORM_FILENAME],586 'MS_FileType': 'Agilent Wide Table in csv', 587 'Output_Directory': 'D:\\MSOrganiser', 588 'Output_Options': ['Area', 'normArea by ISTD', 'normConc by ISTD'], 589 'Annot_File': INPUT_ANNOTATION_FOLDERNAME, 590 'Output_Format': 'Excel', 591 'Concatenate': 'No Concatenate', 592 'Transpose_Results': False, 593 'Allow_Multiple_ISTD': False, 594 'Long_Table': False, 595 'Long_Table_Annot': False, 596 'Testing': False597 }598 with self.assertRaises(SystemExit) as cm:599 [file_data_list, file_name] = no_concatenate_workflow(stored_args,testing = True)600 # Ensure that the system ends with a -1 to indicate an error601 self.assertEqual(cm.exception.code, -1)602 # Ensure that the error was due to input of a folder instead of a file603 mock_print.assert_called_with('Input file path ' + '\'' + INPUT_ANNOTATION_FOLDERNAME + '\'' +604 ' does not lead to a system file. ' + 605 'Please check if the input file path is a system file and not a folder.',606 flush = True)607 self.patcher.stop()608if __name__ == '__main__':...

Full Screen

Full Screen

test_aging.py

Source:test_aging.py Github

copy

Full Screen

...79 assert np.sum(80 np.isclose([col_coord[0], col_coord[1], col_coord[2]], [27, 35, 27])) == 3, "color coordinates wrong"81 assert np.sum(82 np.isclose([mag_range[0], mag_range[1], mag_range[2]], [90, 40, 130])) == 3, "magnitude coordinates wrong"83 def test_bad_input(self):84 with pytest.raises(HokiFormatError):85 col_coord, mag_range = au._find_cmd_coordinates(obs_df=bad_hrd_input, mycmd=mycmd)86 def test_bad_input_2(self):87 col_coord, mag_range = au._find_cmd_coordinates(obs_df=bad_cmd_input, mycmd=mycmd)88 #assert np.siz(col_coord[0]), "This should be a nan"89 assert np.isclose(mag_range[0], 90), "This L coordinate is wrong - test_bad_input."90class TestFindHRDCoordinates(object):91 def test_fake_input(self):92 T_coord, L_coord = au._find_hrd_coordinates(obs_df=fake_hrd_input, myhrd=myhrd)93 assert np.sum(94 np.isclose([T_coord[0], T_coord[1], T_coord[2]], [45, 44, 40])) == 3, "Temperature coordinates wrong"95 assert np.sum(96 np.isclose([L_coord[0], L_coord[1], L_coord[2]], [77, 80, 83])) == 3, "Luminosity coordinates wrong"97 def test_bad_input(self):98 with pytest.raises(HokiFormatError):99 __, __ = au._find_hrd_coordinates(obs_df=bad_cmd_input, mycmd=mycmd)100 def test_bad_input(self):101 T_coord, L_coord = au._find_hrd_coordinates(obs_df=bad_hrd_input, myhrd=myhrd)102 #assert np.isnan(T_coord[0]), "This should be a nan"103 assert np.isclose(L_coord[0], 77), "This L coordinate is wrong - test_bad_input."104class TestNormalise1D(object):105 def test_it_runs(self):106 au.normalise_1d(np.array([0, 1, 4, 5, 0, 1, 7, 8]), crop_the_future=False)107 def test_basic(self):108 norm = au.normalise_1d(np.array([0, 0, 1, 0, 0, 0, 0]), crop_the_future=False)109 assert norm[2] == 1, 'Normalisation done wrong'110 assert sum(norm) == 1, "Normalisaton done wrong"111class TestCalculatePDFs(object):112 def test_fake_input(self):113 pdf_df = au.calculate_individual_pdfs(fake_hrd_input, myhrd)114 assert 'star1' in pdf_df.columns, "Column name issue"115 assert int(sum(pdf_df.star1)) == 1, "PDF not calculated correctly"116 def test_input_without_name(self):117 pdf_df = au.calculate_individual_pdfs(no_name_input, myhrd)118 assert 's1' in pdf_df.columns, "Column names not created right"119 def test_bad_input(self):120 pdf_df = au.calculate_individual_pdfs(bad_hrd_input2, myhrd)121 assert not np.isnan(sum(pdf_df.s0)), "somwthing went wrong"122 #assert np.isnan(sum(distributions_df.s1)), "somwthing went wrong"123class TestCalculateSamplePDF(object):124 def test_basic(self):125 distributions = au.calculate_distributions(fake_hrd_input, myhrd)126 combined = au.calculate_sample_pdf(distributions)127 assert np.isclose(combined.pdf[9], 0.2715379752638662), "combined PDF not right"128 def test_drop_bad(self):129 distributions = au.calculate_distributions(fake_hrd_input, myhrd)130 combined = au.calculate_sample_pdf(distributions, not_you=[3])131 assert np.isclose(combined.pdf[9], 0.2715379752638662), "combined PDF not right"132 def test_drop_good(self):133 distributions = au.calculate_distributions(fake_hrd_input, myhrd)...

Full Screen

Full Screen

test_utils.py

Source:test_utils.py Github

copy

Full Screen

...82 assert np.sum(83 np.isclose([col_coord[0], col_coord[1], col_coord[2]], [27, 35, 27])) == 3, "color coordinates wrong"84 assert np.sum(85 np.isclose([mag_range[0], mag_range[1], mag_range[2]], [90, 40, 130])) == 3, "magnitude coordinates wrong"86 def test_bad_input(self):87 with pytest.raises(HokiFormatError):88 col_coord, mag_range = au._find_cmd_coordinates(obs_df=bad_hrd_input, mycmd=mycmd)89 def test_bad_input_2(self):90 col_coord, mag_range = au._find_cmd_coordinates(obs_df=bad_cmd_input, mycmd=mycmd)91 assert np.isclose(mag_range[0], 90), "This L coordinate is wrong - test_bad_input."92class TestFindHRDCoordinates(object):93 def test_fake_input(self):94 T_coord, L_coord = au._find_hrd_coordinates(obs_df=fake_hrd_input, myhrd=myhrd)95 assert np.sum(96 np.isclose([T_coord[0], T_coord[1], T_coord[2]], [45, 44, 40])) == 3, "Temperature coordinates wrong"97 assert np.sum(98 np.isclose([L_coord[0], L_coord[1], L_coord[2]], [77, 80, 83])) == 3, "Luminosity coordinates wrong"99 def test_bad_input(self):100 with pytest.raises(HokiFormatError):101 __, __ = au._find_hrd_coordinates(obs_df=bad_cmd_input, mycmd=mycmd)102 def test_bad_input(self):103 T_coord, L_coord = au._find_hrd_coordinates(obs_df=bad_hrd_input, myhrd=myhrd)104 #assert np.isnan(T_coord[0]), "This should be a nan"105 assert np.isclose(L_coord[0], 77), "This L coordinate is wrong - test_bad_input."106###############################107# CALCULATING INDIVIDUAL PDFS #108###############################109class TestCalculatePDFs(object):110 def test_fake_input(self):111 pdf_df = au.calculate_individual_pdfs(fake_hrd_input, myhrd)112 assert 'star1' in pdf_df.columns, "Column name issue"113 assert int(sum(pdf_df.star1)) == 1, "PDF not calculated correctly"114 def test_input_without_name(self):115 pdf_df = au.calculate_individual_pdfs(no_name_input, myhrd)116 assert 's1' in pdf_df.columns, "Column names not created right"117 def test_bad_input(self):118 pdf_df = au.calculate_individual_pdfs(bad_hrd_input2, myhrd)119 assert not np.isnan(sum(pdf_df.s0)), "something went wrong"120 def test_symmetric_errors(self):121 pdf_df = au.calculate_individual_pdfs(stars_SYM, myhrd)122 assert not np.isnan(sum(pdf_df['118-4'])), "something went wrong with symmetric errors"123#####################################124# PUTTING PDFS TOGETHER IN SOME WAY #125#####################################126class TestCalculateSamplePDF(object):127 def test_basic(self):128 distributions = au.calculate_distributions(fake_hrd_input, myhrd)129 combined = au.calculate_sample_pdf(distributions)130 assert np.isclose(combined.pdf[9], 0.2715379752638662), "combined PDF not right"131 def test_drop_bad(self):...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run green automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful