def test_run_with_no_args(self): """ Trigger an error by attempting to run the program with no arguments. :return: """ args = [] if logger.isEnabledFor(logging.DEBUG): gen_mileage_stats.main(args) with capture_stderr(gen_mileage_stats.main, args) as output: self.assertTrue( "You did not specify an Excel input file." in output)
def test_normal_use_case(self): """ Normal use case in which the user provides correct minimal input. :return: """ args = ['-i', SAMPLE_DATA_FILE, '-b', '-H'] if logger.isEnabledFor(logging.DEBUG): gen_mileage_stats.main(args) with capture_stdout(gen_mileage_stats.main, args) as output: self.assertTrue("Mean Mileage" in output)
def test_run_html_but_no_plots(self): """ Test by running the -P option only to see if the program warns the user to unsuppress plot generation. :return: """ args = ['-i', SAMPLE_DATA_FILE, '-P'] if logger.isEnabledFor(logging.DEBUG): gen_mileage_stats.main(args) with capture_stderr(gen_mileage_stats.main, args) as output: self.assertTrue( "You must allow plots in order to generate HTML content" in output)
def test_pass_invalid_data_file(self): """ Trigger a AttributeError by passing a datafile that has text in one of the date cells. :return: """ args = [ "-i", os.path.join(TEST_DATA_DIR, 'test_data_invaliddata.xlsx'), '-H' ] if logger.isEnabledFor(logging.DEBUG): gen_mileage_stats.main(args) with capture_stderr(gen_mileage_stats.main, args) as output: self.assertTrue("Workbook contains invalid data" in output)
def test_pass_corrupt_file(self): """ Trigger a zlib.error by passing a file that is corrupt (eg., that can't be unzipped). :return: """ args = [ "-i", os.path.join(TEST_DATA_DIR, 'test_data_corrupted.xlsx'), '-H' ] if logger.isEnabledFor(logging.DEBUG): gen_mileage_stats.main(args) with capture_stderr(gen_mileage_stats.main, args) as output: self.assertTrue("Excel file appears to be corrupt." in output)
def test_pass_wrong_file_name(self): """ Trigger an FileNotFountError by passing an invalid path to the function :return: """ args = [ "-i", os.path.join(TEST_DATA_DIR, 'non-existent-file.xlsx'), '-H' ] if logger.isEnabledFor(logging.DEBUG): gen_mileage_stats.main(args) with capture_stderr(gen_mileage_stats.main, args) as output: self.assertTrue("Cannot find the input file" in output)
def test_run_with_pivot_tables(self): """ See if the program correctly outputs pivot tables to STDOUT :return: """ args = ['-i', SAMPLE_DATA_FILE, '-v', '-H'] if logger.isEnabledFor(logging.DEBUG): gen_mileage_stats.main(args) with capture_stdout(gen_mileage_stats.main, args) as output: self.assertTrue("50.970968" in output) # Specific value for this test file. self.assertTrue("56.922581" in output) self.assertTrue("Median Mileage" in output) self.assertTrue("Min Mileage" in output) self.assertTrue("==============" in output) # Correct formatting?
import gen_mileage_stats gen_mileage_stats.main( ["-i", r"..\tests\test_data\test_data.xlsx", "-b", "-p"])