20
20
import operator
21
21
import unittest
22
22
23
- from lxml import html
23
+ from lxml import etree , html
24
24
from cssselect import (parse , GenericTranslator , HTMLTranslator ,
25
25
SelectorSyntaxError , ExpressionError )
26
26
from cssselect .parser import tokenize , parse_series
@@ -401,7 +401,7 @@ def test_series(self):
401
401
assert parse_series ('5' ) == (0 , 5 )
402
402
403
403
def test_select (self ):
404
- document = html . document_fromstring (HTML_IDS )
404
+ document = etree . fromstring (HTML_IDS )
405
405
sort_key = dict (
406
406
(el , count ) for count , el in enumerate (document .getiterator ())
407
407
).__getitem__
@@ -426,8 +426,9 @@ def pcss(main, *selectors, **kwargs):
426
426
return result
427
427
428
428
all_ids = pcss ('*' )
429
- assert len (all_ids ) == 27
430
- assert all_ids [:4 ] == ['html' , 'nil' , 'nil' , 'outer-div' ]
429
+ assert len (all_ids ) == 32
430
+ assert all_ids [:6 ] == [
431
+ 'html' , 'nil' , 'link-href' , 'link-nohref' , 'nil' , 'outer-div' ]
431
432
assert all_ids [- 1 :] == ['foobar-span' ]
432
433
assert pcss ('div' ) == ['outer-div' , 'li-div' , 'foobar-div' ]
433
434
assert pcss ('DIV' , html_only = True ) == [
@@ -503,9 +504,16 @@ def pcss(main, *selectors, **kwargs):
503
504
assert pcss ('ol#first-ol *:last-child' ) == ['li-div' , 'seventh-li' ]
504
505
assert pcss ('#outer-div:first-child' ) == ['outer-div' ]
505
506
assert pcss ('#outer-div :first-child' ) == [
506
- 'name-anchor' , 'first-li' , 'li-div' , 'p-b' , 'checkbox-disabled' ]
507
+ 'name-anchor' , 'first-li' , 'li-div' , 'p-b' , 'checkbox-disabled' ,
508
+ 'area-href' ]
507
509
assert pcss ('a[href]' ) == ['tag-anchor' , 'nofollow-anchor' ]
508
- assert pcss (':link' , html_only = True ) == pcss ('a[href]' )
510
+
511
+
512
+ assert pcss (':link' , html_only = True ) == [
513
+ 'link-href' , 'tag-anchor' , 'nofollow-anchor' , 'area-href' ]
514
+ assert pcss (':visited' , html_only = True ) == []
515
+
516
+
509
517
assert pcss (':checked' , html_only = True ) == ['checkbox-checked' ]
510
518
assert pcss (':disabled' , html_only = True ) == [
511
519
'fieldset' , 'checkbox-disabled' ]
@@ -590,7 +598,10 @@ def count(selector):
590
598
assert count ('div[class~=dialog]' ) == 51 # ? Seems right
591
599
592
600
HTML_IDS = '''
593
- <html id="html"><head></head><body>
601
+ <html id="html"><head>
602
+ <link id="link-href" href="foo" />
603
+ <link id="link-nohref" />
604
+ </head><body>
594
605
<div id="outer-div">
595
606
<a id="name-anchor" name="foo"></a>
596
607
<a id="tag-anchor" rel="tag" href="http://localhost/foo">link</a>
@@ -612,14 +623,18 @@ def count(selector):
612
623
<p id="paragraph">
613
624
<b id="p-b">hi</b> <em id="p-em">there</em>
614
625
<b id="p-b2">guy</b>
615
- <input type="checkbox" id="checkbox-unchecked">
616
- <input type="checkbox" id="checkbox-checked" checked="checked">
626
+ <input type="checkbox" id="checkbox-unchecked" / >
627
+ <input type="checkbox" id="checkbox-checked" checked="checked" / >
617
628
<fieldset id="fieldset" disabled="disabled">
618
- <input type="checkbox" id="checkbox-disabled">
629
+ <input type="checkbox" id="checkbox-disabled" / >
619
630
</fieldset>
620
631
</p>
621
632
<ol id="second-ol">
622
633
</ol>
634
+ <map name="dummymap">
635
+ <area shape="circle" coords="200,250,25" href="foo.html" id="area-href" />
636
+ <area shape="default" id="area-nohref" />
637
+ </map>
623
638
</div>
624
639
<div id="foobar-div" foobar="ab bc
625
640
cde"><span id="foobar-span"></span></div>
0 commit comments