def test_get_root_type_datatype(self): number = { '@id': schema_org_id('Number'), '@type': [schema_org_id('DataType'), 'rdfs:Class'] } integer = {'@id': schema_org_id('Integer'), 'rdfs:subClassOf': number} schema = {'@graph': [integer, number]} self.assertEqual( generate_schema_org_code.get_root_type(integer, schema), number)
def test_get_root_type_datatype(self): text = { '@id': schema_org_id('Text'), '@type': [schema_org_id('DataType'), 'rdfs:Class'] } url = {'@id': schema_org_id('URL'), 'rdfs:subClassOf': text} schema = {'@graph': [url, text]} self.assertEqual( generate_schema_org_code.get_root_type(url, schema), text)
def test_get_root_type_thing(self): thing = {'@id': schema_org_id('Thing')} intangible = { '@id': schema_org_id('Intangible'), 'rdfs:subClassOf': thing } structured_value = { '@id': schema_org_id('StructuredValue'), 'rdfs:subClassOf': intangible } schema = {'@graph': [thing, intangible, structured_value]} self.assertEqual( generate_schema_org_code.get_root_type(structured_value, schema), thing)
def test_lookup_parents(self): thing = {'@id': schema_org_id('Thing')} intangible = { '@id': schema_org_id('Intangible'), 'rdfs:subClassOf': thing } structured_value = { '@id': schema_org_id('StructuredValue'), 'rdfs:subClassOf': intangible } brand = {'@id': schema_org_id('Brand'), 'rdfs:subClassOf': intangible} schema = {'@graph': [thing, intangible, structured_value, brand]} self.assertListEqual( generate_schema_org_code.lookup_parents(brand, schema, {}), ['Thing', 'Intangible', 'Brand'])
def test_get_root_type_enum(self): thing = {'@id': schema_org_id('Thing')} intangible = { '@id': schema_org_id('Intangible'), 'rdfs:subClassOf': thing } enumeration = { '@id': schema_org_id('Enumeration'), 'rdfs:subClassOf': intangible } actionStatusType = { '@id': schema_org_id('ActionStatusType'), 'rdfs:subClassOf': enumeration } schema = {'@graph': [thing, intangible, enumeration, actionStatusType]} self.assertEqual( generate_schema_org_code.get_root_type(actionStatusType, schema), actionStatusType)
def test_parse_property_identifier(self): thing = {'@id': schema_org_id('Thing')} intangible = { '@id': schema_org_id('Intangible'), 'rdfs:subClassOf': thing } structured_value = { '@id': schema_org_id('StructuredValue'), 'rdfs:subClassOf': intangible } property_value = { '@id': schema_org_id('PropertyValue'), 'rdfs:subClassOf': structured_value } number = { '@id': schema_org_id('Number'), '@type': [schema_org_id('DataType'), 'rdfs:Class'] } integer = {'@id': schema_org_id('Integer'), 'rdfs:subClassOf': number} identifier = { '@id': schema_org_id('Identifier'), schema_org_id('rangeIncludes'): [property_value, integer, number] } schema = { '@graph': [ thing, intangible, structured_value, property_value, number, integer, identifier ] } names = {"http://schema.org/Identifier": 1234, "Identifier": 1235} self.assertEqual( generate_schema_org_code.parse_property(identifier, schema, names), { 'name': 'Identifier', 'name_hash': 1235, 'has_number': True, 'thing_types': [property_value['@id']], 'enum_types': [] })
def test_parse_property_identifier(self): thing = {'@id': schema_org_id('Thing')} intangible = { '@id': schema_org_id('Intangible'), 'rdfs:subClassOf': thing } structured_value = { '@id': schema_org_id('StructuredValue'), 'rdfs:subClassOf': intangible } property_value = { '@id': schema_org_id('PropertyValue'), 'rdfs:subClassOf': structured_value } text = { '@id': schema_org_id('Text'), '@type': [schema_org_id('DataType'), 'rdfs:Class'] } url = {'@id': schema_org_id('URL'), 'rdfs:subClassOf': text} identifier = { '@id': schema_org_id('Identifier'), schema_org_id('rangeIncludes'): [property_value, url, text] } schema = { '@graph': [ thing, intangible, structured_value, property_value, text, url, identifier ] } self.assertEqual( generate_schema_org_code.parse_property(identifier, schema), { 'name': 'Identifier', 'has_text': True, 'thing_types': [property_value['@id']] })