Exemplo n.º 1
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"
Exemplo 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
Exemplo n.º 3
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"
Exemplo n.º 4
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]
Exemplo n.º 5
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))
Exemplo n.º 6
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()
Exemplo n.º 7
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)
Exemplo n.º 8
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"
Exemplo n.º 9
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]
Exemplo n.º 10
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"