Ejemplo n.º 1
0
def test_mutation_of_lines():
    rev1 = [
        "a",
        "b",
        "c",
        "d",
        "e"
    ]

    rev2 = [
        "a",
        "b.1",
        "b.2",
        "c",
        "d",
        "e.1"
    ]
    beginning = None
    revisions = [rev1, rev2]
    networkx_graph = NetworkxGraph()
    simple_matcher = SimpleMatcher()
    gb_obj = gb.GraphBuilder(simple_matcher, networkx_graph)
    beginning = gb_obj.build_graph(revisions)
    gb_obj.slice_line(1, 2)

    assert beginning[1][0].label == "u"
    assert beginning[1][1].label == "c"
    assert beginning[1][2].label == "c"
    assert beginning[1][3].label == "u"
    assert beginning[1][4].label == "u"
    assert beginning[1][5].label == "c"
Ejemplo n.º 2
0
def test_git_files_as_input():

    bare_repo = Repo("./")
    assert bare_repo
    path = "Framework/orchestrator.py"
    path = "Tests/GraphBuilderTests.py"
    relevant_commits = list(bare_repo.iter_commits(paths=path))

    revlist = (
        (commit, (commit.tree / path).data_stream.read())
        for commit in relevant_commits
    )

    revisions = []
    for commit, filecontents in revlist:
        str_file_contents = str(filecontents).split("\\n")
        revisions.append(str_file_contents)

    revisions = Reverse(revisions)
    input_source = StubbedInputSource(revisions)
    mapper = SimpleMapper()
    csv_serializer = CsvFileSerializer("Data", "actual_code.csv")
    networkx_graph = NetworkxGraph(csv_serializer)
    slicer = LineSlicer(networkx_graph)
    orchestrator = Orchestrator(input_source, mapper, networkx_graph, slicer)
    beginning = orchestrator.orchestrate()
    j = 0
Ejemplo n.º 3
0
def test_check_displacement():
    rev1 = [
        "a",
        "b.1",
        "b.2",
        "c",
        "b.3"
    ]

    rev2 = [
        "a",
        "b.1",
        "b.2",
        "b.3",
        "c"
    ]

    revisions = [rev1, rev2]
    networkx_graph = NetworkxGraph()
    simple_matcher = SimpleMatcher()
    gb_obj = gb.SimpleGraphBuilder(simple_matcher)
    beginning = gb_obj.build_graph(revisions)

    assert beginning[1][3].label == "u"
    assert beginning[1][4].label == "a"
Ejemplo n.º 4
0
def test_blanks():
    rev1 = [
        "e",
        "",
        "",
        "",
        "",
        "",
        "fd"
    ]

    rev2 = [
        "e",
        "",
        "",
        "yz"
    ]
    beginning = None
    revisions = [rev1, rev2]
    networkx_graph = NetworkxGraph()
    simple_matcher = SimpleMatcher()
    gb_obj = gb.GraphBuilder(simple_matcher, networkx_graph)
    beginning = gb_obj.build_graph(revisions)

    assert beginning[0][1].label == "a"
    assert beginning[0][2].label == "a"
    assert beginning[0][3].label == "d"
    assert beginning[0][4].label == "d"
    assert beginning[0][5].label == "d"
    assert beginning[0][6].label == "d"
    assert beginning[1][1].label == "u"
    assert beginning[1][2].label == "u"
    assert beginning[1][3].label == "a"
Ejemplo n.º 5
0
def test_check_displacement():
    rev1 = [
        "a",
        "b.1",
        "b.2",
        "c",
        "b.3"
    ]

    rev2 = [
        "a",
        "b.1",
        "b.2",
        "b.3",
        "c"
    ]

    revisions = [rev1, rev2]
    input_source = StubbedInputSource(revisions)
    mapper = SimpleMapper()
    in_memory_serializer = InMemorySerializer()
    networkx_graph = NetworkxGraph(in_memory_serializer)
    slicer = LineSlicer(networkx_graph)
    orchestrator = Orchestrator(input_source, mapper, networkx_graph, slicer)
    beginning = orchestrator.orchestrate()

    assert beginning[1][3].label == "u"
    assert beginning[1][4].label == "a"
Ejemplo n.º 6
0
def test_deserialization():
    rev1 = [
        "a",
        "b",
        "c",
        "d",
        "e",
        "fd",
        "z"
    ]

    rev2 = [
        "a",
        "x",
        "c",
        "e",
        "y",
        "z.1"
    ]
    revisions = [rev1, rev2]
    input_source = StubbedInputSource(revisions)
    mapper = SimpleMapper()
    csv_serializer = CsvFileSerializer("Data", "deserizalized.csv")
    networkx_graph = NetworkxGraph(csv_serializer)
    slicer = LineSlicer(networkx_graph)
    orchestrator = Orchestrator(input_source, mapper, networkx_graph, slicer)
    beginning = orchestrator.orchestrate()
    assert beginning[1][0].label == "u"
    assert beginning[1][2].label == "u"
    assert beginning[1][3].label == "u"
Ejemplo n.º 7
0
def test_graph_building_via_deserialization():
    rev1 = ReadTextFromFile("Data/dummy_test_rev1.txt")
    rev2 = ReadTextFromFile("Data/dummy_test_rev2.txt")
    rev3 = ReadTextFromFile("Data/dummy_test_rev3.txt")
    rev4 = ReadTextFromFile("Data/dummy_test_rev4.txt")
    revisions = [rev1, rev2, rev3, rev4]
    input_source = StubbedInputSource(revisions)

    csv_serializer = CsvFileSerializer("Data", "multi_line.csv")
    serializer = InMemorySerializer()
    mappings = csv_serializer.deserialize(os.path.join("Data", "multi_line.csv"))
    mapper = SimpleMapper(mappings)
    networkx_graph = NetworkxGraph(serializer)
    slicer = LineSlicer(networkx_graph)
    orchestrator = Orchestrator(input_source, mapper, networkx_graph, slicer)
    beginning = orchestrator.orchestrate()

    assert mapper.get_mapping(1, 1, 1) == mappings[0][1][1]
    assert mapper.get_mapping(2, 2, 1) == mappings[0][2][2]
    assert mapper.get_mapping(7, 7, 1) == mappings[0][7][7]

    assert mapper.get_mapping(1, 1, 2) == mappings[1][1][1]
    assert mapper.get_mapping(5, 4, 2) == mappings[1][5][4]

    assert mapper.get_mapping(1, 1, 3) == mappings[2][1][1]
Ejemplo n.º 8
0
def test_multiple_files():
    rev1 = ReadTextFromFile("Data/dummy_test_rev1.txt")
    rev2 = ReadTextFromFile("Data/dummy_test_rev2.txt")
    rev3 = ReadTextFromFile("Data/dummy_test_rev3.txt")
    rev4 = ReadTextFromFile("Data/dummy_test_rev4.txt")
    revisions = [rev1, rev2, rev3, rev4]
    # networkx_graph = NetworkxGraph()
    # simple_matcher = SimpleMatcher()
    # gb_obj = gb.GraphBuilder(simple_matcher, networkx_graph)
    # beginning = gb_obj.build_graph(revisions)
    input_source = StubbedInputSource(revisions)
    mapper = SimpleMapper()
    in_memory_serializer = InMemorySerializer()
    networkx_graph = NetworkxGraph(in_memory_serializer)
    slicer = LineSlicer(networkx_graph)
    visualizer = CommandLineVisualizer()
    orchestrator = Orchestrator(input_source, mapper, networkx_graph, slicer, visualizer)
    beginning = orchestrator.orchestrate()
    print(beginning[2][4].label)
    # nodes, content = orchestrator.slice(3, 5)
    # print(content)

    nodes, content = orchestrator.slice_updated(4, 1, 1, 4, True)
    revisions = orchestrator.visualize(content)
    print(sorted(content))
Ejemplo n.º 9
0
def test_with_actual_files():
    rev1 = ReadTextFromFile("Data/Rev1")
    rev2 = ReadTextFromFile("Data/Rev2")
    revisions = [rev1, rev2]
    networkx_graph = NetworkxGraph()
    simple_matcher = SimpleMatcher()
    gb_obj = gb.GraphBuilder(simple_matcher, networkx_graph)
    beginning = gb_obj.build_graph(revisions)
    gb_obj.slice_line(1, 1)
    print(beginning[1][1].content)
Ejemplo n.º 10
0
def test_git_url_as_input():
    input_url = "https://github.com/saurabhc123/cs5704/blob/master/Tests/GraphBuilderTests.py"
    input_source = GitInputSource(input_url)
    mapper = SimpleMapper()
    csv_serializer = CsvFileSerializer("Data", "git_url_code.csv")
    networkx_graph = NetworkxGraph(csv_serializer)
    slicer = LineSlicer(networkx_graph)
    orchestrator = Orchestrator(input_source, mapper, networkx_graph, slicer)
    beginning = orchestrator.orchestrate()
    j = 0
Ejemplo n.º 11
0
def test_with_actual_files():
    rev1 = ReadTextFromFile("Data/Rev1")
    rev2 = ReadTextFromFile("Data/Rev2")
    revisions = [rev1, rev2]
    input_source = StubbedInputSource(revisions)
    mapper = SimpleMapper()
    in_memory_serializer = InMemorySerializer()
    networkx_graph = NetworkxGraph(in_memory_serializer)
    slicer = LineSlicer(networkx_graph)
    orchestrator = Orchestrator(input_source, mapper, networkx_graph, slicer)
    beginning = orchestrator.orchestrate()
Ejemplo n.º 12
0
def large_test():
    revisions = [rev1, rev2, rev3, rev4, rev5]
    # networkx_graph = NetworkxGraph()
    # simple_matcher = SimpleMatcher()
    # slicer = LineSlicing(networkx_graph)
    # gb_obj = gb.GraphBuilder(simple_matcher, networkx_graph, slicer)
    # beginning = gb_obj.build_graph(revisions)
    input_source = StubbedInputSource(revisions)
    mapper = SimpleMapper()
    in_memory_serializer = InMemorySerializer()
    networkx_graph = NetworkxGraph(in_memory_serializer)
    slicer = LineSlicer(networkx_graph)
    orchestrator = Orchestrator(input_source, mapper, networkx_graph, slicer)
    beginning = orchestrator.orchestrate()

    print(beginning[1][1].content)
Ejemplo n.º 13
0
def test_right_addition():
    rev1 = [
        "a",
        "b",
        "c",
        "d",
        "e",
        "",
        "",
        "",
        "",
        "",
        "fd"
    ]

    rev2 = [
        "a",
        "b",
        "f",
        "c",
        "d",
        "e",
        "",
        "",
        "yz"
    ]
    beginning = None
    revisions = [rev1, rev2]
    input_source = StubbedInputSource(revisions)
    mapper = SimpleMapper()
    in_memory_serializer = InMemorySerializer()
    networkx_graph = NetworkxGraph(in_memory_serializer)
    slicer = LineSlicer(networkx_graph)
    orchestrator = Orchestrator(input_source, mapper, networkx_graph, slicer)
    beginning = orchestrator.orchestrate()

    assert beginning[0][2].label == "a"
    assert beginning[1][2].label == "a"
    assert beginning[1][3].label == "u"
    assert beginning[1][3].content == rev1[2]
    assert beginning[1][4].label == "u"
    assert beginning[1][5].label == "u"
Ejemplo n.º 14
0
def test_right_addition():
    rev1 = [
        "a",
        "b",
        "c",
        "d",
        "e",
        "",
        "",
        "",
        "",
        "",
        "fd"
    ]

    rev2 = [
        "a",
        "b",
        "f",
        "c",
        "d",
        "e",
        "",
        "",
        "yz"
    ]
    beginning = None
    revisions = [rev1, rev2]
    networkx_graph = NetworkxGraph()
    simple_matcher = SimpleMatcher()
    gb_obj = gb.SimpleGraphBuilder(simple_matcher)
    beginning = gb_obj.build_graph(revisions)

    assert beginning[0][2].label == "a"
    assert beginning[1][2].label == "a"
    assert beginning[1][3].label == "u"
    assert beginning[1][3].content == rev1[2]
    assert beginning[1][4].label == "u"
    assert beginning[1][5].label == "u"
Ejemplo n.º 15
0
def test_multiple_file_in_memory_deserialization():
    rev1 = ReadTextFromFile("Data/dummy_test_rev1.txt")
    rev2 = ReadTextFromFile("Data/dummy_test_rev2.txt")
    rev3 = ReadTextFromFile("Data/dummy_test_rev3.txt")
    rev4 = ReadTextFromFile("Data/dummy_test_rev4.txt")
    revisions = [rev1, rev2, rev3, rev4]
    input_source = StubbedInputSource(revisions)
    mapper = SimpleMapper()
    in_memory_serializer = InMemorySerializer()
    networkx_graph = NetworkxGraph(in_memory_serializer)
    slicer = LineSlicer(networkx_graph)
    orchestrator = Orchestrator(input_source, mapper, networkx_graph, slicer)
    beginning = orchestrator.orchestrate()
    mappings = in_memory_serializer.deserialize(None)
    assert mapper.get_mapping(1, 1, 1) == mappings[0][1][1]
    assert mapper.get_mapping(2, 2, 1) == mappings[0][2][2]
    assert mapper.get_mapping(7, 7, 1) == mappings[0][7][7]

    assert mapper.get_mapping(1, 1, 2) == mappings[1][1][1]
    assert mapper.get_mapping(5, 4, 2) == mappings[1][5][4]

    assert mapper.get_mapping(1, 1, 3) == mappings[2][1][1]
Ejemplo n.º 16
0
def test_mutation_of_lines():
    rev1 = [
        "from Framework.graph import Graph",
        "from Framework.graph_builder import GraphBuilder",
        "from Framework.input_source import InputSource",
        "from Framework.mapper import Mapper",
        "from Implementations.Graphs.networkx_graph import NetworkxGraph",
        "self.input_source = input_source",
        "self.mapper = mapper"
    ]

    rev2 = [
        "from Framework.graph import Graph",
        "from Framework.graph_builder import GraphBuilder",
        "from Framework.input_source import InputSource",
        "from Framework.mapper import Mapper",
        "from Implementations.Graphs.networkx_graph import NetworkxGraph",
        "gb_obj = gb.SimpleGraphBuilder(self.mapper, self.graph)",
        "self.mapper = mapper + fake_mapper"
    ]
    beginning = None
    revisions = [rev1, rev2]
    input_source = StubbedInputSource(revisions)
    mapper = SimpleMapper()
    in_memory_serializer = InMemorySerializer()
    networkx_graph = NetworkxGraph(in_memory_serializer)
    slicer = LineSlicer(networkx_graph)
    orchestrator = Orchestrator(input_source, mapper, networkx_graph, slicer)
    beginning = orchestrator.orchestrate()

    assert beginning[1][0].label == "u"
    assert beginning[1][1].label == "u"
    assert beginning[1][2].label == "u"
    assert beginning[1][3].label == "u"
    assert beginning[1][4].label == "u"
    assert beginning[1][6].label == "c"