<s> from twisted . trial import unittest <EOL> from twisted . words . xish . domish import Element <EOL> from twisted . words . xish . xpath import XPathQuery <EOL> from twisted . words . xish import xpath <EOL> class XPathTests ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . e = Element ( ( "<STR_LIT>" , "<STR_LIT:foo>" ) ) <EOL> self . e [ "<STR_LIT>" ] = "<STR_LIT>" <EOL> self . e [ "<STR_LIT>" ] = "<STR_LIT>" <EOL> self . e . addContent ( "<STR_LIT>" ) <EOL> self . bar1 = self . e . addElement ( "<STR_LIT:bar>" ) <EOL> self . subfoo = self . bar1 . addElement ( "<STR_LIT:foo>" ) <EOL> self . gar1 = self . subfoo . addElement ( "<STR_LIT>" ) <EOL> self . gar1 . addContent ( "<STR_LIT>" ) <EOL> self . e . addContent ( "<STR_LIT>" ) <EOL> self . bar2 = self . e . addElement ( "<STR_LIT:bar>" ) <EOL> self . bar2 [ "<STR_LIT>" ] = "<STR_LIT>" <EOL> self . bar3 = self . bar2 . addElement ( "<STR_LIT:bar>" ) <EOL> self . subfoo2 = self . bar3 . addElement ( "<STR_LIT:foo>" ) <EOL> self . gar2 = self . bar3 . addElement ( "<STR_LIT>" ) <EOL> self . gar2 . addContent ( "<STR_LIT>" ) <EOL> self . bar4 = self . e . addElement ( "<STR_LIT:bar>" ) <EOL> self . bar5 = self . e . addElement ( "<STR_LIT:bar>" ) <EOL> self . bar5 [ "<STR_LIT>" ] = "<STR_LIT>" <EOL> self . bar5 [ "<STR_LIT>" ] = "<STR_LIT>" <EOL> self . subfoo3 = self . bar5 . addElement ( "<STR_LIT:foo>" ) <EOL> self . gar3 = self . bar5 . addElement ( "<STR_LIT>" ) <EOL> self . gar3 . addContent ( "<STR_LIT>" ) <EOL> self . bar6 = self . e . addElement ( "<STR_LIT:bar>" ) <EOL> self . bar6 [ "<STR_LIT>" ] = "<STR_LIT>" <EOL> self . bar6 [ "<STR_LIT>" ] = "<STR_LIT>" <EOL> self . subfoo4 = self . bar6 . addElement ( "<STR_LIT:foo>" ) <EOL> self . gar4 = self . bar6 . addElement ( "<STR_LIT>" ) <EOL> self . gar4 . addContent ( "<STR_LIT>" ) <EOL> self . bar7 = self . e . addElement ( "<STR_LIT:bar>" ) <EOL> self . bar7 [ "<STR_LIT>" ] = "<STR_LIT>" <EOL> self . bar7 [ "<STR_LIT>" ] = "<STR_LIT>" <EOL> def test_staticMethods ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertEqual ( xpath . matches ( "<STR_LIT>" , self . e ) , <EOL> True ) <EOL> self . assertEqual ( xpath . queryForNodes ( "<STR_LIT>" , self . e ) , <EOL> [ self . bar1 , self . bar2 , self . bar4 , <EOL> self . bar5 , self . bar6 , self . bar7 ] ) <EOL> self . assertEqual ( xpath . queryForString ( "<STR_LIT>" , self . e ) , <EOL> "<STR_LIT>" ) <EOL> self . assertEqual ( xpath . queryForStringList ( "<STR_LIT>" , self . e ) , <EOL> [ "<STR_LIT>" , "<STR_LIT>" ] ) <EOL> def test_locationFooBar ( self ) : <EOL> """<STR_LIT>""" <EOL> xp = XPathQuery ( "<STR_LIT>" ) <EOL> self . assertEqual ( xp . matches ( self . e ) , <NUM_LIT:1> ) <EOL> def test_locationFooBarFoo ( self ) : <EOL> """<STR_LIT>""" <EOL> xp = XPathQuery ( "<STR_LIT>" ) <EOL> self . assertEqual ( xp . matches ( self . e ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( xp . queryForNodes ( self . e ) , [ self . subfoo , <EOL> self . subfoo3 , <EOL> self . subfoo4 ] ) <EOL> def test_locationNoBar3 ( self ) : <EOL> """<STR_LIT>""" <EOL> xp = XPathQuery ( "<STR_LIT>" ) <EOL> self . assertEqual ( xp . matches ( self . e ) , <NUM_LIT:0> ) <EOL> def test_locationAllChilds ( self ) : <EOL> """<STR_LIT>""" <EOL> xp = XPathQuery ( "<STR_LIT>" ) <EOL> self . assertEqual ( xp . matches ( self . e ) , True ) <EOL> self . assertEqual ( xp . queryForNodes ( self . e ) , [ self . bar1 , self . bar2 , <EOL> self . bar4 , self . bar5 , <EOL> self . bar6 , self . bar7 ] ) <EOL> def test_attribute ( self ) : <EOL> """<STR_LIT>""" <EOL> xp = XPathQuery ( "<STR_LIT>" ) <EOL> self . assertEqual ( xp . matches ( self . e ) , True ) <EOL> def test_attributeWithValueAny ( self ) : <EOL> """<STR_LIT>""" <EOL> xp = XPathQuery ( "<STR_LIT>" ) <EOL> self . assertEqual ( xp . matches ( self . e ) , True ) <EOL> self . assertEqual ( xp . queryForNodes ( self . e ) , [ self . bar2 ] ) <EOL> def test_position ( self ) : <EOL> """<STR_LIT>""" <EOL> xp = XPathQuery ( "<STR_LIT>" ) <EOL> self . assertEqual ( xp . matches ( self . e ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( xp . queryForNodes ( self . e ) , [ self . bar1 ] ) <EOL> test_position . todo = "<STR_LIT>" <EOL> def test_namespaceFound ( self ) : <EOL> """<STR_LIT>""" <EOL> xp = XPathQuery ( "<STR_LIT>" ) <EOL> self . assertEqual ( xp . matches ( self . e ) , <NUM_LIT:1> ) <EOL> def test_namespaceNotFound ( self ) : <EOL> """<STR_LIT>""" <EOL> xp = XPathQuery ( "<STR_LIT>" ) <EOL> self . assertEqual ( xp . matches ( self . e ) , <NUM_LIT:0> ) <EOL> def test_attributeWithValue ( self ) : <EOL> """<STR_LIT>""" <EOL> xp = XPathQuery ( "<STR_LIT>" ) <EOL> self . assertEqual ( xp . matches ( self . e ) , <NUM_LIT:1> ) <EOL> def test_queryForString ( self ) : <EOL> """<STR_LIT>""" <EOL> xp = XPathQuery ( "<STR_LIT>" ) <EOL> self . assertEqual ( xp . queryForString ( self . e ) , "<STR_LIT>" ) <EOL> self . assertEqual ( xp . queryForStringList ( self . e ) , <EOL> [ "<STR_LIT>" , "<STR_LIT>" ] ) <EOL> def test_queryForNodes ( self ) : <EOL> """<STR_LIT>""" <EOL> xp = XPathQuery ( "<STR_LIT>" ) <EOL> self . assertEqual ( xp . queryForNodes ( self . e ) , [ self . bar1 , self . bar2 , <EOL> self . bar4 , self . bar5 , <EOL> self . bar6 , self . bar7 ] ) <EOL> def test_textCondition ( self ) : <EOL> """<STR_LIT>""" <EOL> xp = XPathQuery ( "<STR_LIT>" ) <EOL> self . assertEqual ( xp . matches ( self . e ) , True ) <EOL> def test_textNotOperator ( self ) : <EOL> """<STR_LIT>""" <EOL> xp = XPathQuery ( "<STR_LIT>" ) <EOL> self . assertEqual ( xp . matches ( self . e ) , True ) <EOL> def test_anyLocationAndText ( self ) : <EOL> """<STR_LIT>""" <EOL> xp = XPathQuery ( "<STR_LIT>" ) <EOL> self . assertEqual ( xp . matches ( self . e ) , True ) <EOL> self . assertEqual ( xp . queryForNodes ( self . e ) , [ self . gar1 , self . gar2 , <EOL> self . gar3 , self . gar4 ] ) <EOL> self . assertEqual ( xp . queryForStringList ( self . e ) , [ "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" ] ) <EOL> def test_anyLocation ( self ) : <EOL> """<STR_LIT>""" <EOL> xp = XPathQuery ( "<STR_LIT>" ) <EOL> self . assertEqual ( xp . matches ( self . e ) , True ) <EOL> self . assertEqual ( xp . queryForNodes ( self . e ) , [ self . bar1 , self . bar2 , <EOL> self . bar3 , self . bar4 , <EOL> self . bar5 , self . bar6 , <EOL> self . bar7 ] ) <EOL> def test_anyLocationQueryForString ( self ) : <EOL> """<STR_LIT>""" <EOL> xp = XPathQuery ( "<STR_LIT>" ) <EOL> self . assertRaises ( NotImplementedError , xp . queryForString , None ) <EOL> def test_andOperator ( self ) : <EOL> """<STR_LIT>""" <EOL> xp = XPathQuery ( "<STR_LIT>" ) <EOL> self . assertEqual ( xp . matches ( self . e ) , True ) <EOL> self . assertEqual ( xp . queryForNodes ( self . e ) , [ self . bar5 ] ) <EOL> def test_orOperator ( self ) : <EOL> """<STR_LIT>""" <EOL> xp = XPathQuery ( "<STR_LIT>" ) <EOL> self . assertEqual ( xp . matches ( self . e ) , True ) <EOL> self . assertEqual ( xp . queryForNodes ( self . e ) , [ self . bar5 , self . bar6 ] ) <EOL> def test_booleanOperatorsParens ( self ) : <EOL> """<STR_LIT>""" <EOL> xp = XPathQuery ( """<STR_LIT>""" ) <EOL> self . assertEqual ( xp . matches ( self . e ) , True ) <EOL> self . assertEqual ( xp . queryForNodes ( self . e ) , [ self . bar6 , self . bar7 ] ) <EOL> def test_booleanOperatorsNoParens ( self ) : <EOL> """<STR_LIT>""" <EOL> xp = XPathQuery ( """<STR_LIT>""" ) <EOL> self . assertEqual ( xp . matches ( self . e ) , True ) <EOL> self . assertEqual ( xp . queryForNodes ( self . e ) , [ self . bar5 , self . bar6 , self . bar7 ] ) </s>
