def test_map_one_float(self): en = EIONET_RDF + '/languages/en' self._test('lang_url:float', {'lang_url': '1.23'}, {'lang_url': sparql.Literal('1.23', sparql.XSD_FLOAT)})
def test_literal(self): """ Notation3 representation of a literal """ for value, expected in _literal_data: self.assertEqual(sparql.Literal(value).n3(), expected) self.assertEqual(sparql.Literal(value, lang='en').n3(), expected+'@en')
def test_literal_notsame2(self): """ Difference on both value and language """ l1 = sparql.Literal(u"Hello world",u"http://aims.fao.org/aos/geopolitical.owl#MillionUSD") l2 = sparql.Literal(u"Hallo Welt",u"http://aims.fao.org/aos/geopolitical.owl#MillionUSD") self.assertNotEqual(l1, l2)
def test_literal_notsame3(self): """ Two literals with same language must be the same """ l1 = sparql.Literal(u"Hello world",u"http://aims.fao.org/aos/geopolitical.owl#MillionUSD") self.assertNotEqual(u"Hello world", l1) self.assertNotEqual(l1, u"Hello world") assert l1 != u"Hello world"
def test_isinstance(self): """ Type literals are instances of RDFTerm """ l = sparql.Literal(u"Hello world",u"http://www.w3.org/2001/XMLSchema#string") assert isinstance(l, sparql.RDFTerm)
def test_str(self): """ str should return the literal without type """ l = sparql.Literal(u"Hello world",u"http://www.w3.org/2001/XMLSchema#string") assert str(l) == u"Hello world"
def test_length(self): result = self.do_query([ [sparql.Literal("tomato")], [sparql.Literal("apple")], ]) self.assertEqual(len(result), 2)
def test_literal_notsame3(self): """ Two literals with same language must be the same """ l1 = sparql.Literal(u"Hello world",lang=u"en") self.assertNotEqual(u"Hello world", l1) self.assertNotEqual(l1, u"Hello world")
def test_getitem(self): result = self.do_query([[sparql.Literal("hello")]]) self.assertEqual(result[0][0], "hello")
def test_iter(self): result = self.do_query([[sparql.Literal("hello")]]) self.assertEqual(iter(result).next()[0], "hello")
def test_var_names(self): result = self.do_query([[sparql.Literal("hello")]]) self.assertEqual(result.var_names, ["o"])
def test_one_literal(self): self._test("SELECT * WHERE { ?s ?p ${value} }", {'value': sparql.Literal("Joe")}, 'SELECT * WHERE { ?s ?p "Joe" }')
def test_map_one_parsed_typed_literal(self): en = EIONET_RDF + '/languages/en' self._test('lang_url:n3term', {'lang_url': '"12:33"^^<' + sparql.XSD_TIME + '>'}, {'lang_url': sparql.Literal('12:33', sparql.XSD_TIME)})
def test_typed_literal(self): """ N3 notation of a typed literal """ datatype = u"http://www.w3.org/2001/XMLSchema#string" for value, expected in _literal_data: tl = sparql.Literal(value, datatype) self.assertEqual(tl.n3(), '%s^^<%s>' % (expected, datatype))
def test_one_literal(self): self._test(u"SELECT * WHERE { ?s ?p ${value} }", {'value': sparql.Literal("Joe", None)}, u"SELECT * WHERE { ?s ?p 'Joe' }")
def test_literal_notsame2(self): """ Difference on both value and language """ l1 = sparql.Literal(u"Hello world",lang=u"en") l2 = sparql.Literal(u"Hallo Welt",lang=u"de") self.assertNotEqual(l1, l2)
def test_query_with_arguments(self): self.query.query = mock_db.GET_LANG_BY_NAME result = self.query.execute(lang_name=sparql.Literal("Danish")) danish_iri = sparql.IRI(EIONET_RDF + '/languages/da') self.assertEqual(list(result), [(danish_iri, )])
def test_repr(self): """ repr should return the literal in N3 syntax """ l = sparql.Literal(u"Hello world") self.assertEqual(u'<Literal "Hello world">', repr(l))
def test_map_one_literal(self): self._test(u'name:string', {'name': u"Joe"}, {'name': sparql.Literal(u"Joe", None)})
def test_repr(self): """ repr should return the literal in N3 syntax """ l = sparql.Literal(u"Hello world",u"http://www.w3.org/2001/XMLSchema#string") self.assertEqual(u'<Literal "Hello world"^^<http://www.w3.org/2001/XMLSchema#string>>', repr(l))
def test_literal_notsame1(self): """ Two literals different language must be different """ l1 = sparql.Literal(u'Hello world', lang=u'en') l2 = sparql.Literal(u'Hello world', lang=u'en-US') self.assertNotEqual(l1, l2)
def test_literal_notsame1(self): """ Two literals different language must be different """ l1 = sparql.Literal(u"Hello world",u"http://aims.fao.org/aos/geopolitical.owl#MillionUSD") l2 = sparql.Literal(u"Hello world",u"http://www.w3.org/2001/XMLSchema#string") self.assertNotEqual(l1, l2)
def test_literal_notsame2(self): """ Difference on both value and language """ l1 = sparql.Literal(u'Hello world', lang=u'en') l2 = sparql.Literal(u'Hallo Welt', lang=u'de') self.assertNotEqual(l1, l2)
def test_literal_same(self): """ Two literals with same language must be the same """ l1 = sparql.Literal(u"Hello world",lang=u"en") l2 = sparql.Literal(u"Hello world",lang=u"en") self.assertEqual(l1, l2)
def test_literal_notsame1(self): """ Two literals different language must be different """ l1 = sparql.Literal(u"Hello world",lang=u"en") l2 = sparql.Literal(u"Hello world",lang=u"en-US") self.assertNotEqual(l1, l2)
if e.code == 28: raise QueryTimeout result['exception'] = e.message except Exception, e: result['exception'] = traceback.format_exc() else: result['result'] = ret return result RDF_TERM_FACTORY = { 'n3term': sparql.parse_n3_term, 'iri': sparql.IRI, 'string': sparql.Literal, 'integer': lambda v: sparql.Literal(v, sparql.XSD_INTEGER), 'long': lambda v: sparql.Literal(v, sparql.XSD_LONG), 'double': lambda v: sparql.Literal(v, sparql.XSD_DOUBLE), 'float': lambda v: sparql.Literal(v, sparql.XSD_FLOAT), 'decimal': lambda v: sparql.Literal(v, sparql.XSD_DECIMAL), 'datetime': lambda v: sparql.Literal(v, sparql.XSD_DATETIME), 'date': lambda v: sparql.Literal(v, sparql.XSD_DATE), 'time': lambda v: sparql.Literal(v, sparql.XSD_TIME), 'boolean': lambda v: sparql.Literal(v, sparql.XSD_BOOLEAN), } def parse_arg_spec(raw_arg_spec): """ Parse the arguments for a ZSPARQLMethod. `raw_arg_spec` should be a space-separated string of variable definitions in the format
def test_map_one_literal(self): self._test('name:string', {'name': "Joe"}, {'name': sparql.Literal("Joe")})