File size: 2,480 Bytes
065fee7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
"""Test attribute selectors."""
from .. import util
from soupsieve import SelectorSyntaxError


class TestAttribute(util.TestCase):
    """Test attribute selectors."""

    MARKUP = """
    <div>
    <p type="TEST" id="0" class="somewordshere">Some text <span id="1"> in a paragraph</span>.</p>
    <a type="test" id="2" href="http://google.com">Link</a>
    <span id="3" class="herewords">Direct child</span>
    <pre id="pre" class="wordshere">
    <span id="4">Child 1</span>
    <span id="5">Child 2</span>
    <span id="6">Child 3</span>
    </pre>
    </div>
    """

    def test_attribute_forced_case_insensitive(self):
        """Test attribute value case insensitivity."""

        self.assert_selector(
            self.MARKUP,
            "[class*=WORDS]",
            [],
            flags=util.HTML
        )

        self.assert_selector(
            self.MARKUP,
            "[class*=WORDS i]",
            ["0", "3", "pre"],
            flags=util.HTML
        )

    def test_attribute_case_insensitive_flag_spacing(self):
        """Test attribute value case insensitivity spacing."""

        self.assert_selector(
            self.MARKUP,
            "[class*=WORDSi]",
            [],
            flags=util.HTML
        )

        self.assert_selector(
            self.MARKUP,
            "[class*='WORDS'i]",
            ["0", "3", "pre"],
            flags=util.HTML
        )

    def test_attribute_forced_case_insensitive_xml(self):
        """Test that attribute value case insensitivity can be forced in XML."""

        self.assert_selector(
            self.MARKUP,
            '[type="test" i]',
            ['0', '2'],
            flags=util.XML
        )

    def test_attribute_forced_case_insensitive_xhtml(self):
        """Test that attribute value case insensitivity can be forced in XHTML."""

        self.assert_selector(
            self.wrap_xhtml(self.MARKUP),
            '[type="test" i]',
            ['0', '2'],
            flags=util.XML
        )

    def test_attribute_forced_case_needs_value(self):
        """Test attribute value case insensitivity requires a value."""

        self.assert_raises('[id i]', SelectorSyntaxError)

    def test_attribute_type_case_sensitive(self):
        """Type is treated as case insensitive in HTML, so test that we can force the opposite."""

        self.assert_selector(
            self.MARKUP,
            '[type="test" s]',
            ['2'],
            flags=util.HTML
        )