def Test(tester): tester.startGroup('Exercise namespace nodes') isrc = InputSource.DefaultFactory.fromString(SRC_1, Uri.OsPathToUri(os.getcwd())) doc = NonvalidatingReader.parse(isrc) con = Context.Context(doc, 1, 1) EXPR = '//namespace::node()' expr = Compile(EXPR) #expr is <AbbreviatedAbsoluteLocationPath: /descendant-or-self::node()/namespace::node()> #expr._rel is <Step: namespace::node()> #expr._step is <Step: descendant-or-self::node()> tester.startTest(EXPR) actual = expr.evaluate(con) tester.compare(7, len(actual)) tester.testDone() EXPR = '//node()/namespace::node()' expr = Compile(EXPR) tester.startTest(EXPR) EXPECTED = [] actual = expr.evaluate(con) tester.compare(7, len(actual)) tester.testDone() EXPR = '//*/namespace::node()' expr = Compile(EXPR) tester.startTest(EXPR) EXPECTED = [] actual = expr.evaluate(con) tester.compare(7, len(actual)) tester.testDone() EXPR = '/*/*/namespace::node()' expr = Compile(EXPR) tester.startTest(EXPR) EXPECTED = [] actual = expr.evaluate(con) tester.compare(6, len(actual)) tester.testDone() EXPR = '/*/namespace::node()|/*/*/namespace::node()' expr = Compile(EXPR) tester.startTest(EXPR) EXPECTED = [] actual = expr.evaluate(con) tester.compare(7, len(actual)) tester.testDone() EXPR = '//*' expr = Compile(EXPR) #expr is <AbbreviatedAbsoluteLocationPath: /descendant-or-self::node()/child::*> tester.startTest(EXPR) EXPECTED = [] actual = expr.evaluate(con) tester.compare(4, len(actual)) tester.testDone() return tester.groupDone()
def Test(tester): tester.startGroup('Exercise namespace nodes') isrc = InputSource.DefaultFactory.fromString(SRC_1, Uri.OsPathToUri(os.getcwd())) doc = NonvalidatingReader.parse(isrc) con = Context.Context(doc, 1, 1) EXPR = '//namespace::node()' expr = Compile(EXPR) #expr is <AbbreviatedAbsoluteLocationPath: /descendant-or-self::node()/namespace::node()> #expr._rel is <Step: namespace::node()> #expr._step is <Step: descendant-or-self::node()> tester.startTest(EXPR) actual = expr.evaluate(con) tester.compare(7, len(actual)) tester.testDone() EXPR = '//node()/namespace::node()' expr = Compile(EXPR) tester.startTest(EXPR) EXPECTED = [] actual = expr.evaluate(con) tester.compare(7, len(actual)) tester.testDone() EXPR = '//*/namespace::node()' expr = Compile(EXPR) tester.startTest(EXPR) EXPECTED = [] actual = expr.evaluate(con) tester.compare(7, len(actual)) tester.testDone() EXPR = '/*/*/namespace::node()' expr = Compile(EXPR) tester.startTest(EXPR) EXPECTED = [] actual = expr.evaluate(con) tester.compare(6, len(actual)) tester.testDone() EXPR = '/*/namespace::node()|/*/*/namespace::node()' expr = Compile(EXPR) tester.startTest(EXPR) EXPECTED = [] actual = expr.evaluate(con) tester.compare(7, len(actual)) tester.testDone() EXPR = '//*' expr = Compile(EXPR) #expr is <AbbreviatedAbsoluteLocationPath: /descendant-or-self::node()/child::*> tester.startTest(EXPR) EXPECTED = [] actual = expr.evaluate(con) tester.compare(4, len(actual)) tester.testDone() return tester.groupDone()
def Test(tester): tester.startGroup('CDATA sections in doc') isrc = InputSource.DefaultFactory.fromString(SRC_1, Uri.OsPathToUri(os.getcwd())) doc = NonvalidatingReader.parse(isrc) con = Context.Context(doc, 1, 1) EXPR = '/doc/elem/text()' expr = Compile(EXPR) tester.startTest(EXPR) actual = [ node.data for node in expr.evaluate(con) ] tester.compare(actual, ["abc"]*3) tester.testDone() return tester.groupDone()
def Test(tester): tester.startGroup('CDATA sections in doc') isrc = InputSource.DefaultFactory.fromString(SRC_1, Uri.OsPathToUri(os.getcwd())) doc = NonvalidatingReader.parse(isrc) con = Context.Context(doc, 1, 1) EXPR = '/doc/elem/text()' expr = Compile(EXPR) tester.startTest(EXPR) actual = [node.data for node in expr.evaluate(con)] tester.compare(actual, ["abc"] * 3) tester.testDone() return tester.groupDone()
def fetch(params, debug=None,nopost=None): if(not params.has_key('resultxpath')): return None xhtml=send(params,debug,nopost) if debug: print >> sys.stderr, 'checking results' # make it a 4suite document doc = NonvalidatingReader.parseString(xhtml,params['action']) context = Context(doc, processorNss={"h": XHTML_NS}) #Compute the XPath against the context results=Compile(params['resultxpath']) results=results.evaluate(context) res=[] for a in results: tf = cStringIO.StringIO() PrettyPrint(a,tf) t=tf.getvalue() res.append(t) tf.close() results=res if debug: print >> sys.stderr, 'done', params['action'] return (results, xhtml)
def fetch(params, debug=None, nopost=None): if (not params.has_key('resultxpath')): return None xhtml = send(params, debug, nopost) if debug: print >> sys.stderr, 'checking results' # make it a 4suite document doc = NonvalidatingReader.parseString(xhtml, params['action']) context = Context(doc, processorNss={"h": XHTML_NS}) #Compute the XPath against the context results = Compile(params['resultxpath']) results = results.evaluate(context) res = [] for a in results: tf = cStringIO.StringIO() PrettyPrint(a, tf) t = tf.getvalue() res.append(t) tf.close() results = res if debug: print >> sys.stderr, 'done', params['action'] return (results, xhtml)