Ejemplo n.º 1
0
class correspondenceTest(unittest.TestCase):

    def setUp(self):
        testNS = {
            'med'   : 'http://ds.tno.nl/mediator/1.0/',
            'dc'    : 'http://purl.org/dc/elements/1.1/',
            'edoal' : 'http://ns.inria.org/edoal/1.0/#'
        }
        self.base = 'http://knowledgeweb.semanticweb.org/heterogeneity/alignment#'
        self.nsMgr = NSManager(testNS, self.base)
        self.c = PT.Correspondence(nsMgr=self.nsMgr)
        print('Testcase: {}'.format(self.__class__.__name__))

    def tearDown(self):
        pass

    def testSetName(self):
        print('\tTesting {} '.format(inspect.currentframe().f_code.co_name), end="")
        # Success scenarios
        self.c.setName(name="appelepap") 
        assert self.c.getName() == "appelepap", "Assertion error, got {}".format(self.c.getName())
        self.c.setName(name="unknownPF:appelepap") 
        assert self.c.getName() == "unknownPF:appelepap", "Assertion error, got {}".format(self.c.getName())
        print(".", end="")
        # Failure scenarios
        with self.assertRaises(AssertionError): 
            self.c.setName(name="")
        with self.assertRaises(AssertionError): 
            self.c.setName(name=12)
        with self.assertRaises(AssertionError): 
            self.c.setName(name=True)
        with self.assertRaises(AssertionError): 
            self.c.setName(name=False)
        with self.assertRaises(AssertionError): 
            self.c.setName(name=None)
        print(". done")
            
    def testEntity(self):
        print('\tTesting {} '.format(inspect.currentframe().f_code.co_name), end="")
        count = 0
        N = 4 + 4
        # Success scenarios
        for e_type in [PT.Alignment.EDOAL['CLASS'], PT.Alignment.EDOAL['RELN'], PT.Alignment.EDOAL['PROP'], PT.Alignment.EDOAL['INST']]:
            count += 1
            # Success scenarios, QName with prefix
            testEnt = PT._Entity(entity_iri="med:appelepap", entity_type=e_type, nsMgr=self.nsMgr)
            exp_iri = "<http://ds.tno.nl/mediator/1.0/appelepap>"
            assert testEnt.getIriRef() == exp_iri, "Testfault: got '{}', expected '{}'.".format(testEnt.getIriRef(), exp_iri)
            assert testEnt.getType() == e_type, "Testfault: got '{}', expected '{}'.".format(testEnt.getType(), e_type)
            # Success scenarios, QName without prefix
            testEnt = PT._Entity(entity_iri=":appelepap", entity_type=e_type, nsMgr=self.nsMgr)
            exp_iri = "<" + self.base + "appelepap>"
            assert testEnt.getIriRef() == exp_iri and testEnt.getType() == e_type
            # Success scenarios, with correct IRI
            testEnt = PT._Entity(entity_iri="http://www.w3.org/TR/2003/CR-owl-guide-20030818/wine#VintageYear", entity_type=e_type, nsMgr=self.nsMgr)
            exp_iri = "<http://www.w3.org/TR/2003/CR-owl-guide-20030818/wine#VintageYear>"
            assert testEnt.getIriRef() == exp_iri, "Testfault: got '{}', expected '{}'.".format(testEnt.getIriRef(), exp_iri)
            assert testEnt.getType() == e_type, "Testfault: got '{}', expected '{}'.".format(testEnt.getType(), e_type)
            # Success scenarios, with correct <IRI>
            testEnt = PT._Entity(entity_iri="<http://www.w3.org/TR/2003/CR-owl-guide-20030818/wine#VintageYear>", entity_type=e_type, nsMgr=self.nsMgr)
            exp_iri = "<http://www.w3.org/TR/2003/CR-owl-guide-20030818/wine#VintageYear>"
            assert testEnt.getIriRef() == exp_iri, "Testfault: got '{}', expected '{}'.".format(testEnt.getIriRef(), exp_iri)
            assert testEnt.getType() == e_type, "Testfault: got '{}', expected '{}'.".format(testEnt.getType(), e_type)
            # Success scenarios, with correct Clark's notation
            testEnt = PT._Entity(entity_iri="{http://www.w3.org/TR/2003/CR-owl-guide-20030818/wine#}VintageYear", entity_type=e_type, nsMgr=self.nsMgr)
            exp_iri = "<http://www.w3.org/TR/2003/CR-owl-guide-20030818/wine#VintageYear>"
            assert testEnt.getIriRef() == exp_iri, "Testfault: got '{}', expected '{}'.".format(testEnt.getIriRef(), exp_iri)
            assert testEnt.getType() == e_type, "Testfault: expected '{}', got '{}'.".format(testEnt.getType(), e_type)
            print(".", end="")
        # Failure scenarios
        for e_type in [PT.Alignment.EDOAL['CLASS'], PT.Alignment.EDOAL['RELN'], PT.Alignment.EDOAL['PROP'], PT.Alignment.EDOAL['INST']]:
            count += 1
            with self.assertRaises(RuntimeError): 
                testEnt = PT._Entity(entity_iri=":^_invalidIriChar", entity_type=e_type, nsMgr=self.nsMgr)
            with self.assertRaises(RuntimeError): 
                testEnt = PT._Entity(entity_iri=":!_invalidIriChar", entity_type=e_type, nsMgr=self.nsMgr)
            with self.assertRaises(RuntimeError): 
                testEnt = PT._Entity(entity_iri="^_invalidIriChar", entity_type=e_type, nsMgr=self.nsMgr)
            with self.assertRaises(AssertionError): 
                testEnt = PT._Entity(entity_iri="", entity_type=e_type, nsMgr=self.nsMgr)
            with self.assertRaises(RuntimeError): 
                testEnt = PT._Entity(entity_iri="unknownPF:appelepap", entity_type=e_type, nsMgr=self.nsMgr)
            with self.assertRaises(RuntimeError): 
                testEnt = PT._Entity(entity_iri="noPFOrAnythingWhatsoever", entity_type=e_type, nsMgr=self.nsMgr)
            with self.assertRaises(AssertionError): 
                testEnt = PT._Entity(entity_iri=12, entity_type=e_type, nsMgr=self.nsMgr)
            with self.assertRaises(AssertionError): 
                testEnt = PT._Entity(entity_iri=12.3, entity_type=e_type, nsMgr=self.nsMgr)
            with self.assertRaises(AssertionError): 
                testEnt = PT._Entity(entity_iri=True, entity_type=e_type, nsMgr=self.nsMgr)
            with self.assertRaises(AssertionError): 
                testEnt = PT._Entity(entity_iri=False, entity_type=e_type, nsMgr=self.nsMgr)
            with self.assertRaises(AssertionError): 
                testEnt = PT._Entity(entity_iri=None, entity_type=e_type, nsMgr=self.nsMgr)
            print(".", end="")
        assert count == N, "Didn't test everything, expected {} tests, done only {}".format(N, count)
        print(". done")

    def testConstruction(self):
        print('\tTesting {} '.format(inspect.currentframe().f_code.co_name), end="")
        count = 0
        N = 3 + 3 * 3 + 4 + 4
        # Mixed success and failure scenarios
        for e_type1 in [PT.Alignment.EDOAL['CLASS'], PT.Alignment.EDOAL['RELN'], PT.Alignment.EDOAL['PROP']]:
            count += 1
            testEnt1 = PT._Entity(entity_iri="med:appelepap", entity_type=e_type1, nsMgr=self.nsMgr)
            # Success scenario - unary operation
            constr = PT.Neg(testEnt1)
            assert constr.getCType() == PT._EntityConstruction.NOTSYMBOL, "Testfault: expected '{}', got '{}'.".format(PT._EntityConstruction.NOTSYMBOL, constr.getCType())
            print(".", end="")
            # Binary operation scenarios
            for e_type2 in [PT.Alignment.EDOAL['CLASS'], PT.Alignment.EDOAL['RELN'], PT.Alignment.EDOAL['PROP']]:
                testEnt2 = PT._Entity(entity_iri="med:appelepap", entity_type=e_type2, nsMgr=self.nsMgr)
                if e_type1 == e_type2:
                    # Success scenario - binary operations
                    count += 1
                    constr = PT.Union(testEnt1, testEnt2)
                    assert constr.getCType() == PT._EntityConstruction.SQRUNION, "Testfault: expected '{}', got '{}'.".format(PT._EntityConstruction.SQRUNION, constr.getCType())
                    constr = PT.Intersection(testEnt1, testEnt2)
                    assert constr.getCType() == PT._EntityConstruction.SQRINTSCT, "Testfault: expected '{}', got '{}'.".format(PT._EntityConstruction.SQRINTSCT, constr.getCType())
                    print(".", end="")
                else: 
                    # Failure scenario - binary operations
                    count += 1
                    with self.assertRaises(AssertionError): 
                        constr = PT.Union(testEnt1, testEnt2)
                    print(".", end="")
        # Failure scenarios
        testEnt1 = PT._Entity(entity_iri="med:appelepap", entity_type=PT.Alignment.EDOAL['INST'], nsMgr=self.nsMgr)
        for e_type in [PT.Alignment.EDOAL['CLASS'], PT.Alignment.EDOAL['RELN'], PT.Alignment.EDOAL['PROP'], PT.Alignment.EDOAL['INST']]:
            count += 1
            testEnt2 = PT._Entity(entity_iri="med:appelepap", entity_type=e_type, nsMgr=self.nsMgr)
            with self.assertRaises(AssertionError): 
                constr = PT.Union(testEnt1, testEnt2)
            print(".", end="")
        testEnt2 = PT._Entity(entity_iri="med:appelepap", entity_type=PT.Alignment.EDOAL['INST'], nsMgr=self.nsMgr)
        for e_type in [PT.Alignment.EDOAL['CLASS'], PT.Alignment.EDOAL['RELN'], PT.Alignment.EDOAL['PROP'], PT.Alignment.EDOAL['INST']]:
            count += 1
            testEnt1 = PT._Entity(entity_iri="med:appelepap", entity_type=e_type, nsMgr=self.nsMgr)
            with self.assertRaises(AssertionError): 
                constr = PT.Union(testEnt1, testEnt2)
            print(".", end="")
        assert count == N, "Didn't test everything, expected {} tests, done only {}".format(N, count)
        print(". done")

    def testSetSrcEE(self):
        print('\tTesting {} '.format(inspect.currentframe().f_code.co_name), end="")
        count = 0
        N = 4 * 4 + 3 * 4 + 4
        # Success scenarios; entity_expr of type _Entity
        for e_type in [PT.Alignment.EDOAL['CLASS'], PT.Alignment.EDOAL['RELN'], PT.Alignment.EDOAL['PROP'], PT.Alignment.EDOAL['INST']]:
            for test_iri in ["med:appelepap", ":appelepap", "http://www.w3.org/TR/2003/CR-owl-guide-20030818/wine#VintageYear", "{http://www.w3.org/TR/2003/CR-owl-guide-20030818/wine#}VintageYear"]:
                count += 1
                testEnt = PT._Entity(entity_iri=test_iri, entity_type=e_type, nsMgr=self.nsMgr)
                self.c.setEE1(entity_expr=testEnt)
                assert self.c.getEE1().getIriRef() == self.nsMgr.asIRI(test_iri), "Testfault: got '{}', expected '{}'.".format(self.c.getEE1().getIriRef(), self.nsMgr.asIRI(test_iri))
                assert self.c.getEE1().getType() == e_type, "Testfault: got '{}', expected '{}'.".format(self.c.getEE1().getType(), e_type)
                print(".", end="")
                if e_type != PT.Alignment.EDOAL['INST']:
                    count += 1
                    # Success scenarios; entity_expr of type _EntityConstruction
                    testEnt2 = PT._Entity(entity_iri="med:perenmoes", entity_type=e_type, nsMgr=self.nsMgr)
                    constr = PT.Union(testEnt, testEnt2)
                    self.c.setEE1(entity_expr=constr)
                    assert self.c.getEE1().getCType() == PT._EntityConstruction.SQRUNION, "Testfault: got '{}', expected '{}'.".format(self.c.getEE1().getCType(), PT._EntityConstruction.SQRUNION)
                    assert self.c.getEE1().getEntType() == e_type, "Testfault: got '{}', expected '{}'.".format(self.c.getEE1().getEntType(), e_type)
                    assert self.c.getEE1().getEntities()[0] == testEnt, "Testfault: got '{}', expected '{}'.".format(self.c.getEE1().getEntities()[0], testEnt)
                    assert self.c.getEE1().getEntities()[1] == testEnt2, "Testfault: got '{}', expected '{}'.".format(self.c.getEE1().getEntities()[1], testEnt2)
                    constr = PT.Intersection(testEnt, testEnt2)
                    self.c.setEE1(entity_expr=constr)
                    assert self.c.getEE1().getCType() == PT._EntityConstruction.SQRINTSCT, "Testfault: got '{}', expected '{}'.".format(self.c.getEE1().getCType(), PT._EntityConstruction.SQRINTSCT)
                    assert self.c.getEE1().getEntType() == e_type, "Testfault: got '{}', expected '{}'.".format(self.c.getEE1().getEntType(), e_type)
                    assert self.c.getEE1().getEntities()[0] == testEnt, "Testfault: got '{}', expected '{}'.".format(self.c.getEE1().getEntities()[0], testEnt)
                    assert self.c.getEE1().getEntities()[1] == testEnt2, "Testfault: got '{}', expected '{}'.".format(self.c.getEE1().getEntities()[1], testEnt2)
                    print(".", end="")
        # Failure scenarios
        for e_type in [PT.Alignment.EDOAL['CLASS'], PT.Alignment.EDOAL['RELN'], PT.Alignment.EDOAL['PROP'], PT.Alignment.EDOAL['INST']]:
            count += 1
            with self.assertRaises(AssertionError): 
                self.c.setEE1(entity_expr="wrong type")
            with self.assertRaises(AssertionError): 
                self.c.setEE1(entity_expr=12)
            with self.assertRaises(AssertionError): 
                self.c.setEE1(entity_expr=12.3)
            with self.assertRaises(AssertionError): 
                self.c.setEE1(entity_expr=True)
            with self.assertRaises(AssertionError): 
                self.c.setEE1(entity_expr=None)
            print(".", end="")
        assert count == N, "Didn't test everything, expected {} tests, done only {}".format(N, count)
        print(". done")

    def testSetTgtEE(self):
        print('\tTesting {} '.format(inspect.currentframe().f_code.co_name), end="")
        count = 0
        N = 4 * 4 + 3 * 4 + 4
        # Success scenarios; entity_expr of type _Entity
        for e_type in [PT.Alignment.EDOAL['CLASS'], PT.Alignment.EDOAL['RELN'], PT.Alignment.EDOAL['PROP'], PT.Alignment.EDOAL['INST']]:
            for test_iri in ["med:appelepap", ":appelepap", "http://www.w3.org/TR/2003/CR-owl-guide-20030818/wine#VintageYear", "{http://www.w3.org/TR/2003/CR-owl-guide-20030818/wine#}VintageYear"]:
                count += 1
                testEnt = PT._Entity(entity_iri=test_iri, entity_type=e_type, nsMgr=self.nsMgr)
                self.c.setEE2(entity_expr=testEnt)
                assert self.c.getEE2().getIriRef() == self.nsMgr.asIRI(test_iri), "Testfault: got '{}', expected '{}'.".format(self.c.getEE2().getIriRef(), self.nsMgr.asIRI(test_iri))
                assert self.c.getEE2().getType() == e_type, "Testfault: got '{}', expected '{}'.".format(self.c.getEE2().getType(), e_type)
                print(".", end="")
                if e_type != PT.Alignment.EDOAL['INST']:
                    # Success scenarios; entity_expr of type _EntityConstruction
                    count += 1
                    testEnt2 = PT._Entity(entity_iri="med:perenmoes", entity_type=e_type, nsMgr=self.nsMgr)
                    constr = PT.Union(testEnt, testEnt2)
                    self.c.setEE2(entity_expr=constr)
                    assert self.c.getEE2().getCType() == PT._EntityConstruction.SQRUNION, "Testfault: got '{}', expected '{}'.".format(self.c.getEE2().getCType(), PT._EntityConstruction.SQRUNION)
                    assert self.c.getEE2().getEntType() == e_type, "Testfault: got '{}', expected '{}'.".format(self.c.getEE2().getEntType(), e_type)
                    assert self.c.getEE2().getEntities()[0] == testEnt, "Testfault: got '{}', expected '{}'.".format(self.c.getEE2().getEntities()[0], testEnt)
                    assert self.c.getEE2().getEntities()[1] == testEnt2, "Testfault: got '{}', expected '{}'.".format(self.c.getEE2().getEntities()[1], testEnt2)
                    constr = PT.Intersection(testEnt, testEnt2)
                    self.c.setEE2(entity_expr=constr)
                    assert self.c.getEE2().getCType() == PT._EntityConstruction.SQRINTSCT, "Testfault: got '{}', expected '{}'.".format(self.c.getEE2().getCType(), PT._EntityConstruction.SQRINTSCT)
                    assert self.c.getEE2().getEntType() == e_type, "Testfault: got '{}', expected '{}'.".format(self.c.getEE2().getEntType(), e_type)
                    assert self.c.getEE2().getEntities()[0] == testEnt, "Testfault: got '{}', expected '{}'.".format(self.c.getEE2().getEntities()[0], testEnt)
                    assert self.c.getEE2().getEntities()[1] == testEnt2, "Testfault: got '{}', expected '{}'.".format(self.c.getEE2().getEntities()[1], testEnt2)
                    print(".", end="")
        # Failure scenarios
        for e_type in [PT.Alignment.EDOAL['CLASS'], PT.Alignment.EDOAL['RELN'], PT.Alignment.EDOAL['PROP'], PT.Alignment.EDOAL['INST']]:
            count += 1
            with self.assertRaises(AssertionError): 
                self.c.setEE2(entity_expr="wrong type")
            with self.assertRaises(AssertionError): 
                self.c.setEE2(entity_expr=12)
            with self.assertRaises(AssertionError): 
                self.c.setEE2(entity_expr=12.3)
            with self.assertRaises(AssertionError): 
                self.c.setEE2(entity_expr=True)
            with self.assertRaises(AssertionError): 
                self.c.setEE2(entity_expr=None)
            print(".", end="")
        assert count == N, "Didn't test everything, expected {} tests, done only {}".format(N, count)
        print(". done")

    def testSetCorrRelation(self):
        print('\tTesting {} '.format(inspect.currentframe().f_code.co_name), end="")
        count = 0
        N = 5 
        # Success scenarios
        for rel in [PT.MEDRELEQ, PT.MEDRELSUB, PT.MEDRELSUP, PT.MEDRELIN, PT.MEDRELNI]:
            count += 1
            self.c.setCorrRelation(relation=rel)
            assert self.c.getCorrRelation() == rel
            print(".", end="")
        # Failure scenarios
        with self.assertRaises(AssertionError): 
            self.c.setCorrRelation(relation=None)
        with self.assertRaises(AssertionError): 
            self.c.setCorrRelation(relation=12)
        with self.assertRaises(AssertionError): 
            self.c.setCorrRelation(relation="appelepap")
        with self.assertRaises(AssertionError): 
            self.c.setCorrRelation(relation=True)
        with self.assertRaises(AssertionError): 
            self.c.setCorrRelation(relation=False)
        assert count == N, "Didn't test everything, expected {} tests, done only {}".format(N, count)
        print(". done")

    def testSetCorrMeasure(self):
        print('\tTesting {} '.format(inspect.currentframe().f_code.co_name), end="")
        count = 0
        N = 6 + 8
        # Success scenarios
        for val, tpe in [(0.01, self.nsMgr.asIRI('xsd:float')), ('medium', self.nsMgr.asIRI('xsd:string')), (0.0, self.nsMgr.asIRI('xsd:double')), (1.0, self.nsMgr.asIRI('xsd:float')), (0, self.nsMgr.asIRI('xsd:decimal')), (1, self.nsMgr.asIRI('xsd:integer'))]:
            count += 1
            self.c.setCorrMeasure(measure=val, measure_type=tpe)
            assert (val, tpe) == self.c.getCorrMeasure()
            print(".", end="")
        # Failure scenarios - no check exist yet for incoherence between measure and measure_type, e.g., (0.42, xsd:integer), or ('appelepap', xsd:float)
        for val, tpe in [(0.01, ''), (None, self.nsMgr.asIRI('xsd:float')), (None, None), ('', None), (None, ''), ('', ''), (-0.1, self.nsMgr.asIRI('xsd:float')), (12, self.nsMgr.asIRI('xsd:integer'))]:
            count += 1
            with self.assertRaises(AssertionError): 
                self.c.setCorrMeasure(measure=val, measure_type=tpe)
            print(".", end="")
        assert count == N, "Didn't test everything, expected {} tests, done only {}".format(N, count)
        print(". done")
Ejemplo n.º 2
0
class TestNSManager(unittest.TestCase):
    def setUp(self):
        testNS = {
            'med': 'http://ds.tno.nl/mediator/1.0/',
            'dc': 'http://purl.org/dc/elements/1.1/',
            'edoal': 'http://ns.inria.org/edoal/1.0/#',
            'test': 'http://ds.tno.nl/mediator/1.0'
        }
        self.base = 'http://knowledgeweb.semanticweb.org/heterogeneity/alignment#'
        self.nsMgr = NSManager(nsDict=testNS, base=self.base)

    def tearDown(self):
        pass

    def testNsConcat(self):
        print('Testcase {}\n\ttesting {} ..'.format(
            self.__class__.__name__,
            inspect.currentframe().f_code.co_name),
              end="",
              flush=True)
        assert self.nsMgr.nsConcat(
            'http://www.w3.org/2001/XMLSchema#', 'appel'
        ) == '<http://www.w3.org/2001/XMLSchema#appel>', "got {}".format(
            self.nsMgr.nsConcat('http://www.w3.org/2001/XMLSchema#', 'appel'))
        assert self.nsMgr.nsConcat(
            '<http://www.w3.org/2001/XMLSchema#>', 'appel'
        ) == '<http://www.w3.org/2001/XMLSchema#appel>', "got {}".format(
            self.nsMgr.nsConcat('<http://www.w3.org/2001/XMLSchema#>',
                                'appel'))
        assert self.nsMgr.nsConcat(
            'http://www.w3.org/2001/XMLSchema/', 'appel'
        ) == '<http://www.w3.org/2001/XMLSchema/appel>', "got {}".format(
            self.nsMgr.nsConcat('http://www.w3.org/2001/XMLSchema/', 'appel'))
        assert self.nsMgr.nsConcat(
            '<http://www.w3.org/2001/XMLSchema/>', 'appel'
        ) == '<http://www.w3.org/2001/XMLSchema/appel>', "got {}".format(
            self.nsMgr.nsConcat('<http://www.w3.org/2001/XMLSchema/>',
                                'appel'))
        assert self.nsMgr.nsConcat(
            'http://www.w3.org/2001/XMLSchema', 'appel'
        ) == '<http://www.w3.org/2001/XMLSchema/appel>', "got {}".format(
            self.nsMgr.nsConcat('http://www.w3.org/2001/XMLSchema', 'appel'))
        assert self.nsMgr.nsConcat(
            '<http://www.w3.org/2001/XMLSchema>', 'appel'
        ) == '<http://www.w3.org/2001/XMLSchema/appel>', "got {}".format(
            self.nsMgr.nsConcat('<http://www.w3.org/2001/XMLSchema>', 'appel'))
        print(". done")

    def testCONSTANTS(self):
        print('Testcase {}\n\ttesting {} ..'.format(
            self.__class__.__name__,
            inspect.currentframe().f_code.co_name),
              end="",
              flush=True)
        assert self.nsMgr.CLARKS_LABELS[
            'XSDSTRING'] == '{http://www.w3.org/2001/XMLSchema#}string'
        assert self.nsMgr.CLARKS_LABELS[
            'RDFABOUT'] == '{http://www.w3.org/1999/02/22-rdf-syntax-ns#}about'
        assert self.nsMgr.CLARKS_LABELS[
            'RDFDATATP'] == '{http://www.w3.org/1999/02/22-rdf-syntax-ns#}datatype'
        assert self.nsMgr.CLARKS_LABELS[
            'RDFPARSTP'] == '{http://www.w3.org/1999/02/22-rdf-syntax-ns#}parseType'
        assert self.nsMgr.CLARKS_LABELS[
            'RDFDATATP'] == '{http://www.w3.org/1999/02/22-rdf-syntax-ns#}datatype'
        assert self.nsMgr.CLARKS_LABELS[
            'ALIGNMENT'] == '{http://knowledgeweb.semanticweb.org/heterogeneity/alignment#}Alignment'
        print(". done")

    def testSplitIRI(self):
        print('Testcase {}\n\ttesting {} ..'.format(
            self.__class__.__name__,
            inspect.currentframe().f_code.co_name),
              end="",
              flush=True)
        assert ('align', "Alignment") == self.nsMgr._splitIRI(
            "<http://knowledgeweb.semanticweb.org/heterogeneity/alignment#Alignment>"
        ), "Unexpectedly got '{}'".format(
            self.nsMgr._splitIRI(
                "<http://knowledgeweb.semanticweb.org/heterogeneity/alignment#Alignment>"
            ))
        assert ('med', "Alignment") == self.nsMgr._splitIRI(
            "<http://ds.tno.nl/mediator/1.0/Alignment>")
        with self.assertRaises(AssertionError):
            self.nsMgr._splitIRI("http:Alignment")
        with self.assertRaises(AssertionError):
            self.nsMgr._splitIRI("<http:Alignment>")
        with self.assertRaises(AssertionError):
            self.nsMgr._splitIRI("Alignment")
        with self.assertRaises(AssertionError):
            self.nsMgr._splitIRI("<Alignment>")
        with self.assertRaises(AssertionError):
            self.nsMgr._splitIRI("{http://purl.org/dc/elements/1.1/}creator")
        print(". done")

    def testAsClarks(self):
        print('Testcase {}\n\ttesting {} ..'.format(
            self.__class__.__name__,
            inspect.currentframe().f_code.co_name),
              end="",
              flush=True)
        assert isinstance(self.nsMgr.asClarks('dc:creator'), str)
        assert self.nsMgr.asClarks(
            'dc:creator'
        ) == '{http://purl.org/dc/elements/1.1/}creator', 'Expected "{http://purl.org/dc/elements/1.1/}creator", got {}'.format(
            self.nsMgr.asClarks('dc:creator'))
        assert self.nsMgr.asClarks(
            "<http://purl.org/dc/elements/1.1/creator>"
        ) == '{http://purl.org/dc/elements/1.1/}creator', 'Expected "{http://purl.org/dc/elements/1.1/}creator", got {}'.format(
            self.nsMgr.asClarks("<http://purl.org/dc/elements/1.1/creator>"))
        assert self.nsMgr.asClarks(
            ':align'
        ) == '{' + self.base + '}align', 'Expected: {}, got: {}'.format(
            '{' + self.base + '}align', str(self.nsMgr.asClarks(':align')))
        with self.assertRaises(Exception):
            self.nsMgr.asClarks('none:creator')
        with self.assertRaises(Exception):
            self.nsMgr.asClarks('dc:creator:invalidQname')
        print(". done")

    def testAsIri(self):
        print('Testcase {}\n\ttesting {} ..'.format(
            self.__class__.__name__,
            inspect.currentframe().f_code.co_name),
              end="",
              flush=True)
        print(str(self.nsMgr))
        # Success scenarios
        inpstr = 'dc:creator'
        expstr = '<http://purl.org/dc/elements/1.1/creator>'
        assert str(self.nsMgr.asIRI(
            inpstr)) == expstr, 'Expected: {}, got: {}'.format(
                expstr, str(self.nsMgr.asIRI(inpstr)))
        inpstr = 'test:creator'
        expstr = '<http://ds.tno.nl/mediator/1.0/creator>'
        assert str(self.nsMgr.asIRI(
            inpstr)) == expstr, 'Expected: {}, got: {}'.format(
                expstr, str(self.nsMgr.asIRI(inpstr)))
        inpstr = ':align'
        expstr = '<' + self.base + 'align>'
        assert str(self.nsMgr.asIRI(
            inpstr)) == expstr, 'Expected: {}, got: {}'.format(
                expstr, str(self.nsMgr.asIRI(inpstr)))
        inpstr = '{}align'
        expstr = '<' + self.base + 'align>'
        assert str(self.nsMgr.asIRI(
            inpstr)) == expstr, 'Expected: {}, got: {}'.format(
                expstr, str(self.nsMgr.asIRI(inpstr)))
        inpstr = '<http://purl.org/dc/elements/1.1/creator>'
        expstr = '<http://purl.org/dc/elements/1.1/creator>'
        assert str(self.nsMgr.asIRI(
            inpstr)) == expstr, 'Expected: {}, got: {}'.format(
                expstr, str(self.nsMgr.asIRI(inpstr)))
        inpstr = '{http://purl.org/dc/elements/1.1/}creator'
        expstr = '<http://purl.org/dc/elements/1.1/creator>'
        assert str(self.nsMgr.asIRI(
            inpstr)) == expstr, 'Expected: {}, got: {}'.format(
                expstr, str(self.nsMgr.asIRI(inpstr)))
        # Fail scenarios
        with self.assertRaises(Exception):
            self.nsMgr.asIri('')
        with self.assertRaises(Exception):
            self.nsMgr.asIri('<>')
        with self.assertRaises(Exception):
            self.nsMgr.asIri(':')
        with self.assertRaises(Exception):
            self.nsMgr.asIri('<:>')
        with self.assertRaises(Exception):
            self.nsMgr.asIri('{}')
        with self.assertRaises(Exception):
            self.nsMgr.asIri('<{}>')
        with self.assertRaises(Exception):
            self.nsMgr.asIri('{<>}')
        with self.assertRaises(Exception):
            self.nsMgr.asIri('{}creator{}')
        with self.assertRaises(Exception):
            self.nsMgr.asIri('{}{}creator')
        with self.assertRaises(Exception):
            self.nsMgr.asIri('<none:creator>')
        with self.assertRaises(Exception):
            self.nsMgr.asIri('<dc:creator:invalidQname>')
        print(". done")

    def testPrefix(self):
        print('Testcase {}\n\ttesting {} ..'.format(
            self.__class__.__name__,
            inspect.currentframe().f_code.co_name),
              end="",
              flush=True)
        pf = self.nsMgr.getPrefix('http://ds.tno.nl/mediator/1.0/')
        assert pf == 'med', "Expected {}, got {}".format('med', pf)
        # TestNSManager creation of new prefix
        pf = self.nsMgr.getPrefix('http://ds.tno.nl/non-existent/1.0/')
        cntr = self.nsMgr._prefixCntr
        expectedPF = self.nsMgr.newPrefix()[:-1] + str(cntr)
        assert pf == expectedPF, "Expected {}, got {}".format(expectedPF, pf)
        # TestNSManager new prefix has been registered, i.e., no new prefix has been created again
        pf = self.nsMgr.getPrefix('http://ds.tno.nl/non-existent/1.0/')
        assert pf == expectedPF, "Expected {}, got {}".format(expectedPF, pf)
        print(". done")

    def testIsQName(self):
        print('Testcase {}\n\ttesting {} ..'.format(
            self.__class__.__name__,
            inspect.currentframe().f_code.co_name),
              end="",
              flush=True)
        assert self.nsMgr.isQName('appel:ei')
        assert self.nsMgr.isQName(':ei')
        assert not self.nsMgr.isQName('')
        assert not self.nsMgr.isQName(':')
        assert not self.nsMgr.isQName('appel:')
        assert not self.nsMgr.isQName(':appel:ei')
        assert not self.nsMgr.isQName('koe:appel:ei')
        assert not self.nsMgr.isQName(
            'http://knowledgeweb.semanticweb.org/heterogeneity/alignment#egg')
        print(". done")

    def testIsClarks(self):
        print('Testcase {}\n\ttesting {} ..'.format(
            self.__class__.__name__,
            inspect.currentframe().f_code.co_name),
              end="",
              flush=True)
        assert self.nsMgr.isClarks('{appel}ei')
        assert self.nsMgr.isClarks('{}ei')
        assert not self.nsMgr.isClarks('')
        assert not self.nsMgr.isClarks('{}')
        assert not self.nsMgr.isClarks('{appel}')
        assert not self.nsMgr.isClarks('appel{}')
        assert not self.nsMgr.isClarks('appel{ei}')
        assert not self.nsMgr.isClarks('{}{appel}ei')
        assert not self.nsMgr.isClarks('{koe}{appel}ei')
        assert not self.nsMgr.isClarks('}appel}ei')
        assert not self.nsMgr.isClarks('{appel{ei')
        assert not self.nsMgr.isClarks('{appel}{ei')
        assert not self.nsMgr.isClarks('{appel{}ei')
        print(". done")

    def testIsIRI(self):
        print('Testcase {}\n\ttesting {} ..'.format(
            self.__class__.__name__,
            inspect.currentframe().f_code.co_name),
              end="",
              flush=True)
        assert self.nsMgr.isIRI(
            '<preamb://authority.name/iri_expans/iri_path>')
        assert self.nsMgr.isIRI(
            '<preamb://authority.org/iri_expans/iri_expans/iri_path>')
        assert self.nsMgr.isIRI('<preamb://authority.org/iri_expans#iri_path>')
        assert self.nsMgr.isIRI(
            '<preamb://authority.org/iri_expans/iri_expans#iri_path>')
        assert self.nsMgr.isIRI(
            '<http://knowledgeweb.semanticweb.org/heterogeneity/alignment#Alignment>'
        )
        assert self.nsMgr.isIRI('<http://ds.tno.nl/mediator/1.0/Alignment>')
        assert self.nsMgr.isIRI(
            '<preamb://authority.org/iri_expans/iri_expans#subpath/path>')

        assert not self.nsMgr.isIRI(
            'preamb://authority.fives/iri_expans/iri_path')
        assert not self.nsMgr.isIRI(
            'preamb://authority.name/iri_expans/iri_path>')
        assert not self.nsMgr.isIRI(
            '<preamb://authority.name/iri_expans/iri_path')
        assert not self.nsMgr.isIRI(
            '<preamb://authority.l/iri_expans/iri_path>')
        assert not self.nsMgr.isIRI(
            '<preamb://authority./iri_expans/iri_path>')
        assert not self.nsMgr.isIRI('<preamb://authority/iri_expans/iri_path>')
        assert not self.nsMgr.isIRI(
            '<://authority.something/iri_expans/iri_path>')
        assert not self.nsMgr.isIRI(
            '<preamb:authority.something/iri_expans/iri_path>')
        assert not self.nsMgr.isIRI('<preamb:authority>')
        assert not self.nsMgr.isIRI(
            '<{preamb://authority.org/iri_expans/iri_expans#}iri_path>')
        assert not self.nsMgr.isIRI(
            '<{preamb://authority.org/iri_expans/iri_expans/}iri_path>')
        assert not self.nsMgr.isIRI(
            '<preamb://authority.org/iri_expans/iri_expan/iri_path#>')
        assert not self.nsMgr.isIRI(
            '<preamb://authority.org/iri_expans/iri_expans#iri_path/>')
        assert not self.nsMgr.isIRI(
            '<preamb://authority.org/iri_expans/iri_expans/iri_path/>')
        print(". done")

    def testSplit(self):
        print('Testcase {}\n\ttesting {} ..'.format(
            self.__class__.__name__,
            inspect.currentframe().f_code.co_name),
              end="",
              flush=True)
        # Success scenarios
        pf, prefix_expansion, iri_path = self.nsMgr.splitIri('dc:path')
        assert pf == 'dc' and prefix_expansion == 'http://purl.org/dc/elements/1.1/' and iri_path == 'path', "Got pf:{}, expansion:{}, path:{}".format(
            pf, prefix_expansion, iri_path)
        pf, prefix_expansion, iri_path = self.nsMgr.splitIri(':path')
        assert pf == '' and prefix_expansion == 'http://knowledgeweb.semanticweb.org/heterogeneity/alignment#' and iri_path == 'path', "Got pf:{}, expansion:{}, path:{}".format(
            pf, prefix_expansion, iri_path)
        pf, prefix_expansion, iri_path = self.nsMgr.splitIri(
            '{http://purl.org/dc/elements/1.1/}path')
        assert pf == 'dc' and prefix_expansion == 'http://purl.org/dc/elements/1.1/' and iri_path == 'path', "Got pf:{}, expansion:{}, path:{}".format(
            pf, prefix_expansion, iri_path)
        pf, prefix_expansion, iri_path = self.nsMgr.splitIri('{}path')
        assert pf == '' and prefix_expansion == 'http://knowledgeweb.semanticweb.org/heterogeneity/alignment#' and iri_path == 'path', "Got pf:{}, expansion:{}, path:{}".format(
            pf, prefix_expansion, iri_path)
        # Fail scenarios
        with self.assertRaises(NotImplementedError):
            pf, prefix_expansion, iri_path = self.nsMgr.splitIri('path:')
        with self.assertRaises(NotImplementedError):
            pf, prefix_expansion, iri_path = self.nsMgr.splitIri('a*a')
        with self.assertRaises(NotImplementedError):
            pf, prefix_expansion, iri_path = self.nsMgr.splitIri('a!a')
        with self.assertRaises(NotImplementedError):
            pf, prefix_expansion, iri_path = self.nsMgr.splitIri('a@a')
        with self.assertRaises(NotImplementedError):
            pf, prefix_expansion, iri_path = self.nsMgr.splitIri('a$a')
        with self.assertRaises(NotImplementedError):
            pf, prefix_expansion, iri_path = self.nsMgr.splitIri('a%a')
        with self.assertRaises(NotImplementedError):
            pf, prefix_expansion, iri_path = self.nsMgr.splitIri('a^a')
        with self.assertRaises(NotImplementedError):
            pf, prefix_expansion, iri_path = self.nsMgr.splitIri('a&a')
        with self.assertRaises(NotImplementedError):
            pf, prefix_expansion, iri_path = self.nsMgr.splitIri('a(a')
        with self.assertRaises(NotImplementedError):
            pf, prefix_expansion, iri_path = self.nsMgr.splitIri('a)a')
        with self.assertRaises(NotImplementedError):
            pf, prefix_expansion, iri_path = self.nsMgr.splitIri('a_a')
        with self.assertRaises(NotImplementedError):
            pf, prefix_expansion, iri_path = self.nsMgr.splitIri('a-a')
        with self.assertRaises(NotImplementedError):
            pf, prefix_expansion, iri_path = self.nsMgr.splitIri('a+a')
        with self.assertRaises(NotImplementedError):
            pf, prefix_expansion, iri_path = self.nsMgr.splitIri('a=a')
        with self.assertRaises(NotImplementedError):
            pf, prefix_expansion, iri_path = self.nsMgr.splitIri('a[a')
        with self.assertRaises(NotImplementedError):
            pf, prefix_expansion, iri_path = self.nsMgr.splitIri('a]a')
        with self.assertRaises(NotImplementedError):
            pf, prefix_expansion, iri_path = self.nsMgr.splitIri('a|a')
        with self.assertRaises(NotImplementedError):
            pf, prefix_expansion, iri_path = self.nsMgr.splitIri('a;a')
        with self.assertRaises(NotImplementedError):
            pf, prefix_expansion, iri_path = self.nsMgr.splitIri('a"a')
        with self.assertRaises(NotImplementedError):
            pf, prefix_expansion, iri_path = self.nsMgr.splitIri("a'a")
        with self.assertRaises(NotImplementedError):
            pf, prefix_expansion, iri_path = self.nsMgr.splitIri('a~a')
        with self.assertRaises(NotImplementedError):
            pf, prefix_expansion, iri_path = self.nsMgr.splitIri('a`a')
        with self.assertRaises(NotImplementedError):
            pf, prefix_expansion, iri_path = self.nsMgr.splitIri('a,a')
        with self.assertRaises(NotImplementedError):
            pf, prefix_expansion, iri_path = self.nsMgr.splitIri('a<a')
        with self.assertRaises(NotImplementedError):
            pf, prefix_expansion, iri_path = self.nsMgr.splitIri('a>a')
        with self.assertRaises(NotImplementedError):
            pf, prefix_expansion, iri_path = self.nsMgr.splitIri('a?a')
        print(". done")