fix tox tests

pull/34/head
Gael Pasgrimaud 10 years ago
parent 13a3e446bb
commit ef7dbc4b03
  1. 1
      .travis.yml
  2. 2
      README.rst
  3. 6
      README_fixt.py
  4. 14
      buildout-py3k.cfg
  5. 23
      buildout.cfg
  6. 6
      docs/ajax.rst
  7. 31
      docs/ajax_fixt.py
  8. 0
      docs/conf.py
  9. 22
      docs/manipulating.rst
  10. 10
      docs/scrap_fixt.py
  11. 5
      pyquery/ajax.py
  12. 2
      pyquery/cssselectpatch.py
  13. 8
      pyquery/pyquery.py
  14. 2
      setup.py
  15. 8
      tests/apps.py
  16. 5
      tests/compat.py
  17. 0
      tests/doctests.rst
  18. 30
      tests/test_pyquery.py
  19. 58
      tox.ini

@ -7,6 +7,7 @@ install:
- pip install nose
- pip install webob
- pip install webtest
- pip install requests
- "if [[ $TRAVIS_PYTHON_VERSION == '2.6' ]]; then pip install unittest2; fi"
- "if [[ $TRAVIS_PYTHON_VERSION == '2.5' ]]; then pip install beautifulsoup; fi"
- "if [[ $TRAVIS_PYTHON_VERSION == '2.6' ]]; then pip install beautifulsoup; fi"

@ -33,7 +33,7 @@ document, from a file or from an url::
>>> d = pq(etree.fromstring("<html></html>"))
>>> d = pq(url=your_url)
>>> d = pq(url=your_url,
... opener=lambda url, **kw: urllib.urlopen(url).read())
... opener=lambda url, **kw: urlopen(url).read())
>>> d = pq(filename=path_to_html_file)
Now d is like the $ in jquery::

@ -3,12 +3,18 @@ import os
from webtest import http
from webtest.debugapp import debug_app
try:
from urllib import urlopen
except ImportError:
from urllib.request import urlopen
def setup_test(test):
server = http.StopableWSGIServer.create(debug_app)
server.wait()
path_to_html_file = os.path.join('tests', 'test.html')
test.globs.update(
urlopen=urlopen,
server=server,
your_url=server.application_url,
path_to_html_file=path_to_html_file,

@ -1,14 +0,0 @@
[buildout]
newest = false
parts = eggs
develop = .
[eggs]
recipe = z3c.recipe.script
eggs =
WebOb>1.1.9
pyquery
nose
scripts =
nosetests
interpreter = py3

@ -1,26 +1,31 @@
[buildout]
newest = false
parts = eggs docs
parts = py2 docs
develop = .
[eggs]
[py3]
recipe = zc.recipe.egg
eggs =
cssselect>0.7.9
pyquery
BeautifulSoup
restkit
WebOb
WebOb>1.1.9
WebTest
pyquery
nose
coverage
scripts =
nosetests
[py2]
recipe = zc.recipe.egg
eggs =
${py3:eggs}
unittest2
BeautifulSoup
restkit
[docs]
recipe = zc.recipe.egg
eggs =
${eggs:eggs}
${py2:eggs}
Pygments
Sphinx
sphinx-pypi-upload

@ -16,7 +16,7 @@ submit button at `/submit`::
>>> d = pq('<form></form>', app=input_app)
>>> d.append(d.get('/'))
[<form>]
>>> print d
>>> print(d)
<form><input name="youyou" type="text" value=""/></form>
The app is also available in new nodes::
@ -28,7 +28,7 @@ You can also request another path::
>>> d.append(d.get('/submit'))
[<form>]
>>> print d
>>> print(d)
<form><input name="youyou" type="text" value=""/><input type="submit" value="OK"/></form>
If `restkit`_ is installed, you are able to get url directly with a `HostProxy`_ app::
@ -39,7 +39,7 @@ If `restkit`_ is installed, you are able to get url directly with a `HostProxy`_
You can retrieve the app response::
>>> print a.response.status
>>> print(a.response.status)
200 OK
The response attribute is a `WebOb`_ `Response`_

@ -1,22 +1,33 @@
# -*- coding: utf-8 -*-
import os
import sys
sys.path.insert(0, os.path.dirname(os.path.dirname(__file__)))
from webtest import http
from doctest import SKIP
from tests.apps import input_app
PY3 = sys.version_info >= (3,)
def setup_test(test):
server = http.StopableWSGIServer.create(input_app)
server.wait()
path_to_html_file = os.path.join('tests', 'test.html')
test.globs.update(
input_app=input_app,
server=server,
your_url=server.application_url.rstrip('/') + '/html',
path_to_html_file=path_to_html_file,
)
for example in test.examples:
# urlopen as moved in py3
if PY3:
example.options.setdefault(SKIP, 1)
if not PY3:
server = http.StopableWSGIServer.create(input_app)
server.wait()
path_to_html_file = os.path.join('tests', 'test.html')
test.globs.update(
input_app=input_app,
server=server,
your_url=server.application_url.rstrip('/') + '/html',
path_to_html_file=path_to_html_file,
)
setup_test.__test__ = False
def teardown_test(test):
test.globs['server'].shutdown()
if 'server' in test.globs:
test.globs['server'].shutdown()
teardown_test.__test__ = False

@ -9,7 +9,7 @@ You can also add content to the end of tags::
>>> d = pq('<p class="hello" id="hello">you know Python rocks</p>')
>>> d('p').append(' check out <a href="http://reddit.com/r/python"><span>reddit</span></a>')
[<p#hello.hello>]
>>> print d
>>> print(d)
<p class="hello" id="hello">you know Python rocks check out <a href="http://reddit.com/r/python"><span>reddit</span></a></p>
Or to the beginning::
@ -17,30 +17,30 @@ Or to the beginning::
>>> p = d('p')
>>> p.prepend('check out <a href="http://reddit.com/r/python">reddit</a>')
[<p#hello.hello>]
>>> p.html()
u'check out <a href="http://reddit.com/r/python">reddit</a>you know ...'
>>> print(p.html())
check out <a href="http://reddit.com/r/python">reddit</a>you know ...
Prepend or append an element into an other::
>>> d = pq('<html><body><div id="test"><a href="http://python.org">python</a> !</div></body></html>')
>>> p.prependTo(d('#test'))
[<p#hello.hello>]
>>> d('#test').html()
u'<p class="hello" ...'
>>> print(d('#test').html())
<p class="hello" ...
Insert an element after another::
>>> p.insertAfter(d('#test'))
[<p#hello.hello>]
>>> d('#test').html()
u'<a href="http://python.org">python</a> !'
>>> print(d('#test').html())
<a href="http://python.org">python</a> !
Or before::
>>> p.insertBefore(d('#test'))
[<p#hello.hello>]
>>> d('body').html()
u'<p class="hello" id="hello">...'
>>> print(d('body').html())
<p class="hello" id="hello">...
Doing something for each elements::
@ -62,13 +62,13 @@ Remove what's inside the selection::
And you can get back the modified html::
>>> print d
>>> print(d)
<html><body><p/></body></html>
You can generate html stuff::
>>> from pyquery import PyQuery as pq
>>> print pq('<div>Yeah !</div>').addClass('myclass') + pq('<b>cool</b>')
>>> print(pq('<div>Yeah !</div>').addClass('myclass') + pq('<b>cool</b>'))
<div class="myclass">Yeah !</div><b>cool</b>

@ -1,17 +1,17 @@
# -*- coding: utf-8 -*-
import os
import sys
sys.path.insert(0, os.path.dirname(os.path.dirname(__file__)))
from webtest import http
from webtest.debugapp import debug_app
from tests.apps import input_app
def setup_test(test):
server = http.StopableWSGIServer.create(debug_app)
server = http.StopableWSGIServer.create(input_app)
server.wait()
path_to_html_file = os.path.join('tests', 'test.html')
test.globs.update(
server=server,
your_url=server.application_url,
path_to_html_file=path_to_html_file,
your_url=server.application_url.rstrip('/') + '/html',
)
setup_test.__test__ = False

@ -2,12 +2,13 @@
from .pyquery import PyQuery as Base
from .pyquery import no_default
from webob import Request, Response
from webob import Request
from webob import Response
try:
from restkit.contrib.wsgi_proxy import HostProxy
except ImportError:
HostProxy = no_default # NOQA
HostProxy = no_default # NOQA
class PyQuery(Base):

@ -35,8 +35,8 @@ class XPathExpr(XPathExprOrig):
self.post_condition = other.post_condition
return res
# keep cssselect < 0.8 compat for now
cssselect_xpath.XPathExpr = XPathExpr
class JQueryTranslator(cssselect_xpath.HTMLTranslator):

@ -11,6 +11,7 @@ import lxml.html
import inspect
import sys
PY3k = sys.version_info >= (3,)
if PY3k:
@ -120,6 +121,9 @@ class FlexibleElement(object):
class PyQuery(list):
"""The main class
"""
_translator_class = JQueryTranslator
def __init__(self, *args, **kwargs):
html = None
elements = []
@ -145,11 +149,11 @@ class PyQuery(list):
if 'css_translator' in kwargs:
self._translator = kwargs.pop('css_translator')
elif self.parser in ('xml',):
self._translator = JQueryTranslator(xhtml=True)
self._translator = self._translator_class(xhtml=True)
elif self._parent is not no_default:
self._translator = self._parent._translator
else:
self._translator = JQueryTranslator(xhtml=False)
self._translator = self._translator_class(xhtml=False)
namespaces = kwargs.get('namespaces', {})
if 'namespaces' in kwargs:

@ -34,7 +34,7 @@ News
""" % read('README', 'CHANGES')
version = '1.2.4'
version = '1.2.5'
setup(name='pyquery',
version=version,

@ -9,11 +9,11 @@ def input_app(environ, start_response):
resp = Response()
req = Request(environ)
if req.path_info == '/':
resp.body = '<input name="youyou" type="text" value="" />'
resp.body = b('<input name="youyou" type="text" value="" />')
elif req.path_info == '/submit':
resp.body = '<input type="submit" value="OK" />'
elif req.path_info == '/html/':
resp.body = '<html><p>Success</p></html>'
resp.body = b('<input type="submit" value="OK" />')
elif req.path_info.startswith('/html'):
resp.body = b('<html><p>Success</p></html>')
else:
resp.body = ''
return resp(environ, start_response)

@ -19,3 +19,8 @@ else:
def b(value): # NOQA
return str(value)
try:
from unittest2 import TestCase
except ImportError:
from unittest import TestCase # NOQA

@ -3,6 +3,9 @@
# Copyright (C) 2008 - Olivier Lauzanne <olauzanne@gmail.com>
#
# Distributed under the BSD license, see LICENSE.txt
import os
import sys
sys.path.insert(0, os.path.dirname(os.path.dirname(__file__)))
from lxml import etree
from pyquery.pyquery import PyQuery as pq
from pyquery.ajax import PyQuery as pqa
@ -14,8 +17,7 @@ from .compat import PY3k
from .compat import u
from .compat import b
from .compat import text_type
import unittest
import os
from .compat import TestCase
def not_py3k(func):
@ -34,7 +36,7 @@ docs = os.path.join(os.path.dirname(dirname), 'docs')
path_to_html_file = os.path.join(dirname, 'test.html')
class TestUnicode(unittest.TestCase):
class TestUnicode(TestCase):
def test_unicode(self):
xml = pq(u("<p>é</p>", 'utf-8'))
@ -46,7 +48,7 @@ class TestUnicode(unittest.TestCase):
self.assertEqual(str(xml), '<p>&#233;</p>')
class TestAttributeCase(unittest.TestCase):
class TestAttributeCase(TestCase):
def test_xml_upper_element_name(self):
xml = pq('<X>foo</X>', parser='xml')
@ -59,7 +61,7 @@ class TestAttributeCase(unittest.TestCase):
self.assertEqual(len(xml('x')), 1)
class TestSelector(unittest.TestCase):
class TestSelector(TestCase):
klass = pq
html = """
<html>
@ -200,7 +202,7 @@ class TestSelector(unittest.TestCase):
assert e('').text() is None
class TestTraversal(unittest.TestCase):
class TestTraversal(TestCase):
klass = pq
html = """
<html>
@ -256,7 +258,7 @@ class TestTraversal(unittest.TestCase):
assert self.klass('.node3', self.html).closest('form') == []
class TestOpener(unittest.TestCase):
class TestOpener(TestCase):
def test_open_filename(self):
doc = pq(filename=path_to_html_file)
@ -270,14 +272,14 @@ class TestOpener(unittest.TestCase):
assert len(doc('.node')) == 1, doc
class TestComment(unittest.TestCase):
class TestComment(TestCase):
def test_comment(self):
doc = pq('<div><!-- foo --> bar</div>')
self.assertEqual(doc.text(), 'bar')
class TestCallback(unittest.TestCase):
class TestCallback(TestCase):
html = """
<ol>
<li>Coffee</li>
@ -343,7 +345,7 @@ class TestAjaxSelector(TestSelector):
self.s.shutdown()
class TestManipulating(unittest.TestCase):
class TestManipulating(TestCase):
html = '''
<div class="portlet">
<a href="/toto">Test<img src ="myimage" />My link text</a>
@ -360,7 +362,7 @@ class TestManipulating(unittest.TestCase):
assert val == ' My link text 2', repr(val)
class TestHTMLParser(unittest.TestCase):
class TestHTMLParser(TestCase):
xml = "<div>I'm valid XML</div>"
html = '''
<div class="portlet">
@ -407,7 +409,7 @@ class TestHTMLParser(unittest.TestCase):
assert val == expected, (repr(val), repr(expected))
class TestXMLNamespace(unittest.TestCase):
class TestXMLNamespace(TestCase):
xml = '''<?xml version="1.0" encoding="UTF-8" ?>
<foo xmlns:bar="http://example.com/bar">
<bar:blah>What</bar:blah>
@ -462,7 +464,7 @@ class TestXMLNamespace(unittest.TestCase):
self.assertEqual(repr(val), repr(expected))
class TestWebScrapping(unittest.TestCase):
class TestWebScrapping(TestCase):
def setUp(self):
self.s = http.StopableWSGIServer.create(debug_app)
@ -486,7 +488,7 @@ class TestWebScrapping(unittest.TestCase):
self.s.shutdown()
class TestWebScrappingEncoding(unittest.TestCase):
class TestWebScrappingEncoding(TestCase):
def test_get(self):
if not HAS_REQUEST:

@ -1,52 +1,40 @@
[tox]
envlist=py26,py27,py27-requests,py32,py33
envlist=py26,py27,py32,py33
[testenv:py26]
basepython=python2.6
changedir={toxinidir}
commands =
rm -f .installed.cfg
{envbindir}/buildout buildout:parts-directory={envdir}/parts buildout:bin-directory={envbindir}
{envbindir}/nosetests []
deps =
zc.buildout
[testenv:py27]
basepython=python2.7
changedir={toxinidir}
[testenv]
commands =
rm -f .installed.cfg
{envbindir}/buildout buildout:parts-directory={envdir}/parts buildout:bin-directory={envbindir}
{envbindir}/nosetests []
deps =
zc.buildout
[testenv:py27-requests]
basepython=python2.7
changedir={toxinidir}
commands =
rm -f .installed.cfg
{envbindir}/buildout buildout:parts-directory={envdir}/parts buildout:bin-directory={envbindir} \
eggs:eggs+=requests
{envbindir}/nosetests []
deps =
zc.buildout
cssselect>0.7.9
requests
WebOb>1.1.9
WebTest
nose
coverage
unittest2
BeautifulSoup
restkit
[testenv:py32]
basepython=python3.2
changedir={toxinidir}
commands =
{envbindir}/nosetests []
deps =
nose
webob
cssselect>0.7.9
requests
WebOb>1.1.9
WebTest
nose
coverage
[testenv:py33]
basepython=python3.3
changedir={toxinidir}
commands =
{envbindir}/nosetests []
deps =
nose
webob
cssselect>0.7.9
requests
WebOb>1.1.9
WebTest
nose
coverage

Loading…
Cancel
Save