How to use pyquery - 10 common examples

To help you get started, we’ve selected a few pyquery examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github gawel / pyquery / tests / test_pyquery.py View on Github external
def test_fn_with_kwargs(self):
        "fn() with keyword arguments."
        pq.fn.test = lambda p=1: pq(this).eq(p)  # NOQA
        S = pq(self.html)
        self.assertEqual(S('li').test(0).text(), 'Coffee')
        self.assertEqual(S('li').test().text(), 'Tea')
        self.assertEqual(S('li').test(p=2).text(), 'Milk')
github fle / django-multi-email-field / multi_email_field / tests.py View on Github external
def test__render(self):
        w = MultiEmailWidget()
        output = w.render('test', ['foo@foo.fr', 'bar@bar.fr'])
        self.assertEqual(1, len(pq('textarea', output)))
        self.assertEqual(
            pq('textarea', output).text(),
            'foo@foo.fr\nbar@bar.fr')
github gleitz / howdoi / test_howdoi.py View on Github external
def test_get_text_with_multiple_links_test_two(self):
        html = 'For example, if I were to reference <a rel="nofollow noreferrer" href="http://www.apple.com/">apple.com</a> as the subject of a sentence - or to talk about <a rel="nofollow noreferrer" href="http://www.apple.com/">Apple\'s website</a> as the topic of conversation. This being different to perhaps recommendations for reading <a href="https://ux.stackexchange.com/q/14872/6046">our article about Apple\'s website</a>.'
        paragraph = pq(html)
        expected_output = "For example, if I were to reference [apple.com](http://www.apple.com/) as the subject of a sentence - or to talk about [Apple's website](http://www.apple.com/) as the topic of conversation. This being different to perhaps recommendations for reading [our article about Apple's website](https://ux.stackexchange.com/q/14872/6046)."
        actual_output = howdoi.get_text(paragraph)
        self.assertEqual(actual_output, expected_output)
github fwenzel / reporter / apps / feedback / tests.py View on Github external
def test_rating(self):
        """Submit rating form with and without AJAX."""

        # Empty POST: Count errors
        for ajax in True, False:
            r = self.post_feedback({'type': OPINION_RATING}, ajax=ajax)
            if not ajax:
                doc = pyquery.PyQuery(r.content)
                eq_(doc('article#rate form .errorlist').length, len(RATING_USAGE))
            else:
                eq_(r.status_code, 400)
                errors = json.loads(r.content)
                eq_(len(errors), len(RATING_USAGE))
                for question in RATING_USAGE:
                    assert question.short in errors

        # Submit actual rating
        data = {'type': OPINION_RATING}
        for type in RATING_USAGE:
            data[type.short] = RATING_CHOICES[type.id % len(RATING_CHOICES)][0]

        for ajax in True, False:
            r = self.post_feedback(data, follow=False, ajax=ajax)
            if not ajax:
github gawel / pyquery / tests / test_pyquery.py View on Github external
def test_unicode(self):
        xml = pq(u"<p>é</p>")
        self.assertEqual(type(xml.html()), str)
        self.assertEqual(str(xml), '<p>é</p>')
        self.assertEqual(str(xml('p:contains("é")')), '<p>é</p>')
github gawel / pyquery / tests / test_pyquery.py View on Github external
def test_xhtml_namespace(self):
        expected = 'What'
        d = pq(self.xhtml.encode('utf8'), parser='xml')
        d.xhtml_to_html()
        val = d('div').text()
        self.assertEqual(repr(val), repr(expected))
github fwenzel / reporter / apps / feedback / tests.py View on Github external
def autocomplete_check(site_id):
            r = self.client.get(reverse('feedback.sad'), HTTP_USER_AGENT=(
                self.FX_UA % '20.0'), SITE_ID=site_id, follow=True)
            doc = pyquery.PyQuery(r.content)
            form = doc('#feedbackform form')

            assert form
            eq_(form.attr('autocomplete'), 'off')
            print r
github gawel / pyquery / tests / test_pyquery.py View on Github external
def test_get_root(self):
        doc = pq(b'<p>')
        self.assertEqual(isinstance(doc.root, etree._ElementTree), True)
        self.assertEqual(doc.encoding, 'UTF-8')

        child = doc.children().eq(0)
        self.assertNotEqual(child._parent, no_default)
        self.assertTrue(isinstance(child.root, etree._ElementTree))
</p>
github gawel / pyquery / tests / test_pyquery.py View on Github external
def test_fn(self):
        "Example from `PyQuery.Fn` docs."
        fn = lambda: this.map(lambda i, el: pq(this).outerHtml())  # NOQA
        pq.fn.listOuterHtml = fn
        S = pq(self.html)
        self.assertEqual(S('li').listOuterHtml(),
                         ['<li>Coffee</li>', '<li>Tea</li>', '<li>Milk</li>'])
github gawel / pyquery / tests / test_pyquery.py View on Github external
def test_session(self):
        if HAS_REQUEST:
            import requests
            session = requests.Session()
            session.headers.update({'X-FOO': 'bar'})
            d = pq(self.application_url, {'q': 'foo'},
                   method='get', session=session)
            self.assertIn('HTTP_X_FOO: bar', d('p').text())
        else:
            self.skipTest('no requests library')