def test_defaults(self): args = argument_utils.parse_args(parse_args=False) self.assertEqual(args.mode, defaults.MODE) self.assertEqual(args.filenames, defaults.FILENAME) self.assertEqual(args.featurize_type, defaults.FEATURIZE_TYPE) self.assertEqual(args.models, defaults.MODELS) self.assertEqual(args.test_nums, defaults.TEST_NUMS) self.assertEqual(args.test_intersections, defaults.TEST_INTERSECTIONS)
def test_flags(self): flag_shorthand_arglist = ["evaluate", "-d", "-s", "-q", "-l", "-x"] args = argument_utils.parse_args(parse_args=False, arglist=flag_shorthand_arglist) self.assertTrue(args.make_distance_histograms) self.assertTrue(args.save_scores) self.assertTrue(args.quiet_eval) self.assertTrue(args.load_scores) self.assertTrue(args.excel) flag_longhand_arglist = [ "evaluate", "--make_distance_histograms", "--save_scores", "--quiet_eval", "--load_scores", "--excel" ] args = argument_utils.parse_args(parse_args=False, arglist=flag_longhand_arglist) self.assertTrue(args.make_distance_histograms) self.assertTrue(args.save_scores) self.assertTrue(args.quiet_eval) self.assertTrue(args.load_scores) self.assertTrue(args.excel)
def test_non_defaults(self): mode = "evaluate" filename = "testfile.txt" featurize = "n" models = "lstm1" testnums = "000,001,111" test_intersections = "1,2,3,4" nondefault_arglist = [ mode, "--filenames", filename, "--featurize", featurize, "--models", models, "--test_nums", testnums, "--test_intersections", test_intersections ] args = argument_utils.parse_args(parse_args=False, arglist=nondefault_arglist) self.assertEqual(args.mode, mode) self.assertEqual(args.filenames, [filename]) self.assertEqual(args.featurize_type, featurize) self.assertEqual(args.models, models) self.assertEqual(args.test_nums, testnums) self.assertEqual(args.test_intersections, test_intersections)
def test_multiple_filenames(self): args = argument_utils.parse_args( parse_args=False, arglist=["a", "--filenames", "testfile1.txt", "testfile2.txt"]) self.assertEqual(args.filenames, ["testfile1.txt", "testfile2.txt"])
def test_program_full_stack(self): # testing combine and augment together because order matters. # augment depends on combine. peachtree, lankershim = program.main( argument_utils.parse_args(False, ["c"])) os.remove(peachtree) os.remove(lankershim) peachtree, lankershim = program.main( argument_utils.parse_args(False, ["c"])) self.assertTrue(os.path.exists(peachtree)) self.assertTrue(os.path.exists(lankershim)) # done with combine program.main( argument_utils.parse_args(False, [ "a", "--filenames", "trajectories-peachtree.txt", "trajectories-lankershim.txt" ])) self.assertTrue( os.path.exists( os.path.join(constants.PATH_TO_RESOURCES, "Peachtree", "AUGv2_trajectories-peachtree.txt"))) self.assertTrue( os.path.exists( os.path.join(constants.PATH_TO_RESOURCES, "Lankershim", "AUGv2_trajectories-lankershim.txt"))) # done with augment program.main( argument_utils.parse_args( False, ["f", "--featurize_type", "i", "--test_nums", "000"])) for intersection in range(1, 10): path_to_features_for_intersection = os.path.join( constants.PATH_TO_RESULTS, "ByIntersection", "000", str(intersection)) self.assertTrue(os.path.exists(path_to_features_for_intersection)) self.assertTrue( os.path.exists( os.path.join(path_to_features_for_intersection, "featuresAndTargets"))) self.assertTrue( os.path.exists( os.path.join(path_to_features_for_intersection, "LSTM_Formatted_featuresAndTargets.npy"))) # done with featureizing program.main( argument_utils.parse_args(False, [ "t", "--models", "test", "--test_nums", "000", "--test_intersections", "1" ])) # done training some models program.main( argument_utils.parse_args(False, [ "e", "--models", "test", "--test_nums", "000", "--test_intersections", "1" ]))
#argv[6] == s (save), 0 (dont save) - UNUSED, save all model_arg = arguments.models models = argument_utils.model_choices[model_arg] testtypes = arguments.test_nums.split(",") str_inters = arguments.test_intersections.split(",") saving = True # TODO arg? for test_inters in str_inters: list_test = [int(i) for i in test_inters] train_inters = sorted( list(set([1, 2, 3, 4, 5, 6, 7, 8, 9]) - set(list_test))) print("test inters:", list_test) print("train inters:", train_inters) intersections = ([int(i) for i in test_inters], [int(i) for i in train_inters]) new_train_and_test(models, testtypes, intersections, saving, False, exper=True) else: print( "invalid argument:", arguments.mode, "options are a - augment, f - featurize, tr - train, te - test, t - train and test" ) if __name__ == "__main__": main(argument_utils.parse_args())