def testNoFilesInList(self): test_input = ["-f", EMPTY_LOG_LIST] if logger.isEnabledFor(logging.DEBUG): main(test_input) with capture_stderr(main, test_input) as output: self.assertTrue( "Found no lammps log data to process from" in output)
def testSumWOBest(self): test_input = ["-c", DA_GAUSS_INI, "-s", ORIG_ALL_BEST] if logger.isEnabledFor(logging.DEBUG): main(test_input) with capture_stderr(main, test_input) as output: self.assertTrue( "specified, which is required with a specified" in output)
def testMissingFileList(self): test_input = ["-l", " "] with capture_stdout(main, test_input) as output: self.assertTrue("show this help message" in output) with capture_stderr(main, test_input) as output: self.assertTrue( "Specified file listing cp2k force files missing" in output)
def testNoIni(self): test_input = [] with capture_stdout(main, test_input) as output: self.assertTrue("optional arguments:" in output) with capture_stderr(main, test_input) as output: self.assertTrue( "Problems reading file: Could not read file" in output)
def testInputFile(self): test_input = ["-c", MISS_KEY_INFO_INI, "-f", FITEVB_OUT] if logger.isEnabledFor(logging.DEBUG): main(test_input) with capture_stderr(main, test_input) as output: self.assertTrue( "expected comma-separated numerical lower range" in output)
def testNoArgs(self): test_input = [] if logger.isEnabledFor(logging.DEBUG): main(test_input) with capture_stderr(main, test_input) as output: # Error in looking for ini file self.assertTrue("Problems reading file" in output)
def testNotIni(self): # gracefully fail if give the wrong file to the -c option test_input = ["-c", NOT_INI] if logger.isEnabledFor(logging.DEBUG): main(test_input) with capture_stderr(main, test_input) as output: self.assertTrue("WARNING: File contains no section headers" in output)
def testSubsetCiInfo(self): with capture_stderr(main, ["-c", CI_SUBSET_INI]) as output: self.assertTrue("found no data from" in output) self.assertFalse(diff_lines(DEF_CI_SUBSET_OUT, GOOD_CI_SUBSET_OUT)) silent_remove(DEF_CI_SUBSET_OUT, disable=DISABLE_REMOVE) silent_remove(DEF_CI_OUT1, disable=DISABLE_REMOVE) silent_remove(DEF_CI_OUT2, disable=DISABLE_REMOVE)
def testWrongFileToFilter(self): # If put a configuration file as the file to read, fail well test_input = ["-f", DEF_INI, "-c", DEF_INI] if logger.isEnabledFor(logging.DEBUG): main(test_input) with capture_stderr(main, test_input) as output: self.assertTrue("could not convert string" in output)
def testNoArgs(self): with capture_stderr(main, []) as output: self.assertTrue( "WARNING: Problems reading file: Could not read file" in output) with capture_stdout(main, []) as output: self.assertTrue("optional arguments" in output)
def testNoSpecifiedPairFile(self): test_input = ["-f", DUMP_PATH] if logger.isEnabledFor(logging.DEBUG): main(test_input) with capture_stderr(main, test_input) as output: self.assertTrue( "No pair file specified and did not find" in output)
def testTplKeyInMain(self): # aim for a helpful message if the template key is in main test_input = ["-c", TPL_KEY_IN_MAIN_INI] if logger.isEnabledFor(logging.DEBUG): main(test_input) with capture_stderr(main, test_input) as output: self.assertTrue('Unexpected key' in output)
def testDefInpWithBadBuffer(self): bad_buffer = 'xyz' with capture_stderr(main, ["-f", DEF_INPUT, "-b", bad_buffer]) as output: self.assertTrue( 'WARNING: Problems reading data: Input for buffer ({}) could not be converted to ' 'a float.'.format(bad_buffer) in output)
def testBasinHopNonFloatMax(self): # test catching min greater than max test_input = ["-c", CONV_HOP_NONFLOAT_MAX_INI] if logger.isEnabledFor(logging.DEBUG): main(test_input) with capture_stderr(main, test_input) as output: self.assertTrue("could not convert string" in output)
def testBasinHopMaxMin(self): # test catching min greater than max test_input = ["-c", CONV_HOP_MAX_MIN_INI] if logger.isEnabledFor(logging.DEBUG): main(test_input) with capture_stderr(main, test_input) as output: self.assertTrue("is not less than" in output)
def testExtraSection(self): # catch an error if the program finds an unexpected section test_input = ["-c", EXTRA_SEC_INI] if logger.isEnabledFor(logging.DEBUG): main(test_input) with capture_stderr(main, test_input) as output: self.assertTrue('not one of the valid section names' in output)
def testMissingTplKey(self): # make sure it gracefully fails when a template key is missing test_input = ["-c", MISSING_TPL_KEY_INI] if logger.isEnabledFor(logging.DEBUG): main(test_input) with capture_stderr(main, test_input) as output: self.assertTrue('required for template file' in output)
def testWrongGluNumAtoms(self): test_input = ["-f", GLU_FILE, "-n", NOT_GLU_ATOM_NUM] if logger.isEnabledFor(logging.DEBUG): main(test_input) with capture_stderr(main, test_input) as output: self.assertTrue(NOT_GLU_ATOM_NUM in output) self.assertTrue(GLU_ATOM_NUM in output)
def testValBeforeSection(self): # make sure it gracefully fails when a template key is missing test_input = ["-c", VAL_BEFORE_SECTION_INI] if logger.isEnabledFor(logging.DEBUG): main(test_input) with capture_stderr(main, test_input) as output: self.assertTrue('must start with' in output)
def testFindNoWatH(self): test_input = ["-c", WRONG_WAT_H_TYPE_INI] if logger.isEnabledFor(logging.DEBUG): main(test_input) with capture_stderr(main, test_input) as output: self.assertTrue(WAT_H_TYPE in output) self.assertTrue("no such atoms were found" in output)
def testNoSuchOption(self): # main(["-@", DEF_OUT]) with capture_stderr(main, ["-@", DEF_OUT]) as output: self.assertTrue("unrecognized argument" in output) self.assertTrue(DEF_OUT in output) with capture_stdout(main, ["-@", DEF_OUT]) as output: self.assertTrue("optional arguments" in output)
def testSubsetCiInfo(self): with capture_stderr(main, ["-c", CI_SUBSET_INI]) as output: self.assertTrue("found no data from" in output) self.assertFalse(diff_lines(DEF_CI_SUBSET_OUT, GOOD_CI_SUBSET_OUT)) silent_remove(DEF_CI_SUBSET_OUT) silent_remove(DEF_CI_OUT1) silent_remove(DEF_CI_OUT2)
def testTplDumpMismatch(self): try: with capture_stderr(evbdump2data.main, ["-c", TPL_DUMP_MISMATCH_INI]) as output: self.assertTrue("listed number of atoms (214084) does not equal the number of atoms in the " "template data file (1429)" in output) finally: silent_remove(REPROD_TPL)
def testMissingFilledTplName(self): # new file name not specified by either config file or command line test_input = ["-c", PAR_NO_NEW_FILE_NAME_INI] if logger.isEnabledFor(logging.DEBUG): main(test_input) with capture_stderr(main, test_input) as output: self.assertTrue(FILLED_TPL_FNAME in output)
def testMissingMain(self): # make sure it gracefully fails when a template key is missing test_input = ["-c", MISSING_MAIN_INI] if logger.isEnabledFor(logging.DEBUG): main(test_input) with capture_stderr(main, test_input) as output: self.assertTrue("missing the required 'main' section" in output)
def testBinTooMany(self): test_input = ["-f", DEF_INPUT, "-c", BIN_TOO_MANY_INI] if logger.isEnabledFor(logging.DEBUG): main(test_input) with capture_stderr(main, test_input) as output: self.assertTrue("Expected a comma-separated list of length 3 or 4 for section 'bin_settings' key 'cv'. " "Read: 0.5,0.7,2,6,10" in output)
def testIncompDump(self): try: with capture_stderr(main, ["-c", INCOMP_DUMP_INI_PATH]) as output: self.assertTrue("WARNING" in output) self.assertFalse(diff_lines(DEF_GOFR_INCOMP_OUT, GOOD_HO_GOFR_OUT_PATH)) finally: silent_remove(DEF_GOFR_INCOMP_OUT, disable=DISABLE_REMOVE)
def testNoArgs(self): test_input = [] if logger.isEnabledFor(logging.DEBUG): main(test_input) with capture_stderr(main, test_input) as output: self.assertTrue("Could not read file" in output) with capture_stdout(main, test_input) as output: self.assertTrue("optional arguments" in output)
def testNoArgs(self): test_input = [] if logger.isEnabledFor(logging.DEBUG): main(test_input) with capture_stdout(main, test_input) as output: self.assertTrue("arguments:" in output) with capture_stderr(main, test_input) as output: self.assertTrue("required" in output)
def testBadInput(self): # Test what happens when cannot convert a value to float try: with capture_stderr(main, ["-f", BAD_INPUT]) as output: self.assertTrue("could not be converted to a float" in output) self.assertFalse(diff_lines(BAD_INPUT_OUT, GOOD_BAD_INPUT_OUT)) finally: silent_remove(BAD_INPUT_OUT, disable=DISABLE_REMOVE)
def testCompDihAlt(self): # Test it is okay with sections in the 1st but not 2nd file with capture_stderr(main, ["-c", COMP_DIH_ALT_INI]) as output: self.assertTrue("WARNING: Skipping section" in output) try: self.assertFalse(diff_lines(COMP_DIH_ALT_OUT, COMP_DIH_ALT_OUT_GOOD)) finally: silent_remove(COMP_DIH_ALT_OUT, disable=DISABLE_REMOVE)
def testParseError(self): # This input has a line with only "z" (no equals), resulting in a parsing error we will catch test_input = ["-f", DEF_INPUT, "-c", PARSE_ERROR_INI] if logger.isEnabledFor(logging.DEBUG): main(test_input) with capture_stderr(main, test_input) as output: self.assertTrue("File contains parsing errors" in output) self.assertTrue("'z" in output)
def testMissingInfo(self): test_input = ["-c", INCOMP_INI] if logger.isEnabledFor(logging.DEBUG): main(test_input) with capture_stderr(main, test_input) as output: self.assertTrue("Missing config val for key 'prot_res_mol_id'" in output) with capture_stdout(main, test_input) as output: self.assertTrue("optional arguments" in output)
def testDupCol(self): test_input = ["-f", DUP_COL_CMP_LIST] if logger.isEnabledFor(logging.DEBUG): main(test_input) with capture_stderr(main, test_input) as output: self.assertFalse(diff_lines(DEF_OUT, GOOD_OUT)) self.assertTrue("Non-unique column" in output) silent_remove(DEF_OUT, disable=DISABLE_REMOVE)
def testNoIni(self): test_input = [] if logger.isEnabledFor(logging.DEBUG): main(test_input) with capture_stdout(main, test_input) as output: self.assertTrue("usage:" in output) with capture_stderr(main, test_input) as output: self.assertTrue("Problems reading file: Could not read file" in output)
def testAddNothing(self): # this first test does not really doing anything, and warns the user try: with capture_stderr(main, [INPUT_PATH]) as output: self.assertTrue("Return file will be the same as the input" in output) self.assertFalse(diff_lines(INPUT_PATH, DEF_OUT_PATH)) finally: silent_remove(DEF_OUT_PATH)
def testNotIni(self): # gracefully fail if give the wrong file to the -c option test_input = ["-c", NOT_INI] if logger.isEnabledFor(logging.DEBUG): main(test_input) with capture_stderr(main, test_input) as output: self.assertTrue( "WARNING: File contains no section headers" in output)
def testGluBadDump(self): # main(["-c", GLU_BAD_DATA_INI]) try: with capture_stderr(main, ["-c", GLU_BAD_DATA_INI]) as output: self.assertTrue("Problems reading data: Unexpected line in file tests/test_data/evbd2d/glu_bad.dump: " "ITEM: XYZ MS id mol type q x y z" in output) finally: silent_remove(REPROD_TPL)
def testParseError(self): # This input has a line without equals), resulting in a parsing error we will catch test_input = ["-f", DEF_INPUT, "-c", PARSE_ERROR_INI] if logger.isEnabledFor(logging.DEBUG): main(test_input) with capture_stderr(main, test_input) as output: self.assertTrue("parsing errors" in output) self.assertTrue("'col2" in output)
def testHelp(self): test_input = ['-h'] if logger.isEnabledFor(logging.DEBUG): main(test_input) with capture_stderr(main, test_input) as output: self.assertFalse(output) with capture_stdout(main, test_input) as output: self.assertTrue("optional arguments" in output)
def testIncompDump(self): try: with capture_stderr(main, ["-c", INCOMP_DUMP_INI_PATH]) as output: self.assertTrue("WARNING" in output) self.assertFalse( diff_lines(DEF_GOFR_INCOMP_OUT, GOOD_HO_GOFR_OUT_PATH)) finally: silent_remove(DEF_GOFR_INCOMP_OUT, disable=DISABLE_REMOVE)
def testNoHydData(self): """ Because the types do not match the data file, did not find the molecules desired. """ evbdump2data.main(["-c", GLU_BAD_ATOM_TYPE_INI]) with capture_stderr(evbdump2data.main, ["-c", GLU_BAD_ATOM_TYPE_INI]) as output: self.assertTrue("Check the data file" in output) silent_remove(REPROD_TPL)
def testMissingConfig(self): test_input = ["-c", INCOMP_INI_PATH] if logger.isEnabledFor(logging.DEBUG): main(test_input) with capture_stderr(main, test_input) as output: self.assertTrue("Missing config val" in output) with capture_stdout(main, test_input) as output: self.assertTrue("optional arguments" in output)
def testInvalidData(self): test_input = ["-c", INVALID_INI] with capture_stderr(main, test_input) as output: self.assertTrue( "Problem with config vals on key h3o_o_type: invalid literal for int" in output) with capture_stdout(main, test_input) as output: self.assertTrue("optional arguments" in output)
def testMissingConfig(self): test_input = ["-c", INCOMP_INI_PATH] if logger.isEnabledFor(logging.DEBUG): main(test_input) with capture_stderr(main, test_input) as output: self.assertTrue("Missing config val for key 'water_o_type'" in output) with capture_stdout(main, test_input) as output: self.assertTrue("optional arguments" in output)
def testAddElemReadDict(self): # There will be a missing element because of a missing key in the specified dictionary try: # main(["-c", READ_ELEM_DICT_INI]) with capture_stderr(main, ["-c", READ_ELEM_DICT_INI]) as output: self.assertTrue("Please add atom type" in output) self.assertFalse(diff_lines(ADD_ELEMENT_OUT, GOOD_READ_ELEM_OUT)) finally: silent_remove(ADD_ELEMENT_OUT)
def testCheckWaterOrder(self): try: # main(["-c", CHECK_WATER_ORDER_INI]) with capture_stderr(main, ["-c", CHECK_WATER_ORDER_INI]) as output: for message in WATER_OUT_OF_ORDER_MESSAGES: self.assertTrue(message in output) self.assertLess(len(output), 650) finally: silent_remove(DEF_OUT)
def testAddElemReadDictNoOverwrite(self): # Make sure preserves the element from the original pdb even though not in the read dict try: # main(["-c", READ_ELEM_DICT_KEEP_ELEM_INI]) with capture_stderr(main, ["-c", READ_ELEM_DICT_KEEP_ELEM_INI]) as output: self.assertTrue("Please add atom type" in output) self.assertFalse(diff_lines(DEF_OUT, GOOD_ADD_ELEMENT_OUT)) finally: silent_remove(DEF_OUT)
def testMixedInput(self): """ This input file has tuples and lists that cannot be handled by np.loadtxt """ try: with capture_stderr(main, ["-f", MIXED_INPUT, "-n", "-d", ","]) as output: self.assertTrue("could not be converted to a float" in output) self.assertFalse(diff_lines(MIXED_OUT, GOOD_MIXED_OUT)) finally: silent_remove(MIXED_OUT, disable=DISABLE_REMOVE)
def testTypoIni(self): # If a section name is encountered and not expected, flag it test_input = ["-f", DEF_INPUT, "-c", TYPO_INI] try: with capture_stderr(main, test_input) as output: self.assertTrue("Found section 'min', which will be ignored" in output) self.assertTrue("No filtering will be applied" in output) self.assertFalse(diff_lines(CSV_OUT, DEF_INPUT)) finally: silent_remove(CSV_OUT, disable=DISABLE_REMOVE)
def testAllNanInput(self): """ This input file has only tuples and lists """ try: with capture_stderr(main, ["-f", ALL_NAN_INPUT, "-n", "-d", ","]) as output: self.assertTrue("could not be converted to a float" in output) self.assertFalse(diff_lines(ALL_NAN_OUT, GOOD_ALL_NAN_OUT)) finally: silent_remove(ALL_NAN_OUT, logger.isEnabledFor(logging.DEBUG))
def testHIJAlt(self): try: test_input = ["-c", HIJ_ALT_INI] if logger.isEnabledFor(logging.DEBUG): main(test_input) with capture_stderr(main, test_input) as output: self.assertTrue("did not have the full list of atom numbers" in output) self.assertFalse(diff_lines(HIJ_ALT_OUT, GOOD_HIJ_ALT_OUT)) finally: silent_remove(HIJ_ALT_OUT, disable=DISABLE_REMOVE)
def testAddElementsMissingType(self): try: # main(["-c", ADD_ELEMENT_MISSING_TYPE_INI]) with capture_stderr(main, ["-c", ADD_ELEMENT_MISSING_TYPE_INI]) as output: # testing that only get the warning once, so check output length. May change wording a bit, # so checked than less than length + a buffer (which is less than if multiple warnings are printed) self.assertLess(len(output), 200) self.assertTrue("Please add atom type" in output) self.assertFalse(diff_lines(ADD_ELEMENT_MISSING_OUT, ADD_ELEMENT_MISSING_ORIG)) finally: silent_remove(ADD_ELEMENT_MISSING_OUT)
def testMissingRadius(self): # Tests both providing a dictionary and not having an available radius (still prints everything, just missing # one radius) try: with capture_stderr(main, ["-c", MISSING_RADIUS_INI]) as output: self.assertTrue("Did not find atom type 'XYZ' in the atom_type to radius dictionary" in output) self.assertFalse(diff_lines(QMMM_OUT, GOOD_QMMM_OUT)) self.assertEqual(3, len(diff_lines(MM_KIND_OUT, GOOD_MM_KIND_OUT))) self.assertFalse(diff_lines(VMD_ATOMS_OUT, GOOD_VMD_ATOMS_OUT)) finally: silent_remove(QMMM_OUT) silent_remove(MM_KIND_OUT) silent_remove(VMD_ATOMS_OUT)
def testDefineTS(self): """ In addition to testing the case where a TS location is defined, tests for overwriting file warning """ try: main([str(EXP_TEMP), "-f", GOOD_RAD_PATH, "-o", "-c", "2.4"]) self.assertFalse(diff_lines(DEF_FILE_OUT, GOOD_TS_OUT)) # main([str(EXP_TEMP), "-f", GOOD_RAD_PATH, "-c", "2.4"]) # with capture_stdout(main, [str(EXP_TEMP), "-f", GOOD_RAD_PATH, "-c", "2.4"]) as output: # print("output out", output) with capture_stderr(main, [str(EXP_TEMP), "-f", GOOD_RAD_PATH, "-c", "2.4"]) as output: # print("output err", output) self.assertTrue("Not overwriting existing file" in output) finally: silent_remove(DEF_FILE_OUT)