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 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 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 testBinMax2(self): # In this input, both bins have more than the max entries test_input = ["-f", BIN_INPUT, "-c", BIN_MAX2_INI] try: main(test_input) self.assertFalse(diff_lines(DEF_BIN_OUT, GOOD_BIN_MAX2_OUT)) finally: silent_remove(DEF_BIN_OUT, disable=DISABLE_REMOVE)
def testBinMax(self): # In this input, one big has more than the max and one less test_input = ["-f", BIN_INPUT, "-c", BIN_MAX_INI] try: main(test_input) # self.assertFalse(diff_lines(DEF_BIN_OUT, GOOD_BIN_MAX_OUT)) finally: silent_remove(DEF_BIN_OUT, disable=DISABLE_REMOVE)
def testNoMinNonFloat(self): # Tests both handling when no min section is specified and non-floats in the file to be analyzed test_input = ["-f", NON_FLOAT_INPUT, "-c", NO_MIN_INI] try: main(test_input) self.assertFalse(diff_lines(NON_FLOAT_OUT, GOOD_NON_FLOAT_OUT)) finally: silent_remove(NON_FLOAT_OUT)
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 testBin(self): test_input = ["-f", BIN_INPUT, "-c", BIN_INI] if logger.isEnabledFor(logging.DEBUG): main(test_input) try: with capture_stdout(main, test_input) as output: self.assertTrue("Keeping 14 of 16 rows based on filtering criteria" in output) self.assertFalse(diff_lines(DEF_BIN_OUT, GOOD_BIN_OUT)) finally: silent_remove(DEF_BIN_OUT, disable=DISABLE_REMOVE)
def testDupKey(self): # Checking what happens if the key is listed twice. Expect the program to use the last # key value. In this case, it results in no rows that meet the criteria test_input = ["-f", DEF_INPUT, "-c", DUP_KEY_INI] try: if logger.isEnabledFor(logging.DEBUG): main(test_input) with capture_stdout(main, test_input) as output: self.assertTrue("Keeping 0 of 4 rows based on filtering criteria" in output) self.assertFalse(diff_lines(CSV_OUT, GOOD_CSV_NONE_KEPT)) finally: silent_remove(CSV_OUT, disable=DISABLE_REMOVE)
def testInvalidKey(self): test_input = ["-f", DEF_INPUT, "-c", INVALID_KEY_INI] if logger.isEnabledFor(logging.DEBUG): main(test_input) with capture_stderr(main, test_input) as output: self.assertTrue("Unexpected key" in output)
def testNoSuchFile(self): test_input = ["-f", "ghost.csv", "-c", DEF_INI] if logger.isEnabledFor(logging.DEBUG): main(test_input) with capture_stderr(main, test_input) as output: self.assertTrue("Problems reading file" in output)
def testBinNonInt(self): test_input = ["-f", DEF_INPUT, "-c", BIN_NONINT_INI] if logger.isEnabledFor(logging.DEBUG): main(test_input) with capture_stderr(main, test_input) as output: self.assertTrue("could not convert '0.2' to" in output)
def testBinNegInt(self): test_input = ["-f", DEF_INPUT, "-c", BIN_NEG_INT_INI] if logger.isEnabledFor(logging.DEBUG): main(test_input) with capture_stderr(main, test_input) as output: self.assertTrue("positive integers are required" in output)
def testNonfloatKeyValue(self): test_input = ["-f", DEF_INPUT, "-c", NONFLOAT_KEY_INI] if logger.isEnabledFor(logging.DEBUG): main(test_input) with capture_stderr(main, test_input) as output: self.assertTrue("For section 'min_vals' key 'z', could not convert value '' to a float" in output)