Gael Pasgrimaud avatar Gael Pasgrimaud committed a1048e1

tests.py pep8ify. add tox.ini

Comments (0)

Files changed (7)

 build/
 parts/
 docs/_build/
+.tox/
 .installed.cfg
 *.egg-info
 *.pyc

buildout-py3k.cfg

     nose
 scripts =
     nosetests
-interpreter = python
+interpreter = py3
     Pygments
     Sphinx
     sphinx-pypi-upload
-interpreter = python
+interpreter = py
 scripts =
 
 [tox]

pyquery/pyquery.py

             'Youhou'
 
         """
-        return self.attr('value', value)
+        return self.attr('value', value) or None
 
     def html(self, value=no_default, **kwargs):
         """Get or set the html representation of sub nodes.
     from pyquery.ajax import PyQuery as pqa
     from http.client import HTTPConnection
     text_type = str
+
     def u(value, encoding):
         return str(value)
+
     def b(value):
         return value.encode('utf-8')
 else:
-    from cStringIO import StringIO
-    import pyquery
-    from httplib import HTTPConnection
-    from pyquery import PyQuery as pq
-    from ajax import PyQuery as pqa
+    from cStringIO import StringIO  # NOQA
+    import pyquery  # NOQA
+    from httplib import HTTPConnection  # NOQA
+    from pyquery import PyQuery as pq  # NOQA
+    from ajax import PyQuery as pqa  # NOQA
     text_type = unicode
-    def u(value, encoding):
+
+    def u(value, encoding):  # NOQA
         return unicode(value, encoding)
-    def b(value):
+
+    def b(value):  # NOQA
         return str(value)
 
+
 def not_py3k(func):
     if not PY3k:
         return func
     conn.request("GET", "/pyquery/")
     response = conn.getresponse()
 except (socket.timeout, socket.error):
-    GOT_NET=False
+    GOT_NET = False
 else:
-    GOT_NET=True
+    GOT_NET = True
 
 
 def with_net(func):
 docs = os.path.join(os.path.dirname(dirname), 'docs')
 path_to_html_file = os.path.join(dirname, 'test.html')
 
+
 def input_app(environ, start_response):
     resp = Response()
     req = Request(environ)
         resp.body = ''
     return resp(environ, start_response)
 
+
 class TestReadme(doctest.DocFileCase):
     path = os.path.join(dirname, '..', 'README.txt')
 
             continue
         klass_name = 'Test%s' % filename.replace('.txt', '').title()
         path = os.path.join(docs, filename)
-        exec('%s = type("%s", (TestReadme,), dict(path=path))' % (klass_name, klass_name))
+        exec('%s = type("%s", (TestReadme,), dict(path=path))' % (
+                                                       klass_name, klass_name))
 
 
 class TestTests(doctest.DocFileCase):
             <body>
               <form action="/">
                 <input name="enabled" type="text" value="test"/>
-                <input name="disabled" type="text" value="disabled" disabled="disabled"/>
+                <input name="disabled" type="text"
+                       value="disabled" disabled="disabled"/>
                 <input name="file" type="file" />
                 <select name="select">
                   <option value="">Choose something</option>
                   <option value="three">Three</option>
                 </select>
                 <input name="radio" type="radio" value="one"/>
-                <input name="radio" type="radio" value="two" checked="checked"/>
+                <input name="radio" type="radio"
+                       value="two" checked="checked"/>
                 <input name="radio" type="radio" value="three"/>
                 <input name="checkbox" type="checkbox" value="a"/>
-                <input name="checkbox" type="checkbox" value="b" checked="checked"/>
+                <input name="checkbox" type="checkbox"
+                       value="b" checked="checked"/>
                 <input name="checkbox" type="checkbox" value="c"/>
                 <input name="button" type="button" value="button" />
                 <button>button</button>
         assert e('<p>Hello world</p>').text() == 'Hello world'
         assert e('').text() == None
 
+
 class TestTraversal(unittest.TestCase):
     klass = pq
     html = """
            <html>
             <body>
               <div id="node1"><span>node1</span></div>
-              <div id="node2" class="node3"><span>node2</span><span> booyah</span></div>
+              <div id="node2" class="node3">
+                        <span>node2</span><span> booyah</span></div>
             </body>
            </html>
            """
 
     def test_each(self):
         doc = self.klass(self.html)
-        doc('span').each(lambda: doc(this).wrap("<em></em>"))
+        doc('span').each(lambda: doc(this).wrap("<em></em>"))  # NOQA
         assert len(doc('em')) == 3
 
     def test_map(self):
         assert self.klass('div', self.html).map(ids_minus_one) == [0, 1]
 
         d = pq('<p>Hello <b>warming</b> world</p>')
-        self.assertEqual(d('strong').map(lambda i,el: pq(this).text()), [])
+        self.assertEqual(d('strong').map(lambda i, el: pq(this).text()), [])  # NOQA
 
     def test_end(self):
         assert len(self.klass('div', self.html).find('span').end()) == 2
 
     def test_closest(self):
         assert len(self.klass('#node1 span', self.html).closest('body')) == 1
-        assert self.klass('#node2', self.html).closest('.node3').attr('id') == 'node2'
+        assert self.klass('#node2', self.html).closest('.node3').attr('id') \
+                                                                    == 'node2'
         assert self.klass('.node3', self.html).closest('form') == []
 
+
 class TestOpener(unittest.TestCase):
 
     def test_custom_opener(self):
         doc = pq(url='http://example.com', opener=opener)
         assert len(doc('.node')) == 1, doc
 
+
 class TestCallback(unittest.TestCase):
     html = """
         <ol>
 
     def test_S_this_inside_callback(self):
         S = pq(self.html)
-        self.assertEqual(S('li').map(lambda i, el: S(this).html()), ['Coffee', 'Tea', 'Milk'])
+        self.assertEqual(S('li').map(lambda i, el: S(this).html()),  # NOQA
+                                     ['Coffee', 'Tea', 'Milk'])
 
     def test_parameterless_callback(self):
         S = pq(self.html)
-        self.assertEqual(S('li').map(lambda: S(this).html()), ['Coffee', 'Tea', 'Milk'])
+        self.assertEqual(S('li').map(lambda: S(this).html()),  # NOQA
+                                     ['Coffee', 'Tea', 'Milk'])
+
 
 def application(environ, start_response):
     req = Request(environ)
         response.body = b('<a href="/plop">Yeah !</a>')
     return response(environ, start_response)
 
+
 def secure_application(environ, start_response):
     if 'REMOTE_USER' not in environ:
         return exc.HTTPUnauthorized('vomis')(environ, start_response)
     return application(environ, start_response)
 
+
 class TestAjaxSelector(TestSelector):
     klass = pqa
 
         val = n.post('/')
         assert len(val('a')) == 1, val
 
+
 class TestManipulating(unittest.TestCase):
     html = '''
     <div class="portlet">
         val = d('a:last').html()
         assert val == ' My link text 2', repr(val)
 
+
 class TestHTMLParser(unittest.TestCase):
     xml = "<div>I'm valid XML</div>"
     html = '''
       Behind you, a three-headed HTML&dash;Entity!
     </div>
     '''
+
     def test_parser_persistance(self):
         d = pq(self.xml, parser='xml')
         self.assertRaises(etree.XMLSyntaxError, lambda: d.after(self.html))
         d = pq(self.xml, parser='html')
-        d.after(self.html) # this should not fail
-
+        d.after(self.html)  # this should not fail
 
     @not_py3k
     def test_soup_parser(self):
-        d = pq('<meta><head><title>Hello</head><body onload=crash()>Hi all<p>', parser='soup')
-        self.assertEqual(str(d), '<html><meta/><head><title>Hello</title></head><body onload="crash()">Hi all<p/></body></html>')
+        d = pq('<meta><head><title>Hello</head><body onload=crash()>Hi all<p>',
+               parser='soup')
+        self.assertEqual(str(d), (
+            '<html><meta/><head><title>Hello</title></head>'
+            '<body onload="crash()">Hi all<p/></body></html>'))
 
     def test_replaceWith(self):
         expected = '''<div class="portlet">
         val = d.__html__()
         assert val == expected, (repr(val), repr(expected))
 
+
 class TestXMLNamespace(unittest.TestCase):
     xml = '''<?xml version="1.0" encoding="UTF-8" ?>
     <foo xmlns:bar="http://example.com/bar">
     def test_selector(self):
         expected = 'What'
         d = pq(b(self.xml), parser='xml')
-        val = d('bar|blah', namespaces={'bar': 'http://example.com/bar'}).text()
+        val = d('bar|blah',
+                namespaces={'bar': 'http://example.com/bar'}).text()
         self.assertEqual(repr(val), repr(expected))
 
     def test_selector_with_xml(self):
         expected = 'What'
-        d = pq('bar|blah', b(self.xml), parser='xml', namespaces={'bar': 'http://example.com/bar'})
+        d = pq('bar|blah', b(self.xml), parser='xml',
+               namespaces={'bar': 'http://example.com/bar'})
         val = d.text()
         self.assertEqual(repr(val), repr(expected))
 
         val = d.text()
         self.assertEqual(repr(val), repr(expected))
 
+
 class TestWebScrapping(unittest.TestCase):
+
     @with_net
     def test_get(self):
-        d = pq('http://www.theonion.com/search/', {'q': 'inconsistency'}, method='get')
+        d = pq('http://www.theonion.com/search/', {'q': 'inconsistency'},
+               method='get')
         self.assertEqual(d('input[name=q]:last').val(), 'inconsistency')
         self.assertEqual(d('.news-in-brief h3').text(), (
                         'Slight Inconsistency Found In Bible Pep-Rally '
                         'Skit Rumored To Involve Cross-Dressing Principal'))
 
-    # FIXME
     @with_net
     def test_post(self):
-        d = pq('http://www.theonion.com/search/', {'q': 'inconsistency'}, method='post')
-        self.assertEqual(d('input[name=q]:last').val(), None) # the onion does not search on post
+        d = pq('http://www.theonion.com/search/', {'q': 'inconsistency'},
+               method='post')
+        # the onion does not search on post
+        self.assertEqual(d('input[name=q]:last').val(), None)
 
 if __name__ == '__main__':
     fails, total = unittest.main()
           'lxml>=2.1',
           'cssselect',
       ],
-      test_requires=['nose'],
-      test_suite='nose.collector',
       entry_points="""
       # -*- Entry points: -*-
       """,
+[tox]
+envlist=py26,py27,py32
+
+[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}
+commands =
+    rm -f .installed.cfg
+    {envbindir}/buildout buildout:parts-directory={envdir}/parts buildout:bin-directory={envbindir}
+    {envbindir}/nosetests
+deps =
+    zc.buildout
+
+[testenv:py32]
+basepython=python3.2
+changedir={toxinidir}
+commands =
+    rm -f .installed.cfg
+    python3.2 bootstrap-py3k.py buildout:parts-directory={envdir}/parts buildout:bin-directory={envbindir}
+    {envbindir}/buildout -c buildout-py3k.cfg buildout:parts-directory={envdir}/parts buildout:bin-directory={envbindir}
+    {envbindir}/nosetests
+
+[testenv:py33]
+basepython=python3.3
+changedir={toxinidir}
+commands =
+    rm -f .installed.cfg
+    python3.3 bootstrap-py3k.py buildout:parts-directory={envdir}/parts buildout:bin-directory={envbindir}
+    {envbindir}/buildout -c buildout-py3k.cfg buildout:parts-directory={envdir}/parts buildout:bin-directory={envbindir}
+    {envbindir}/nosetests
+
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.