def test_main(self): args_list = ["-d", "vert", "-if", "my_fake_file"] args = cg.build_parser().parse_args(args_list) logger.debug( "unhappy path - input file list only contains 1 entry - args: {}". format(args)) cg.main(args) args_list[2] = "--file_wildcard" args_list[3] = "not_going_to_find_this_file_3874873784378389" args = cg.build_parser().parse_args(args_list) logger.debug( "unhappy path - file_wildcard does not match any files - args: {}" .format(args)) with self.assertRaises(Exception) as context: cg.main(args) self.assertIsNotNone(context.exception) logger.debug("context.exception: {}".format(context.exception)) self.assertIn("No files were found", str(context.exception), "the expected exception was not thrown") args_list[ 3] = "functional_tests/test_concat_gctoo_test_main_fake_empty_file.gct" args = cg.build_parser().parse_args(args_list) logger.debug( "unhappy path - file_wildcard matches just 1 file - args: {}". format(args)) cg.main(args)
def test_main(self): test_dir = "functional_tests/test_concat_gctoo/test_main" g_a = pg.parse(os.path.join(test_dir, "a.gct")) logger.debug("g_a: {}".format(g_a)) g_b = pg.parse(os.path.join(test_dir, "b.gct")) logger.debug("g_b: {}".format(g_b)) save_build_parser = cg.build_parser class MockParser: def __init__(self, args): self.args = args def parse_args(self, unused): return self.args #unhappy path - write out error report file expected_output_file = tempfile.mkstemp()[1] logger.debug( "unhappy path - write out error report file - expected_output_file: {}" .format(expected_output_file)) args = save_build_parser().parse_args([ "-d", "horiz", "-if", g_a.src, g_b.src, "-o", "should_not_be_used", "-ot", "gct", "-erof", expected_output_file ]) logger.debug("args: {}".format(args)) my_mock_parser = MockParser(args) cg.build_parser = lambda: my_mock_parser with self.assertRaises( cg.MismatchCommonMetadataConcatGctooException) as context: cg.main() self.assertTrue(os.path.exists(expected_output_file)) report_df = pd.read_csv(expected_output_file, sep="\t") logger.debug("report_df:\n{}".format(report_df)) self.assertEqual(2, report_df.shape[0]) os.remove(expected_output_file) print() print() print() #happy path args.remove_all_metadata_fields = True args.error_report_output_file = None expected_output_file = tempfile.mkstemp(suffix=".gct")[1] logger.debug("happy path - expected_output_file: {}".format( expected_output_file)) args.out_name = expected_output_file my_mock_parser = MockParser(args) cg.buid_parser = lambda: my_mock_parser cg.main() self.assertTrue(os.path.exists(expected_output_file)) r = pg.parse(expected_output_file) logger.debug("happy path -r:\n{}".format(r)) logger.debug("r.data_df:\n{}".format(r.data_df)) self.assertEqual((2, 4), r.data_df.shape) self.assertEqual({"a", "b", "g", "f"}, set(r.data_df.columns)) self.assertEqual({"rid1", "rid2"}, set(r.data_df.index)) #cleanup os.remove(expected_output_file) cg.build_parser = save_build_parser