class TestTypedLiteralType(unittest.TestCase): def setUp(self): self.type = TypedLiteralType() self.string_type = TypedLiteralType(XSD.string) self.literal_descriptor = self.string_type.literal() self.context = Context() def test_matches_only_typed_literals(self): self.assertFalse(BlankNode() in self.type) self.assertFalse(URI('test') in self.type) self.assertFalse(PlainLiteral('1.5') in self.type) self.assertFalse(PlainLiteral('1.5', 'en') in self.type) self.assert_(TypedLiteral('1.5', XSD.float) in self.type) self.assert_(TypedLiteral('1.5', XSD.string) in self.type) def test_datatype_contrains_matched_literals(self): self.assertFalse(TypedLiteral('1.5', XSD.float) in self.string_type) self.assert_(TypedLiteral('1.5', XSD.string) in self.string_type) def test_has_datatype_type_descriptor(self): self.assert_(isinstance(self.type.datatype, TypeDescriptor)) self.assert_(self.type.datatype is self.type.ddd) def test_calling_datatype_with_instance_returns_datatype(self): literal = TypedLiteral('1.5', XSD.float) self.assertEqual(self.type.datatype(literal, self.context), XSD.float) def test_calling_literal_returns_descriptor(self): self.assert_(isinstance(self.literal_descriptor, TypeDescriptor)) def test_calling_literal_descriptor_returns_plain_literal(self): literal = TypedLiteral('1.5', XSD.float) self.assertEqual(self.literal_descriptor(literal, self.context), PlainLiteral('1.5')) def test_calling_literal_descriptor_with_datatype_returns_typed_literal(self): literal = PlainLiteral('1.5') literal_descriptor = self.string_type.literal(XSD.decimal) self.assertEqual(literal_descriptor(literal, self.context), TypedLiteral('1.5', XSD.decimal))
def setUp(self): self.type = TypedLiteralType() self.string_type = TypedLiteralType(XSD.string) self.literal_descriptor = self.string_type.literal() self.context = Context()