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 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 testArrayWrongDelimiter(self): test_input = ["-f", VEC_INPUT] main(test_input) if logger.isEnabledFor(logging.DEBUG): main(test_input) with capture_stderr(main, test_input) as output: self.assertTrue("delimiter" in output)
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 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 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 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 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 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 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 testIncDimen(self): # Test what happens when the lines do not all have the same number of dimensions test_input = ["-f", BAD_INPUT2, "-d", ' '] if logger.isEnabledFor(logging.DEBUG): main(test_input) with capture_stderr(main, test_input) as output: self.assertTrue("Problems reading data" in output) self.assertTrue("3 values " in output) self.assertTrue("2 values" 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, DISABLE_REMOVE)
def testCheckWaterOrder(self): test_input = ["-c", CHECK_WATER_ORDER_INI] if logger.isEnabledFor(logging.DEBUG): main(test_input) try: with capture_stderr(main, test_input) 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, disable=DISABLE_REMOVE)
def testMixedInput(self): """ This input file has tuples and lists that cannot be handled by np.loadtxt """ test_input = ["-f", MIXED_INPUT, "-n", "-d", ","] try: with capture_stderr(main, test_input) 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 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 testAddElemReadDictNoOverwrite(self): # Make sure preserves the element from the original pdb even though not in the read dict test_input = ["-c", READ_ELEM_DICT_KEEP_ELEM_INI] try: silent_remove(DEF_OUT) if logger.isEnabledFor(logging.DEBUG): main(test_input) else: 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, disable=DISABLE_REMOVE)
def testAddElemReadDict(self): # There will be a missing element because of a missing key in the specified dictionary test_input = ["-c", READ_ELEM_DICT_INI] try: silent_remove(ADD_ELEMENT_OUT) if logger.isEnabledFor(logging.DEBUG): main(test_input) silent_remove(ADD_ELEMENT_OUT) with capture_stderr(main, test_input) 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, disable=DISABLE_REMOVE)
def testAddElementsMissingType(self): test_input = ["-c", ADD_ELEMENT_MISSING_TYPE_INI] try: if logger.isEnabledFor(logging.DEBUG): main(test_input) else: with capture_stderr(main, test_input) 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, disable=DISABLE_REMOVE)
def testBadInput(self): # Test what happens when cannot convert a value to float # Note: within Intellij, some values were not nan that were nan outside the environment # thus, I'm not checking the output for exactly no line differences try: test_input = ["-f", BAD_INPUT, '-d', ' '] if logger.isEnabledFor(logging.DEBUG): main(test_input) with capture_stderr(main, test_input) as output: self.assertTrue("could not be converted to a float" in output) self.assertLess( len(diff_lines(BAD_INPUT_OUT, GOOD_BAD_INPUT_OUT)), 7) finally: silent_remove(BAD_INPUT_OUT, disable=DISABLE_REMOVE)
def testMakeParEqMissingParam(self): test_input = ["-c", PAR_EQ_MISS_PARAM_INI] if logger.isEnabledFor(logging.DEBUG): main(test_input) with capture_stderr(main, test_input) as output: self.assertTrue('Missing parameter value' in output)
def testMakeParEqWrongOrder(self): test_input = ["-c", PAR_EQ_WRONG_ORDER_INI] if logger.isEnabledFor(logging.DEBUG): main(test_input) with capture_stderr(main, test_input) as output: self.assertTrue('Check order' in output)
def testMakeParMissingKeyFileName(self): test_input = ["-c", PAR_NO_NEW_FILE_NAME_INI, "-f", '{ghost}.par'] if logger.isEnabledFor(logging.DEBUG): main(test_input) with capture_stderr(main, test_input) as output: self.assertTrue('required for filled template file name' in output)
def testUnexpectedKey(self): # main(["-c", UNEXPECTED_KEY_INI]) with capture_stderr(main, ["-c", UNEXPECTED_KEY_INI]) as output: self.assertTrue("Unexpected key" in output)
def testRepeatKeyNumDict(self): # main(["-c", ATOM_DICT_REPEAT_INI]) with capture_stderr(main, ["-c", ATOM_DICT_REPEAT_INI]) as output: self.assertTrue("non-unique" in output)
def testReadBadAtomNumDict(self): # main(["-c", ATOM_DICT_BAD_INI]) with capture_stderr(main, ["-c", ATOM_DICT_BAD_INI]) as output: self.assertTrue("xx" in output) self.assertTrue("Problems with input" in output)
def testMissingTpl(self): test_input = ["-c", MISSING_TPL_INI] if logger.isEnabledFor(logging.DEBUG): main(test_input) with capture_stderr(main, test_input) as output: self.assertTrue("template file specified" in output)
def testMissingWord(self): test_input = ["-d", USER_DICT] if logger.isEnabledFor(logging.DEBUG): main(test_input) with capture_stderr(main, test_input) as output: self.assertTrue("new_word" in output)
def testVectorNotArray(self): test_input = ["-f", VEC_INPUT, "-d", ' '] if logger.isEnabledFor(logging.DEBUG): main(test_input) with capture_stderr(main, test_input) as output: self.assertTrue("File contains a vector" in output)
def testNoArgs(self): with capture_stderr(main, []) as output: self.assertTrue("Problems reading file" in output)
def testNoSuchOption(self): with capture_stderr(main, ["-@", DEF_INPUT]) as output: self.assertTrue("unrecognized argument" in output) self.assertTrue(DEF_INPUT in output)