def testSaveSmi(self): try: test_input = ["-r", "10", "-o", TEST_SMI_BASENAME, "-d", SUB_DATA_DIR, "-a", "1.0"] main(test_input) self.assertFalse(diff_lines(TEST_SMI_OUT, GOOD_TEST_SMI_OUT)) finally: silent_remove(TEST_SMI_OUT, disable=DISABLE_REMOVE) pass
def testHelp(self): test_input = ['-h'] # main(test_input) 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 testTCLGenOptions(self): try: test_input = ["-r", "8", "-i", "4", "-m", "4", "-f", "tcl", "-d", SUB_DATA_DIR, "--chain_id", "1", "--psf_fname", "birch", "--toppar_dir", "", "-a", "1.0", "-x"] main(test_input) self.assertFalse(diff_lines(DEF_TCL_OUT, GOOD_TCL_OPTIONS_OUT)) finally: silent_remove(DEF_TCL_OUT, disable=DISABLE_REMOVE) pass
def testDirInBasename(self): # This should ignore the temp_dir; will throw error if it doesn't try: test_input = ["-r", "10", "-o", TEST_SMI_OUT, "-d", TEMP_DIR, "-a", "1.0"] main(test_input) self.assertFalse(diff_lines(TEST_SMI_OUT, GOOD_TEST_SMI_OUT)) finally: silent_remove(TEST_SMI_OUT, disable=DISABLE_REMOVE) pass
def testBadConfigFile(self): test_input = ["-c", "ghost.ini"] # main(test_input) if logger.isEnabledFor(logging.DEBUG): main(test_input) with capture_stderr(main, test_input) as output: self.assertTrue("Could not find specified configuration file" in output) with capture_stdout(main, test_input) as output: self.assertTrue("optional arguments" in output)
def testUnrecognizedArg(self): test_input = ['-@'] # main(test_input) if logger.isEnabledFor(logging.DEBUG): main(test_input) with capture_stderr(main, test_input) as output: self.assertTrue("unrecognized argument" in output) with capture_stdout(main, test_input) as output: self.assertTrue("optional arguments" in output)
def testSaveJSON(self): try: silent_remove(DEF_JSON_OUT) test_input = ["-r", "10", "-f", "json", "-d", SUB_DATA_DIR, "-a", "1.0"] main(test_input) with open(DEF_JSON_OUT, "r") as f: json_str = f.readlines() self.assertTrue(GOOD_JSON_PARTS[0] in json_str[0]) finally: silent_remove(DEF_JSON_OUT, disable=DISABLE_REMOVE)
def testMakeSubDir(self): try: test_input = ["-r", "10", "-d", TEMP_DIR, "-o", TEST_SMI_BASENAME, "-a", "1.0"] main(test_input) self.assertFalse(diff_lines(TEST_SMI_OUT_TEMP_DIR, GOOD_TEST_SMI_OUT)) finally: silent_remove(TEST_SMI_OUT_TEMP_DIR, disable=DISABLE_REMOVE) silent_remove(TEMP_DIR, dir_with_files=True, disable=DISABLE_REMOVE) silent_remove(INNER_TEMP_DIR, disable=DISABLE_REMOVE) pass
def testSavePNGSVGNewSize(self): # Smoke test only (not comparing images) try: test_input = ["-r", "10", "-f", "png, svg", "-d", SUB_DATA_DIR, "-s", "(900, 900)"] main(test_input) self.assertTrue(os.path.isfile(DEF_PNG_OUT)) self.assertTrue(os.path.isfile(DEF_SVG_OUT)) finally: silent_remove(DEF_PNG_OUT, disable=DISABLE_REMOVE) silent_remove(DEF_SVG_OUT, disable=DISABLE_REMOVE) pass
def testSaveJSONPathInOutName(self): try: silent_remove(DEF_JSON_OUT) test_input = ["-r", "10", "-f", "json", "-o", DEF_JSON_OUT, "-a", "1.0"] main(test_input) with open(DEF_JSON_OUT, "r") as f: json_str = f.readlines() for json_part in GOOD_JSON_PARTS: self.assertTrue(json_part in json_str[0]) finally: silent_remove(DEF_JSON_OUT, disable=DISABLE_REMOVE) pass
def testSavePNGSVG(self): # Smoke test only (not comparing images) try: silent_remove(DEF_PNG_OUT) silent_remove(DEF_SVG_OUT) test_input = ["-r", "10", "-f", "svg", "-o", DEF_BASENAME + '.png', "-d", SUB_DATA_DIR, "-m", "6", "-s", "900 900"] main(test_input) self.assertTrue(os.path.isfile(DEF_PNG_OUT)) self.assertTrue(os.path.isfile(DEF_SVG_OUT)) finally: silent_remove(DEF_PNG_OUT, disable=DISABLE_REMOVE) silent_remove(DEF_SVG_OUT, disable=DISABLE_REMOVE)
def testSGPlot3(self): # also has multiple sg_ratio; smoke test only (that files are created, but not testing content expected_files = [PLOT_BOND_V_SG6_PNG, PLOT_BOND_V_SG8_PNG] try: for fname in expected_files: silent_remove(fname) test_input = ["-r", "6", "-i", "8", "-m", "16", "-a", "1e8, 1e6", "-sg", "5,10", "-n", "3", "-p", "-d", PLOT_DIR, "-x"] main(test_input) for fname in expected_files: self.assertTrue(os.path.isfile(fname)) finally: silent_remove(TEMP_DIR, dir_with_files=True, disable=DISABLE_REMOVE) pass
def testSaveJSONCommaPNG(self): # Smoke test on png with default image size try: silent_remove(DEF_PNG_OUT) silent_remove(DEF_JSON_OUT) test_input = ["-r", "10", "-f", "json, png", "-d", SUB_DATA_DIR, "-a", "1.0"] main(test_input) self.assertTrue(os.path.isfile(DEF_PNG_OUT)) with open(DEF_JSON_OUT, "r") as f: json_str = f.readlines() self.assertTrue(GOOD_JSON_PARTS[0] in json_str[0]) finally: silent_remove(DEF_PNG_OUT, disable=DISABLE_REMOVE) silent_remove(DEF_JSON_OUT, disable=DISABLE_REMOVE) pass