Exemple #1
0
 def testOutputResultXML(self):
     class testOptions(object):
         verbose        = False
         output         = None
         format_var_out = "XML"
     options  = testOptions()
     result = (
         { "head":    { "vars": ["s", "p", "o"] }
         , "results": 
           { "bindings": 
             [ { 's': { 'type': "bnode", 'value': "nodeid" }
               , 'p': { 'type': "uri", 'value': "http://example.org/test#p1" }
               , 'o': { 'type': "literal", 'value': "literal string" }
               }
             ]
           }
         })
     teststr = StringIO.StringIO()
     with SwitchStdout(teststr):
         asqc.outputResult("asqc", options, result)
         testtxt = teststr.getvalue()
     log.debug("testOutputResultXML \n"+testtxt)
     assert """<binding name="s">""" in testtxt
     assert """<bnode>nodeid</bnode>""" in testtxt
     assert """<binding name="p">""" in testtxt
     assert """<uri>http://example.org/test#p1</uri>""" in testtxt
     assert """<binding name="o">""" in testtxt
     assert """<literal>literal string</literal>""" in testtxt
     return
Exemple #2
0
 def testOutputResultJSON(self):
     class testOptions(object):
         verbose        = False
         output         = None
         format_var_out = None
     options  = testOptions()
     result = (
         { "head":    { "vars": ["s", "p", "o"] }
         , "results": 
           { "bindings": 
             [ { 's': { 'type': "uri", 'value': "http://example.org/test#s1" }
               , 'p': { 'type': "uri", 'value': "http://example.org/test#p1" }
               , 'o': { 'type': "uri", 'value': "http://example.org/test#o1" }
               }
             ]
           }
         })
     teststr = StringIO.StringIO()
     with SwitchStdout(teststr):
         asqc.outputResult("asqc", options, result)
         testtxt = teststr.getvalue()
     assert """"s": {"type": "uri", "value": "http://example.org/test#s1"}""" in testtxt
     assert """"p": {"type": "uri", "value": "http://example.org/test#p1"}""" in testtxt
     assert """"s": {"type": "uri", "value": "http://example.org/test#s1"}""" in testtxt
     return
Exemple #3
0
 def testOutputResultCSV(self):
     class testOptions(object):
         verbose        = False
         output         = None
         format_var_out = "CSV"
     options  = testOptions()
     result = (
         { "head":    { "vars": ["s", "p", "o"] }
         , "results": 
           { "bindings": 
             [ { 's': { 'type': "bnode", 'value': "nodeid" }
               , 'p': { 'type': "uri", 'value': "http://example.org/test#p1" }
               , 'o': { 'type': "literal", 'value': """literal '"' '\u00e9' string""" }
               }
             ]
           }
         })
     teststr = StringIO.StringIO()
     with SwitchStdout(teststr):
         asqc.outputResult("asqc", options, result)
         testtxt = teststr.getvalue()
     log.debug("testOutputResultCSV \n"+testtxt)
     log.debug("testOutputResultCSV \n"+repr(testtxt))
     assert """s, p, o""" in testtxt
     assert r'''_:nodeid, <http://example.org/test#p1>, "literal '""' '\u00e9' string"''' in testtxt
     return
Exemple #4
0
 def testOutputResultRDFXML(self):
     class testOptions(object):
         verbose        = False
         output         = None
         format_rdf_out = None
     options  = testOptions()
     result = rdflib.Graph()
     result.add(
         ( rdflib.URIRef("http://example.org/test#s1")
         , rdflib.URIRef("http://example.org/test#p1")
         , rdflib.URIRef("http://example.org/test#o1")
         ) )
     teststr = StringIO.StringIO()
     with SwitchStdout(teststr):
         asqc.outputResult("asqc", options, result)
         testtxt = teststr.getvalue()
     assert """<rdf:Description rdf:about="http://example.org/test#s1">""" in testtxt
     return
Exemple #5
0
 def testOutputResultRDFN3(self):
     class testOptions(object):
         verbose        = False
         output         = None
         format_rdf_out = "N3"
     options  = testOptions()
     result = rdflib.Graph()
     result.add(
         ( rdflib.URIRef("http://example.org/test#s1")
         , rdflib.URIRef("http://example.org/test#p1")
         , rdflib.URIRef("http://example.org/test#o1")
         ) )
     teststr = StringIO.StringIO()
     with SwitchStdout(teststr):
         asqc.outputResult("asqc", options, result)
         testtxt = teststr.getvalue()
     log.debug("testOutputResultRDFN3 \n"+testtxt)
     assert """ns1:s1 ns1:p1 ns1:o1 .""" in testtxt
     return
Exemple #6
0
 def testOutputResultTemplate(self):
     class testOptions(object):
         verbose        = False
         output         = None
         format_var_out = "s: %(s_repr)s p: <%(p)s> o: %(o_repr)s ."
     options  = testOptions()
     result = (
         { "head":    { "vars": ["s", "p", "o"] }
         , "results": 
           { "bindings": 
             [ { 's': { 'type': "bnode", 'value': "nodeid" }
               , 'p': { 'type': "uri", 'value': "http://example.org/test#p1" }
               , 'o': { 'type': "literal", 'value': "literal string" }
               }
             ]
           }
         })
     teststr = StringIO.StringIO()
     with SwitchStdout(teststr):
         asqc.outputResult("asqc", options, result)
         testtxt = teststr.getvalue()
     log.debug("testOutputResultTemplate \n"+testtxt)
     assert """s: _:nodeid p: <http://example.org/test#p1> o: "literal string" .""" in testtxt
     return