def _test_id1(self, h): self.setup() self.mp.feed(h) ret = tpl.select('#a', self.func) self.assertEqual(len(ret), 1) self.assertTrue(isinstance(ret[0], tpl.TagNode)) self.assertEqual(ret[0]['id'], 'a') ret = tpl.select('#b', self.func) self.assertEqual(ret, [])
def test_disabled2(self): self.setup() self.mp.feed("<a><input name='who' />a</a>") ret = tpl.select(':disabled', self.func) self.assertEqual(len(ret), 0) ret = tpl.select(':enabled', self.func) self.assertEqual(len(ret), 1) self.assertTrue(isinstance(ret[0], tpl.TagNode)) self.assertEqual(ret[0]['name'], 'who')
def _test_class1(self, h): self.setup() #h = "<a> </a>" self.mp.feed(h) ret = tpl.select('.a', self.func) self.assertEqual(len(ret), 1) self.assertTrue(isinstance(ret[0], tpl.TagNode)) self.assertEqual(ret[0].tag, 'a') self.assertEqual(ret[0]['class'], 'a') ret = tpl.select('.b', self.func) self.assertEqual(ret, [])
def test_group1(self): self.setup() self.mp.feed("<a>a</a><b>b</b>") ret = tpl.select('b,a', self.func) self.assertEqual(len(ret), 2) self.assertEqual(ret[0].tag, 'b') self.assertEqual(ret[1].tag, 'a') ret = tpl.select('a,b', self.func) self.assertEqual(len(ret), 2) self.assertEqual(ret[1].tag, 'b') self.assertEqual(ret[0].tag, 'a')
def test_class3(self): self.setup() h = "<a class='cd a' b='2'> </a>" self.mp.feed(h) ret = tpl.select('.a', self.func) self.assertEqual(len(ret), 1) self.assertTrue(isinstance(ret[0], tpl.TagNode)) self.assertEqual(ret[0].tag, 'a') self.assertEqual(ret[0]['class'], 'cd a') ret = tpl.select('.b', self.func) self.assertEqual(ret, [])
def test_tag2(self): self.setup() h = "<html><a b='1'> </a><div/><a b='2'> <br/></a></html>" self.mp.feed(h) ret = tpl.select('a', self.func) self.assertEqual(len(ret), 2) self.assertTrue(isinstance(ret[0], tpl.TagNode)) self.assertTrue(isinstance(ret[1], tpl.TagNode)) self.assertEqual((ret[0].tag, ret[1].tag), ('a', 'a')) self.assertEqual((ret[0]['b'], ret[1]['b']), ('1', '2')) ret = tpl.select('b', self.func) self.assertEqual(ret, [])
def _test_indirect_child1(self, h): self.setup() self.mp.feed(h) ret = tpl.select('a b', self.func) self.assertEqual(len(ret), 1) self.assertTrue(isinstance(ret[0], tpl.TagNode)) self.assertEqual(ret[0].tag, 'b')
def test_checked2(self): self.setup() self.mp.feed("<a><input type='radio' checked name='who' />a</a>") ret = tpl.select(':checked', self.func) self.assertEqual(len(ret), 1) self.assertTrue(isinstance(ret[0], tpl.TagNode)) self.assertEqual(ret[0]['name'], 'who')
def test_first_child2(self): self.setup() self.mp.feed("<a><b id='b'>b</b>a<b id='c'></b></a>") ret = tpl.select('b:first-child', self.func) self.assertEqual(len(ret), 1) self.assertTrue(isinstance(ret[0], tpl.TagNode)) self.assertEqual(ret[0].tag, 'b') self.assertEqual(ret[0]['id'], 'b')
def test_attribute_eq5(self): self.setup() self.mp.feed(" <a abcd='1'> <b abcd='2 3'> abccc </b> </a>") ret = tpl.select('a [abcd="2 3"]', self.func) self.assertEqual(len(ret), 1) self.assertTrue(isinstance(ret[0], tpl.TagNode)) self.assertEqual(ret[0]['abcd'], '2 3') self.assertEqual(ret[0].tag, 'b')
def test_attribute_in1(self): self.setup() self.mp.feed("<a abcd='efgh'></a><b abcd></b>") ret = tpl.select('[abcd*=ef]', self.func) self.assertEqual(len(ret), 1) t = ret[0] self.assertTrue(isinstance(t, tpl.TagNode)) self.assertEqual(t['abcd'], 'efgh') self.assertEqual(t.tag, 'a') ret = tpl.select('[abcd*=fg]', self.func) self.assertEqual(len(ret), 1) self.assertEqual(ret[0], t) ret = tpl.select('[abcd*=gh]', self.func) self.assertEqual(len(ret), 1) self.assertEqual(ret[0], t)
def test_attribute_ed1(self): self.setup() self.mp.feed("<a abcd='efgh'></a><b abcd></b>") ret = tpl.select('[abcd$=gh]', self.func) self.assertEqual(len(ret), 1) self.assertTrue(isinstance(ret[0], tpl.TagNode)) self.assertEqual(ret[0]['abcd'], 'efgh') self.assertEqual(ret[0].tag, 'a')
def _test_direct_child1(self, h): self.setup() self.mp.feed(h) ret = tpl.select('a>b', self.func) #print ret, str(ret[0]) self.assertEqual(len(ret), 1) self.assertTrue(isinstance(ret[0], tpl.TagNode)) self.assertEqual(ret[0].tag, 'b') self.assertEqual(ret[0].parent.tag, 'a')
def test_first_child1(self): self.setup() self.mp.feed("<a>a</a><b>b</b>") ret = tpl.select(':first-child', self.func) self.assertEqual(len(ret), 3) self.assertTrue(isinstance(ret[0], tpl.TagNode)) self.assertEqual(ret[0].tag, 'a') self.assertTrue(isinstance(ret[1], tpl.DataNode)) self.assertEqual(str(ret[1]), 'a') self.assertTrue(isinstance(ret[2], tpl.DataNode)) self.assertEqual(str(ret[2]), 'b')
def test_attribute1(self): self.setup() self.mp.feed("<a abcd='1'></a><b abcd></b>") ret = tpl.select('[abcd]', self.func) self.assertEqual(len(ret), 2) self.assertTrue(isinstance(ret[0], tpl.TagNode)) self.assertEqual(ret[0]['abcd'], '1') self.assertEqual(ret[0].tag, 'a') self.assertTrue(isinstance(ret[1], tpl.TagNode)) self.assertTrue(ret[1]['abcd'] is None) self.assertEqual(ret[1].tag, 'b')
def test_attribute_ed2(self): self.setup() self.mp.feed("<a abcd='efgh'></a><b abcd></b>") ret = tpl.select('[abcd^=fg]', self.func) self.assertEqual(len(ret), 0)
def test_id2(self): self.setup() self.mp.feed("<a id='b' b='2'> </a>") ret = tpl.select('#a', self.func) self.assertEqual(ret, [])
def test_direct_child2(self): self.setup() self.mp.feed("<a>a<c>c<b>b</b></c></a>") ret = tpl.select('a>b', self.func) self.assertEqual(len(ret), 0)
def test_group2(self): self.setup() self.mp.feed("<a>a</a><b>b</b>") ret = tpl.select('b , a', self.func) self.assertEqual(len(ret), 2)
def test_first_child3(self): self.setup() self.mp.feed("<a>a<b id='b'>b</b>a<b id='c'></b></a>") ret = tpl.select('b:first-child', self.func) self.assertEqual(len(ret), 0)
def test_checked4(self): self.setup() self.mp.feed("<a><input checked name='who' />a</a>") ret = tpl.select(':checked', self.func) self.assertEqual(len(ret), 0)