Ejemplo n.º 1
0
    def test_set_collection(self):
        # initialize with no collection
        xq = Xquery(xpath='/el')
        xq.set_collection('coll')
        self.assertEqual('collection("/db/coll")/el', xq.getQuery())

        # initialize with one collection, then switch
        xq = Xquery(collection='coll1')
        xq.set_collection('coll2')
        self.assertEqual('collection("/db/coll2")/node()', xq.getQuery())

        # leading slash is ok too
        xq.set_collection('/coll3')
        self.assertEqual('collection("/db/coll3")/node()', xq.getQuery())

        # set to None
        xq.set_collection(None)
        self.assertEqual('/node()', xq.getQuery())
Ejemplo n.º 2
0
 def test_document(self):
     xq = Xquery(xpath='/el', document="/db/coll/file.xml")
     self.assertEqual('doc("/db/coll/file.xml")/el', xq.getQuery())
     # document takes precedence over collection
     xq.set_collection('coll')  # should be ignored
     self.assertEqual('doc("/db/coll/file.xml")/el', xq.getQuery())