Skip to content

Commit

Permalink
incomplete Tests for merge methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Simaris committed Dec 27, 2020
1 parent f7d0e1e commit ea51d95
Show file tree
Hide file tree
Showing 25 changed files with 307 additions and 8 deletions.
7 changes: 7 additions & 0 deletions tests/merges/TestA/a_graphs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
_:a <ed:a> _:b .
_:b <ed:b> _:c .
_:c <ed:a> _:a .
---
_:a <ed:b> _:b .
_:b <ed:a> _:c .
_:c <ed:b> _:a .
Empty file added tests/merges/TestA/base.nt
Empty file.
3 changes: 3 additions & 0 deletions tests/merges/TestA/branch.nt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
_:a <ed:a> _:b .
_:b <ed:b> _:c .
_:c <ed:a> _:a .
3 changes: 3 additions & 0 deletions tests/merges/TestA/target.nt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
_:a <ed:b> _:b .
_:b <ed:a> _:c .
_:c <ed:b> _:a .
41 changes: 41 additions & 0 deletions tests/merges/TestABCD/a_graphs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
_:a <ed:a> _:b .
_:b <ed:a> _:c .
_:c <ed:a> _:a .

_:a <ed:a> _:b .
_:b <ed:a> _:c .
_:c <ed:a> _:d .
_:d <ed:a> _:a .

_:a <ed:b> _:b .
_:b <ed:b> _:c .
_:c <ed:b> _:d .
_:d <ed:b> _:a .

_:a <ed:a> _:b .
_:b <ed:b> _:c .
_:c <ed:a> _:d .
_:d <ed:b> _:a .
---
_:a <ed:a> _:b .
_:b <ed:b> _:c .
_:c <ed:a> _:a .

_:a <ed:b> _:b .
_:b <ed:a> _:c .
_:c <ed:b> _:a .

_:a <ed:a> _:b .
_:b <ed:a> _:c .
_:c <ed:a> _:d .
_:d <ed:a> _:a .
_:a <ed:a> _:c .

_:a <ed:a> _:b .
_:b <ed:a> _:d .
_:d <ed:a> _:e .
_:e <ed:a> _:b .
_:b <ed:a> _:c .
_:c <ed:a> _:d .
_:d <ed:a> _:a .
_:a <ed:a> _:e .
Empty file added tests/merges/TestABCD/base.nt
Empty file.
18 changes: 18 additions & 0 deletions tests/merges/TestABCD/branch.nt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
_:a <ed:a> _:b .
_:b <ed:a> _:c .
_:c <ed:a> _:a .

_:a <ed:a> _:b .
_:b <ed:a> _:c .
_:c <ed:a> _:d .
_:d <ed:a> _:a .

_:a <ed:b> _:b .
_:b <ed:b> _:c .
_:c <ed:b> _:d .
_:d <ed:b> _:a .

_:a <ed:a> _:b .
_:b <ed:b> _:c .
_:c <ed:a> _:d .
_:d <ed:b> _:a .
22 changes: 22 additions & 0 deletions tests/merges/TestABCD/target.nt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
_:a <ed:a> _:b .
_:b <ed:b> _:c .
_:c <ed:a> _:a .

_:a <ed:b> _:b .
_:b <ed:a> _:c .
_:c <ed:b> _:a .

_:a <ed:a> _:b .
_:b <ed:a> _:c .
_:c <ed:a> _:d .
_:d <ed:a> _:a .
_:a <ed:a> _:c .

_:a <ed:a> _:b .
_:b <ed:a> _:d .
_:d <ed:a> _:e .
_:e <ed:a> _:b .
_:b <ed:a> _:c .
_:c <ed:a> _:d .
_:d <ed:a> _:a .
_:a <ed:a> _:e .
14 changes: 14 additions & 0 deletions tests/merges/TestB/a_graphs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
_:a <ed:a> _:b .
_:b <ed:a> _:c .
_:c <ed:a> _:d .
_:d <ed:a> _:a .
_:a <ed:a> _:c .
---
_:a <ed:a> _:b .
_:b <ed:a> _:d .
_:d <ed:a> _:e .
_:e <ed:a> _:b .
_:b <ed:a> _:c .
_:c <ed:a> _:d .
_:d <ed:a> _:a .
_:a <ed:a> _:e .
Empty file added tests/merges/TestB/base.nt
Empty file.
5 changes: 5 additions & 0 deletions tests/merges/TestB/branch.nt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
_:a <ed:a> _:b .
_:b <ed:a> _:c .
_:c <ed:a> _:d .
_:d <ed:a> _:a .
_:a <ed:a> _:c .
Binary file added tests/merges/TestB/debug.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions tests/merges/TestB/debugResult
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
_:a <ed:a> _:b .
_:b <ed:a> _:c .
_:d <ed:a> _:a .
_:b <ed:a> _:d .
_:a <ed:a> _:c .
_:c <ed:a> _:d .
_:d <ed:a> _:e .
_:e <ed:a> _:a .
Binary file added tests/merges/TestB/debugTarget.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions tests/merges/TestB/target.nt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
_:a <ed:a> _:b .
_:b <ed:a> _:d .
_:d <ed:a> _:e .
_:e <ed:a> _:b .
_:b <ed:a> _:c .
_:c <ed:a> _:d .
_:d <ed:a> _:a .
_:a <ed:a> _:e .
1 change: 1 addition & 0 deletions tests/merges/TestC/a_graphs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
_:a <ed:a> _:a .
Empty file added tests/merges/TestC/base.nt
Empty file.
3 changes: 3 additions & 0 deletions tests/merges/TestC/branch.nt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
_:a <ed:a> _:b .
_:b <ed:a> _:c .
_:c <ed:a> _:a .
3 changes: 3 additions & 0 deletions tests/merges/TestC/debugResult
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
_:a <ed:a> _:b .
_:b <ed:a> _:c .
_:c <ed:a> _:a .
4 changes: 4 additions & 0 deletions tests/merges/TestC/target.nt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
_:a <ed:a> _:b .
_:b <ed:a> _:c .
_:c <ed:a> _:d .
_:d <ed:a> _:a .
41 changes: 41 additions & 0 deletions tests/merges/TestHouseMerge/a_graphs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<http://ex.org/Eingang> <urn:ex:a> _:a .
_:a <urn:ex:a> _:b .
_:b <urn:ex:a> _:d .
_:d <urn:ex:a> _:e .
_:e <urn:ex:a> _:b .
_:b <urn:ex:a> _:c .
_:c <urn:ex:a> _:d .
_:d <urn:ex:a> _:a .
_:a <urn:ex:a> _:e .
_:a <urn:ex:a> <http://ex.org/Weg> .
<http://ex.org/Weg> <urn:ex:a> _:x .
_:x <urn:ex:a> _:y .
_:y <urn:ex:a> _:l .
_:l <urn:ex:a> _:m .
_:m <urn:ex:a> _:y .
_:y <urn:ex:a> _:z .
_:z <urn:ex:a> _:l .
_:l <urn:ex:a> _:x .
_:x <urn:ex:a> _:m .
_:m <urn:ex:a> <http://ex.org/Ausgang> .
---
<http://ex.org/Strasse> <urn:ex:a> _:a .
_:a <urn:ex:a> _:b .
_:b <urn:ex:a> _:d .
_:d <urn:ex:a> _:e .
_:e <urn:ex:a> _:b .
_:b <urn:ex:a> _:c .
_:c <urn:ex:a> _:d .
_:d <urn:ex:a> _:a .
_:a <urn:ex:a> _:e .
_:a <urn:ex:a> <http://ex.org/Weg> .
<http://ex.org/Weg> <urn:ex:a> _:x .
_:x <urn:ex:a> _:y .
_:y <urn:ex:a> _:l .
_:l <urn:ex:a> _:m .
_:m <urn:ex:a> _:y .
_:y <urn:ex:a> _:z .
_:z <urn:ex:a> _:l .
_:l <urn:ex:a> _:x .
_:x <urn:ex:a> _:m .
_:m <urn:ex:a> <http://ex.org/Strasse> .
Empty file.
20 changes: 20 additions & 0 deletions tests/merges/TestHouseMerge/branch.nt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<http://ex.org/Eingang> <urn:ex:a> _:a .
_:a <urn:ex:a> _:b .
_:b <urn:ex:a> _:d .
_:d <urn:ex:a> _:e .
_:e <urn:ex:a> _:b .
_:b <urn:ex:a> _:c .
_:c <urn:ex:a> _:d .
_:d <urn:ex:a> _:a .
_:a <urn:ex:a> _:e .
_:a <urn:ex:a> <http://ex.org/Weg> .
<http://ex.org/Weg> <urn:ex:a> _:x .
_:x <urn:ex:a> _:y .
_:y <urn:ex:a> _:l .
_:l <urn:ex:a> _:m .
_:m <urn:ex:a> _:y .
_:y <urn:ex:a> _:z .
_:z <urn:ex:a> _:l .
_:l <urn:ex:a> _:x .
_:x <urn:ex:a> _:m .
_:m <urn:ex:a> <http://ex.org/Ausgang> .
20 changes: 20 additions & 0 deletions tests/merges/TestHouseMerge/target.nt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<http://ex.org/Strasse> <urn:ex:a> _:a .
_:a <urn:ex:a> _:b .
_:b <urn:ex:a> _:d .
_:d <urn:ex:a> _:e .
_:e <urn:ex:a> _:b .
_:b <urn:ex:a> _:c .
_:c <urn:ex:a> _:d .
_:d <urn:ex:a> _:a .
_:a <urn:ex:a> _:e .
_:a <urn:ex:a> <http://ex.org/Weg> .
<http://ex.org/Weg> <urn:ex:a> _:x .
_:x <urn:ex:a> _:y .
_:y <urn:ex:a> _:l .
_:l <urn:ex:a> _:m .
_:m <urn:ex:a> _:y .
_:y <urn:ex:a> _:z .
_:z <urn:ex:a> _:l .
_:l <urn:ex:a> _:x .
_:x <urn:ex:a> _:m .
_:m <urn:ex:a> <http://ex.org/Strasse> .
94 changes: 86 additions & 8 deletions tests/merges/test_merge_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

import os
from os import listdir
from os.path import isdir, join
from os.path import isfile, isdir, join
import quit.application as quitApp
from quit.web.app import create_app
import unittest
import pygit2
from helpers import TemporaryRepositoryFactory
import rdflib
from atomicgraphs.atomic_graph import AtomicGraphFactory as aGraphFactory


class GraphMergeTests(unittest.TestCase):
Expand All @@ -22,12 +24,18 @@ def tearDown(self):
def testThreeWayMerge(self):
"""Test merging two commits."""
testPath = os.path.dirname(os.path.abspath(__file__))
print(testPath)
for d in listdir(testPath):
# for d in listdir(testPath):
# for d in ["TestA", "TestHouseMerge", "TestABCD", "TestB", "TestC"]:
# if isdir(join(testPath, d)) and d != "__pycache__":
# self._merge_test(d, "three-way")
for d in ["TestD"]:
if isdir(join(testPath, d)) and d != "__pycache__":
self._prepare_merge_test(d, "three-way")
print("#######################################")
print("### {} ###".format(d))
print("#######################################")
self._merge_test(d, "three-way")

def _prepare_merge_test(self, dirPath, method):
def _merge_test(self, dirPath, method):
# Prepate a git Repository
file = open(join(dirPath, "base.nt"), "r")
content = file.read()
Expand All @@ -51,9 +59,39 @@ def _prepare_merge_test(self, dirPath, method):
reference = repo.lookup_reference('refs/heads/%s' % "componentB")
branchOid = reference.resolve().target
branchCommit = repo.get(branchOid)
file = open(join(dirPath, "result.nt"), "r")
self.assertEqual(branchCommit.tree["graph.nt"].data.decode("utf-8"), file.read())
file.close()
if isfile(join(dirPath, "a_graphs")):
file = open(join(dirPath, "a_graphs"), "r")
aControllGraphContents = file.read().split("---")
file.close()
resultContent = branchCommit.tree["graph.nt"].data.decode("utf-8")
resultGraph = rdflib.Graph().parse(data=resultContent, format="nt")
aResultGraphs = set(iter(aGraphFactory(resultGraph)))
print("ResultContent:\n{}\n-----".format(resultContent))
print("Current Result Set:\n-->{}".format({a.__hash__() for a in aResultGraphs}))
for aControllGraphContent in aControllGraphContents:
graph = rdflib.Graph().parse(data=aControllGraphContent, format="nt")
for aGraph in aGraphFactory(graph):
print("aGraph: {}".format(aGraph.__hash__()))
message = "Merge test {}:\n Graph {} is not in the set: {}"
resultSetString = {a.__hash__() for a in aResultGraphs}
message = message.format(dirPath, aGraph.__hash__(), resultSetString)
try:
self.assertTrue(aGraph in aResultGraphs, message)
except AssertionError:
graphFile = open(join(dirPath, "debugResult"), "w")
graphFile.write(self.__show_comparison(aGraph, aControllGraphContent))
graphFile.close()
print("- {}".format(self.__show_colours(next(iter(aResultGraphs)))))
print("- {}".format(self.__show_colours(aGraph)))
raise
aResultGraphs.remove(aGraph)
message = "Merge test {}:\n Not all graphs were defined in a_graphs: {}"
message = message.format(dirPath, aResultGraphs)
self.assertEqual(0, len(aResultGraphs), message)
else:
file = open(join(dirPath, "result.nt"), "r")
self.assertEqual(branchCommit.tree["graph.nt"].data.decode("utf-8"), file.read())
file.close()

def expand_branch(self, repo, branch, graphFile):
reference = repo.lookup_reference('refs/heads/%s' % branch)
Expand All @@ -70,6 +108,46 @@ def expand_branch(self, repo, branch, graphFile):
repo.state_cleanup()
return newCommitOid

# TODO remove
def __show_comparison(self, graph, controllContent):
listLabel = ["a", "b", "c", "d", "e", "f", "g", "h", "i"]
bNodeMap = {}
for triple in graph:
node = triple[0]
if node.n3() not in bNodeMap:
if isinstance(node, rdflib.BNode):
bNodeMap[node.n3()] = "_:{}".format(listLabel.pop(0))
else:
bNodeMap[node.n3()] = "<{}>".format(node.n3())
node = triple[2]
if node.n3() not in bNodeMap:
if isinstance(node, rdflib.BNode):
bNodeMap[node.n3()] = "_:{}".format(listLabel.pop(0))
else:
bNodeMap[node.n3()] = "<{}>".format(node.n3())
template = "{1}"
result = ""
for triple in graph:
newLine = "{} <{}> {} .".format(bNodeMap[triple[0].n3()],
triple[1], bNodeMap[triple[2].n3()])
result = template.format(result, newLine)
template = "{0}\n{1}"
return result

def __show_colours(self, graph):
bNodeSet = set()
for triple in graph:
if isinstance(triple[0], rdflib.BNode):
bNodeSet.add(triple[0])
if isinstance(triple[2], rdflib.BNode):
bNodeSet.add(triple[2])
colourSet = set(graph.colourPartitions[x] for x in bNodeSet)
print("===")
for node in bNodeSet:
print("node {}".format(graph.colourPartitions[node]))
return sorted(colourSet)


# def testContextMerge(self):
# """Test merging two commits."""
#
Expand Down

0 comments on commit ea51d95

Please sign in to comment.