Commits

Gael Pasgrimaud committed 8f169a8

test docs/

  • Participants
  • Parent commits 885c218

Comments (0)

Files changed (6)

File buildout.cfg

 [buildout]
-newest = true
+newest = false
 parts = eggs docs
 develop = .
 [eggs]

File docs/attributes.txt

 Attributes
 ----------
 
+
 You can play with the attributes with the jquery API::
 
+    >>> p = pq('<p id="hello" class="hello"></p>')('p')
     >>> p.attr("id")
     'hello'
     >>> p.attr("id", "plop")

File docs/css.txt

 CSS
 ---
 
-You can also play with css classes::
+.. Initialize tests
+
+    >>> from pyquery import PyQuery
+    >>> p = PyQuery('<p id="hello" class="hello"><a/></p>')('p')
+
+You can play with css classes::
 
     >>> p.addClass("toto")
     [<p#hello.toto.hello>]

File docs/manipulating.txt

 
 You can also add content to the end of tags::
 
-    >>> d('p').append('check out <a href="http://reddit.com/r/python"><span>reddit</span></a>')
-    [<p#hello.hello>, <p#test>]
+    >>> 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
-    <html>
-    ...
-    <p class="hello" id="hello" style="font-size: 17px">you know <a href="http://python.org/">Python</a> rockscheck out <a href="http://reddit.com/r/python"><span>reddit</span></a></p><p id="test">
-    hello <a href="http://python.org">python</a> !
-    check out <a href="http://python.org/">Python</a> rockscheck out <a href="http://reddit.com/r/python"><span>reddit</span></a></p>
-    ...
+    <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::
 
+    >>> p = d('p')
     >>> p.prepend('check out <a href="http://reddit.com/r/python">reddit</a>')
     [<p#hello.hello>]
     >>> p.html()
 
 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()
-    '<p class="hello" ...</p>...hello...python...'
+    '<p class="hello" ...'
 
 Insert an element after another::
 
     >>> p.insertBefore(d('#test'))
     [<p#hello.hello>]
     >>> d('body').html()
-    '\n<p class="hello" id="hello" style="font-size: 17px">...'
+    '<p class="hello" id="hello">...'
 
 Doing something for each elements::
 
 
 Remove an element::
 
+    >>> d = pq('<html><body><p id="id">Yeah!</p><p>python rocks !</p></div></html>')
     >>> d.remove('p#id')
     [<html>]
     >>> d('p#id')
     []
 
-Replace an element by another::
-
-    >>> p.replaceWith('<p>testing</p>')
-    [<p#hello.hello2.hello>]
-    >>> d('p')
-    [<p>, <p#test>]
-
-Or the other way around::
-
-    >>> d('<h1>arya stark</h1>').replaceAll('p')
-    [<h1>]
-    >>> d('p')
-    []
-    >>> d('h1')
-    [<h1>, <h1>]
-
 Remove what's inside the selection::
 
-    >>> d('h1').empty()
-    [<h1>, <h1>]
+    >>> d('p').empty()
+    [<p>]
 
 And you can get back the modified html::
 
     >>> print d
-    <html>
-    <body>
-    <h1/><h1/></body>
-    </html>
+    <html><body><p/></body></html>
 
 You can generate html stuff::
 

File docs/traversing.txt

 
 You can filter the selection list using a string selector::
 
+    >>> d = pq('<p id="hello" class="hello"><a/></p><p id="test"><a/></p>')
     >>> d('p').filter('.hello')
     [<p#hello.hello>]
 

File pyquery/test.py

 from ajax import PyQuery as pqa
 
 dirname = os.path.dirname(os.path.abspath(pyquery.__file__))
+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):
         test = self._dt_test
         test.globs.update(globals())
 
+for filename in os.listdir(docs):
+    if filename.endswith('.txt'):
+        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)
+
 class TestTests(doctest.DocFileCase):
     path = os.path.join(dirname, 'tests.txt')