Exemplo n.º 1
0
def test_generator():
    def _execute(function, fold, expected):
        result = function(fold)
        print "Expected: {}".format(expected)
        print "Got     : {}".format(result)
        assert result == expected

    test_inputs = glob("test/gengraph/*.parse_ct")
    test_gengraph_outputs = glob("test/gengraph/*.gengraph")
    test_find_shortest_path_outputs = glob("test/gengraph/*.find_shortest_path")
    if len(test_gengraph_outputs + test_find_shortest_path_outputs) == 0:
        # The outputs of this test are long-winded,
        # if necessary the outputs can be regenerated from the 
        # functions under test, so use wisely!
        # The inputs are static and match the output of parse_ct which 
        # shouldn't be changing anytime soon
        for test in test_inputs:
            (testname, testext) = os.path.splitext(test)
            with open("test/gengraph/" + test) as parsefile:
                parsed = pickle.load(parse_file)
                # Generate the graph test outputs
                with open("test/gengraph/{}.gengraph".format(testname), w) as f:
                    case = distance.gengraph(parsed)
                    pickle.store(case)
                with open("test/gengraph/{}.find_shortest_path".format(testname), w) as f:
                    pathcase = distance.find_shortest_path(case)
                    pickle.store(pathcase)

    for (function, test) in itertools.product([distance.gen_graph, distance.find_shortest_path], test_inputs):
        try:
            expected_file = open("test/gengraph/" + test)
            expected = pickle.load(expected_file)
            expected_file.close()
        except IOError:
            sys.stderr.write("gengraph2_test_generator(): could not open file %s" % "test/gengraph/" + test)
            assert False

        yield _gengraph_execute, expected[0]["seq"], expected[1]
Exemplo n.º 2
0
 def _gengraph_execute(fold, expected, message):
     result = distance.gengraph(fold)
     print "Testing {}".format(message)
     print "Expected: {}".format(expected)
     print "Got     : {}".format(result)
     assert result == expected