def test_alumniSuperproperty(self): p_alumni = VTerm.getTerm("alumni") p_alumniOf = VTerm.getTerm("alumniOf") p_suggestedAnswer = VTerm.getTerm("suggestedAnswer") self.assertFalse(p_alumni in p_suggestedAnswer.getSupers(), "not suggestedAnswer subPropertyOf alumni.") self.assertFalse(p_suggestedAnswer in p_alumni.getSupers(), "not alumni subPropertyOf suggestedAnswer.") self.assertFalse(p_alumni in p_alumni.getSupers(), "not alumni subPropertyOf alumni.") self.assertFalse(p_alumniOf in p_alumni.getSupers(), "not alumni subPropertyOf alumniOf.") self.assertFalse(p_suggestedAnswer in p_suggestedAnswer.getSupers(), "not suggestedAnswer subPropertyOf suggestedAnswer.")
def test_alumniInverse(self): p_alumni = VTerm.getTerm("alumni") p_alumniOf = VTerm.getTerm("alumniOf") p_suggestedAnswer = VTerm.getTerm("suggestedAnswer") #log.info("alumni: " + str(p_alumniOf.getInverseOf() )) self.assertTrue(p_alumni == p_alumniOf.getInverseOf(), "alumniOf inverseOf alumni." ) self.assertTrue(p_alumniOf == p_alumni.getInverseOf(), "alumni inverseOf alumniOf." ) self.assertFalse(p_alumni == p_alumni.getInverseOf(), "Not alumni inverseOf alumni." ) self.assertFalse(p_alumniOf == p_alumniOf.getInverseOf(), "Not alumniOf inverseOf alumniOf." ) self.assertFalse(p_alumni == p_suggestedAnswer.getInverseOf(), "Not answer inverseOf alumni." )
def test_FooBarIsNotClass(self): tFooBar = VTerm.getTerm("FooBar") try: tFooBarIsClass = tFooBar.isClass() self.assertFalse(tFooBarIsClass, "FooBar is not a class (should be None)") log.info("FooBar:" + str(tFooBar) ) except: log.debug("Failed to get FooBar, as expected. So can't ask it if it isClass().")
def test_enumCommentCount(self): enum_comment_errors=[] for ev in VTerm.getAllEnumerations(): comments = ev.getGetComments() log.debug("enumeration '%s': Expected 1 rdfs:comment, found: %s.\n" % ( ev.getId(), str(len(comments) )) ) if len(comments) != 1: enum_comment_errors.append ("enumerated value %s: Expected 1 rdfs:comment, found: %s.\n %s" % (e.id, len(comments), andstr.join(comments) ) ) log.debug("enum comment count: "+ str(len(enum_comment_errors))) self.assertTrue(len(enum_comment_errors)==0, "Comment count enumeration errors. Aggregated: \n\n" + " \n".join(enum_comment_errors))
def test_gotThing(self): thing = VTerm.getTerm("Thing") if thing is None: gotThing = False else: gotThing = True self.assertEqual( gotThing, True, "Thing node should be accessible via GetUnit('Thing').")
def test_propCommentCount(self): prop_comment_errors=[] for p in VTerm.getAllProperties(): comments = p.getComments() log.debug("property %s props %s" % (p.getId(), str(len(comments)) )) if len(comments) != 1: prop_comment_errors.append ("property '%s': Expected 1 rdfs:comment, found: %s.\n %s" % (p.getId(), len(comments), andstr.join(comments) ) ) log.debug("property comment count: %s\n" % str(len(prop_comment_errors))) self.assertEqual(len(prop_comment_errors), 0, "Comment count property errors. Aggregated: \n\n" + " \n\n".join(prop_comment_errors))
def test_typeCommentCount(self): type_comment_errors=[] for t in VTerm.getAllTypes(): comments = t.getComments() log.debug(t.getId() + " " + str(len(comments))) if len(comments) != 1: type_comment_errors.append ("type '%s': Expected 1 rdfs:comment, found: %s.\n %s" % (t.getId(), len(comments), andstr.join(comments) ) ) log.debug("type comment count: "+ str(len(type_comment_errors))) self.assertTrue(len(type_comment_errors)==0, "Comment count type errors. Aggregated: \n" + " \n\n".join(type_comment_errors))
def test_gotFooBarThing(self): foobar = VTerm.getTerm("FooBar") if foobar is None: gotFooBar = False else: gotFooBar = True self.assertEqual( gotFooBar, False, "Thing node should NOT be accessible via GetUnit('FooBar').")
def test_DataTypeSupertypeDataType(self): tDataType = VTerm.getTerm("DataType") self.assertTrue(tDataType.subClassOf(tDataType), "DataType subClassOf DataType.")
def test_NewsArticleSupertypeArticle(self): tNewsArticle = VTerm.getTerm("NewsArticle") tArticle = VTerm.getTerm("Article") self.assertFalse(tArticle.subClassOf(tNewsArticle), "Article is not a sub-type of NewsArticle")
def test_EnumerationIsEnumeration(self): eEnumeration = VTerm.getTerm("Enumeration") self.assertTrue(eEnumeration.isEnumeration(), "Enumeration is an Enumeration type.")
def test_answerSubpropertiesArrayLen(self): p_suggestedAnswer = VTerm.getTerm("suggestedAnswer") log.info("suggestedAnswer array: " + str(p_suggestedAnswer.getSubs())) self.assertEqual(p_suggestedAnswer.getSubs(), 0, "answer subproperties() gives array of len 1.")
def test_EventCancelledIsEnumerationValue(self): eEventCancelled = VTerm.getTerm("EventCancelled") self.assertTrue(eEventCancelled.isEnumerationValue(), "EventCancelled is an Enumeration value.")
def test_answerSubpropertiesArrayLen(self): p_offers = VTerm.getTerm("offers") self.assertEqual(len(p_offers.getSubs()), 0, "offers subproperties() gives array of len 0.")
def test_GetImmediateSubtypesWrong(self): tArticle = VTerm.getTerm("CreativeWork") self.assertFalse( VTerm.getTerm("NewsArticle") in tArticle.getSubs(), "CreativeWork is not in immediate subtypes of Article.")
def test_answerSubproperties(self): p_suggestedAnswer = VTerm.getTerm("suggestedAnswer") p_acceptedAnswer = VTerm.getTerm("acceptedAnswer") self.assertTrue(p_acceptedAnswer == p_suggestedAnswer.getSubs()[0], "suggestedAnswer subproperties(), acceptedAnswer in 0th element of array.")
def test_answerSubpropertiesArrayLen(self): p_suggestedAnswer = VTerm.getTerm("suggestedAnswer") log.info("suggestedAnswer array: "+ str(p_suggestedAnswer.getSubs() )) self.assertEqual(p_suggestedAnswer.getSubs(), 0, "answer subproperties() gives array of len 1.")
def test_answerSubproperty(self): p_suggestedAnswer = VTerm.getTerm("suggestedAnswer") p_acceptedAnswer = VTerm.getTerm("acceptedAnswer") subs = p_suggestedAnswer.getSubs() self.assertTrue(p_acceptedAnswer in subs, "acceptedAnswer is a subPropertyOf suggestedAanswer.")
def test_acceptedAnswerSuperpropertiesArrayLen(self): p_acceptedAnswer = VTerm.getTerm("acceptedAnswer") aa_supers = p_acceptedAnswer.getSupers() for f in aa_supers: log.info("acceptedAnswer's subproperties(): %s" % f.id) self.assertTrue( len(aa_supers) == 1, "acceptedAnswer subproperties() gives array of len 1. Actual: %s ." % len(aa_supers) )
def test_offersNotSupersededByActor(self): p_actor = VTerm.getTerm("actor") p_offers = VTerm.getTerm("offers") self.assertFalse(p_offers in p_actor.getSupersedes(), "offers property doesn't supersede actors property.")
def test_actorNotSupersededByOffers(self): p_actor = VTerm.getTerm("actor") p_offers = VTerm.getTerm("offers") self.assertFalse(p_actor in p_offers.getSupersedes(), "actor property doesn't supersede offers property.")
def test_actorSupersedesActors(self): p_actor = VTerm.getTerm("actor") p_actors = VTerm.getTerm("actors") self.assertTrue(p_actors in p_actor.getSupersedes(), "actor supersedes actors.")
def test_PersonNotAttribute(self): tPerson = VTerm.getTerm("Person") self.assertFalse(tPerson.isProperty(), "Not true that Person isAttribute().")
def test_GetImmediateSubtypesWrong(self): tArticle = VTerm.getTerm("CreativeWork") self.assertFalse(VTerm.getTerm("NewsArticle") in tArticle.getSubs(), "CreativeWork is not in immediate subtypes of Article.")
def test_actorNotSuperseded(self): p_actor = VTerm.getTerm("actor") self.assertFalse(p_actor.superseded(), "actor property has not been superseded.")
def test_EventStatusTypeIsEnumeration(self): eEventStatusType = VTerm.getTerm("EventStatusType") self.assertTrue(eEventStatusType.isEnumeration(), "EventStatusType is an Enumeration.")
def test_EventStatusTypeIsntEnumerationValue(self): eEventStatusType = VTerm.getTerm("EventStatusType") self.assertFalse(eEventStatusType.isEnumerationValue(), "EventStatusType is not an Enumeration value.")
def test_dualPath(self): self.assertEqual( len( GetParentPathTo(VTerm.getTerm("Restaurant"), VTerm.getTerm("Thing"))), 2, "2 supertype paths from Restaurant to Thing.")
def test_ItemAvailabilityIsEnumeration(self): eItemAvailability = VTerm.getTerm("ItemAvailability") self.assertTrue(eItemAvailability.isEnumeration(), "ItemAvailability is an Enumeration.")
def test_EventTotallyFooBarIsntEnumerationValue(self): eEventCancelledFB = VTerm.getTerm("EventTotallyFooBar") if eEventCancelledFB is not None: self.assertFalse(eEventCancelledFB.isEnumerationValue(), "EventTotallyFooBar is not an Enumeration value, not even a node.") self.assertTrue(eEventCancelledFB is None, "EventTotallyFooBar should not resolve to a node.")
def test_ArticleSupertypeNewsArticle(self): tNewsArticle = VTerm.getTerm("NewsArticle") tArticle = VTerm.getTerm("Article") self.assertTrue(tNewsArticle.subClassOf(tArticle), "NewsArticle is a sub-type of Article")
def test_ThingNotSupertypePerson(self): tThing = VTerm.getTerm("Thing") tPerson = VTerm.getTerm("Person") self.assertFalse(tThing.subClassOf(tPerson), "Thing not subClassOf Person.")
def test_ThingSupertypeThing(self): tThing = VTerm.getTerm("Thing") self.assertTrue(tThing.subClassOf(tThing), "Thing subClassOf Thing.")
def test_StoresArePlaces(self): tStore = VTerm.getTerm("Store") tPlace = VTerm.getTerm("Place") self.assertTrue(tStore.subClassOf(tPlace), "Store subClassOf Place.")
def test_PersonSupertypeThing(self): tThing = VTerm.getTerm("Thing") tPerson = VTerm.getTerm("Person") self.assertTrue(tPerson.subClassOf(tThing), "Person subClassOf Thing.")
def test_offersNotSuperseded(self): p_offers = VTerm.getTerm("offers") self.assertFalse(p_offers.superseded(), "offers property has not been superseded.")
def test_StoreSupertypeLocalBusiness(self): tStore = VTerm.getTerm("Store") tLocalBusiness = VTerm.getTerm("LocalBusiness") self.assertTrue(tStore.subClassOf(tLocalBusiness), "Store subClassOf LocalBusiness.")
def test_actorsSuperseded(self): p_actors = VTerm.getTerm("actors") self.assertTrue(p_actors.superseded(), "actors property has been superseded.")
def test_StoresAreOrganizations(self): tStore = VTerm.getTerm("Store") tOrganization = VTerm.getTerm("Organization") self.assertTrue(tStore.subClassOf(tOrganization), "Store subClassOf Organization.")
def test_GetImmediateSubtypesOk(self): tArticle = VTerm.getTerm("Article") self.assertTrue( VTerm.getTerm("NewsArticle") in tArticle.getSubs(), "NewsArticle is in immediate subtypes of Article.")
def test_booleanDataType(self): self.assertTrue(VTerm.getTerm("Boolean").isDataType()) self.assertTrue(VTerm.getTerm("DataType").isDataType()) self.assertFalse(VTerm.getTerm("Thing").isDataType()) self.assertFalse(VTerm.getTerm("Duration").isDataType())
def test_html_tree(self): uThing = VTerm.getTerm("Thing") mainroot = TypeHierarchyTree("local_label") mainroot.traverseForHTML(uThing, layers="core", idprefix="C.") html = mainroot.toHTML() self.assertTrue( html != None and len(html) > 0, "traverseForHTML should return content")
def test_jsonld_tree(self): uThing = VTerm.getTerm("Thing") mainroot = TypeHierarchyTree() mainroot.traverseForJSONLD(uThing, layers="core") thing_tree = mainroot.toJSON() self.assertTrue( thing_tree != None and len(thing_tree) > 0, "traverseForJSONLD should return content")
def test_simplePath(self): self.assertEqual( len( GetParentPathTo(VTerm.getTerm("CreativeWork"), VTerm.getTerm("Thing")) ), 1, "1 supertype path from CreativeWork to Thing." )
def test_dualPath(self): self.assertEqual( len( GetParentPathTo(VTerm.getTerm("Restaurant"), VTerm.getTerm("Thing")) ), 2, "2 supertype paths from Restaurant to Thing." )
def test_inverseDualPath(self): self.assertEqual( len( GetParentPathTo(VTerm.getTerm("Thing"), VTerm.getTerm("Restaurant")) ), 0, "0 supertype paths from Thing to Restaurant." )
def test_inverseDualPath(self): self.assertEqual( len( GetParentPathTo(VTerm.getTerm("Thing"), VTerm.getTerm("Restaurant"))), 0, "0 supertype paths from Thing to Restaurant.")
def test_QuantityisClass(self): tQuantity = VTerm.getTerm("Quantity") self.assertTrue(tQuantity.isClass(), "Quantity is a class.")