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 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 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 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 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 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 testMakeParCommandLine(self): # as in testMakePar, but specifying the created file name from the command line try: silent_remove(PAR_OUT) main(["-c", PAR_NO_NEW_FILE_NAME_INI, "-f", PAR_FNAME]) self.assertFalse(diff_lines(PAR_OUT, GOOD_PAR_OUT)) finally: silent_remove(PAR_OUT, disable=DISABLE_REMOVE)
def testMakePar(self): # For this test, there is exactly one value provided for each parameter try: silent_remove(PAR_OUT) main(["-c", PAR_INI]) self.assertFalse(diff_lines(PAR_OUT, GOOD_PAR_OUT)) finally: silent_remove(PAR_OUT, disable=DISABLE_REMOVE)
def testMakeEqPar(self): try: for o_file in MULTI_OUT_FILES: silent_remove(o_file) main(["-c", PAR_EQ_INI]) self.assertFalse(diff_lines(MULTI_PAR_OUT1, GOOD_MULTI_PAR_OUT1)) self.assertFalse(diff_lines(MULTI_PAR_OUT2, GOOD_PAR_OUT)) self.assertFalse(diff_lines(MULTI_PAR_OUT3, GOOD_MULTI_PAR_OUT3)) finally: for o_file in MULTI_OUT_FILES: silent_remove(o_file, disable=DISABLE_REMOVE)
def testMakeOneMultiPar(self): # Now, one parameter has multiple values try: for o_file in MULTI_OUT_FILES: silent_remove(o_file) main(["-c", PAR_ONE_MULTI_INI]) self.assertFalse(diff_lines(MULTI_PAR_OUT1, GOOD_MULTI_PAR_OUT1)) self.assertFalse(diff_lines(MULTI_PAR_OUT2, GOOD_PAR_OUT)) self.assertFalse(diff_lines(MULTI_PAR_OUT3, GOOD_MULTI_PAR_OUT3)) finally: for o_file in MULTI_OUT_FILES: silent_remove(o_file, disable=DISABLE_REMOVE)
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 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)