olauzanne / pyquery (http://pypi.python.org/pypi/pyquery)

A jquery-like library for python

Clone this repository (size: 130.4 KB): HTTPS / SSH
$ hg clone http://bitbucket.org/olauzanne/pyquery/
commit 89: 4a62ac921e43
parent 88: 18ba6c4eaf9a
branch: default
added :text and :checkbox selectors, added tests for new selectors
Scott Smerchek / ssmerche
11 months ago

Changed (Δ779 bytes):

raw changeset »

pyquery/cssselectpatch.py (12 lines added, 0 lines removed)

pyquery/test.py (10 lines added, 3 lines removed)

Up to file-list pyquery/cssselectpatch.py:

@@ -86,6 +86,18 @@ class JQueryPseudo(Pseudo):
86
86
        xpath.add_condition("@type = 'radio' and name(.) = 'input'")
87
87
        return xpath
88
88
89
    def _xpath_text(self, xpath):
90
        """Matches all text input elements.
91
        """
92
        xpath.add_condition("@type = 'text' and name(.) = 'input'")
93
        return xpath
94
95
    def _xpath_checkbox(self, xpath):
96
        """Matches all checkbox input elements.
97
        """
98
        xpath.add_condition("@type = 'checkbox' and name(.) = 'input'")
99
        return xpath
100
89
101
cssselect.Pseudo = JQueryPseudo
90
102
91
103
class JQueryFunction(Function):

Up to file-list pyquery/test.py:

@@ -102,6 +102,11 @@ class TestSelector(unittest.TestCase):
102
102
                <input name="radio" type="radio" value="one"/>
103
103
                <input name="radio" type="radio" value="two" checked="checked"/>
104
104
                <input name="radio" type="radio" value="three"/>
105
                <input name="checkbox" type="checkbox" value="a"/>
106
                <input name="checkbox" type="checkbox" value="b" checked="checked"/>
107
                <input name="checkbox" type="checkbox" value="c"/>
108
                <input name="button" type="button" value="button" />
109
                <button>button</button>
105
110
              </form>
106
111
            </body>
107
112
           </html>
@@ -149,12 +154,14 @@ class TestSelector(unittest.TestCase):
149
154
        #test on the form
150
155
        e = self.klass(self.html4)
151
156
        assert len(e(':disabled')) == 1
152
        assert len(e('input:enabled')) == 5
157
        assert len(e('input:enabled')) == 9
153
158
        assert len(e(':selected')) == 1
154
        assert len(e(':checked')) == 1
159
        assert len(e(':checked')) == 2
155
160
        assert len(e(':file')) == 1
156
        assert len(e(':input')) == 7
161
        assert len(e(':input')) == 12
162
        assert len(e(':button')) == 2
157
163
        assert len(e(':radio')) == 3
164
        assert len(e(':checkbox')) == 3
158
165
159
166
class TestTraversal(unittest.TestCase):
160
167
    klass = pq