Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Documentation.

  • Loading branch information...
commit 22a8217e2a7bd95ec2f6a6d3b6647b5b53122fe3 1 parent 028d3e4
@cortesi authored
View
1  doc-src/api.html
@@ -1,5 +1,4 @@
This page describes the API exposed from the __libpry__ module.
-
@!libpry("test")!@
View
3  doc-src/cli.html
@@ -0,0 +1,3 @@
+
+$!examples.pry("", "--help")!$
+
View
13 doc-src/coverage.html
@@ -3,7 +3,18 @@
========
The examples in this section can be found in the _examples/project_ directory
-in the __pry__ distribution.
+in the __pry__ distribution. From this directory we can run __pry__ with the -s
+argument to provide a coverage summary:
+$!examples.pry("examples/project/test", "-s")!$
+As the output shows, the test suite does not completely cover the file _one.py_
+- lines 5 and 8 to 11 have not been run. The contents of this file are as
+follows:
+$!examples.py("examples/project/module/one.py", linenos="inline")!$
+
+Line 5 is clearly not covered because it is unreachable. An inspection of the
+relevant portion of the test suite shows that __method2__ is never called:
+
+$!examples.py("examples/project/test/test_one.py")!$
View
14 doc-src/coverage/annotations.html
@@ -1,5 +1,4 @@
-
Many projects contain code that can not be covered by unit tests. Having these
portions show up in test coverage statistics is not helpful, so __pry__
provides a way to annotate code to exempt lines from coverage.
@@ -7,9 +6,14 @@
:::Example
----------
-<!--(block | pySyntax)-->
-$!test_annotation!$
-<!--(end)-->
-<div class="fname">(examples/test_basic.py)</div>
+$!examples.py("examples/project/module/two.py")!$
+
+Even though the code within the __nocover__ block is unreachable, it does not
+show up in analysis output, and _two.py_ has 100% coverage:
+
+$!examples.pry("examples/project/test", "-s")!$
+If a <strong>#begin nocover</strong> directive is not matched by an
+<strong>#end nocover</strong> directive, it applies to the remainder of the
+file.
View
8 doc-src/coverage/dotpry.html
@@ -38,13 +38,7 @@
parallel __test__ directory. The <strong>.pry</strong> file in the test
directory looks like this:
-<pre class="output">
-base = ..
-coverage = ../module
-exclude = ../module/exclude.py
-</pre>
-<div class="fname">(examples/project/test/.pry)</div>
-
+$!examples.plain("examples/project/test/.pry")!$
More .pry syntax
================
View
2  doc-src/coverage/index.py
@@ -2,5 +2,5 @@
pages = [
Page("dotpry.html", ".pry config file"),
- Page("annotations.html", "Annotations"),
+ Page("annotations.html", "Code Annotation"),
]
View
46 doc-src/index.py
@@ -1,3 +1,4 @@
+import os, os.path, subprocess
import countershape.widgets
import countershape.layout
import countershape.grok
@@ -14,19 +15,52 @@
)
this.layout = countershape.layout.TwoPane("yui-t2", "doc3")
-ns.test_basic = readFrom("../examples/test_basic.py")
-ns.test_trees = readFrom("../examples/test_trees.py")
-ns.test_autotree = readFrom("../examples/test_autotree.py")
-ns.test_annotation = readFrom("../examples/project/module/two.py")
+class Examples:
+ def __init__(self, d):
+ self.d = os.path.abspath(d)
+ def _wrap(self, proc, path):
+ f = file(os.path.join(self.d, path)).read()
+ if proc:
+ f = proc(f)
+ post = "<div class=\"fname\">(%s)</div>"%path
+ return f + post
+
+ def py(self, path, **kwargs):
+ return self._wrap(ns.pySyntax.withConf(**kwargs), path)
+
+ def _preProc(self, f):
+ return "<pre class=\"output\">%s</pre>"%f
+
+ def plain(self, path):
+ return self._wrap(self._preProc, path)
+
+ def pry(self, path, args):
+ cur = os.getcwd()
+ os.chdir(os.path.join(self.d, path))
+ prog = os.path.join(self.d, "pry")
+ pipe = subprocess.Popen(
+ "%s "%prog + args,
+ shell=True,
+ stdout=subprocess.PIPE,
+ stderr=subprocess.PIPE
+ ).stdout
+ os.chdir(cur)
+
+ content = "> pry %s\n"%args + pipe.read()
+ return self._preProc(content)
+
+
+ns.examples = Examples("..")
ns.libpry = countershape.grok.grok("../libpry")
pages = [
Page("index.html", "Introduction"),
- Page("start.html", "Writing Tests"),
- Directory("trees"),
+ Page("tests.html", "Writing Tests"),
+ Directory("tests"),
Page("coverage.html", "Coverage"),
Directory("coverage"),
+ Page("profiling.html", "Profiling"),
Page("cli.html", "The pry tool"),
Page("api.html", "API"),
Page("admin.html", "Administrivia")
View
16 doc-src/profiling.html
@@ -0,0 +1,16 @@
+
+__pry__ includes functionality to allow quick-and-dirty profiling and
+benchmarking of code. Consider the following simple example test module:
+
+$!examples.py("examples/test_profile.py")!$
+
+The -n flag specifies the number of times each test being run should be
+repeated. When the verbosity is bumped up to show individual test timings
+(-vv), this is a handy quick comparative benchmarking tool.
+
+$!examples.pry("examples", "-vvn 100000 test_profile.py")!$
+
+The -p flag specifies that a profile run should be done:
+
+$!examples.pry("examples", "-pn 10000 test_profile.py")!$
+
View
31 doc-src/start.html → doc-src/tests.html
@@ -2,11 +2,7 @@
A basic example
===============
-<!--(block | pySyntax)-->
-$!test_basic!$
-<!--(end)-->
-
-<div class="fname">(examples/test_basic.py)</div>
+$!examples.py("examples/test_basic.py")!$
This example should look familiar to anyone who has used the built-in Python
__unittest__ module. The main points to note are:
@@ -32,27 +28,8 @@
Running the tests
=================
-You can find the file above at <span>examples/test_basic.py</span> in the
-__pry__ distribution. From the examples directory, we can run the tests as
-follows:
-
-
-<pre class="output">
-> pry test_basic.py
-.E.
-
-ERRORS
-======
-./test_basic.MySuite.test_three
- Traceback (most recent call last):
- File "./test_basic.py", line 27, in test_three
- assert d["foo"] == "two"
- AssertionError
-
- :: Re-evaluating expression:
- :: d["foo"] == "two"
- :: 'one' == 'two'
+From the <span>examples</span> in the __pry__ distribution, we can run the
+tests as follows:
+$!examples.pry("examples", "test_basic.py")!$
-3 tests (pass: 2, fail: 1) - 0.001s
-</pre>
View
14 doc-src/trees/autotree.html → doc-src/tests/autotree.html
@@ -7,19 +7,9 @@
The following code is functionally equivalent to the example given in the
previous section:
-<!--(block | pySyntax)-->
-$!test_autotree!$
-<!--(end)-->
-<div class="fname">(examples/test_autotree.py)</div>
+$!examples.py("examples/test_autotree.py")!$
Test hierarchy:
-<pre class="output">
-> pry -l test_autotree.py
-./test_autotree
- MyContainer
- test_one
- test_two
-Total: 2
-</pre>
+$!examples.pry("examples", "-l test_autotree.py")!$
View
0  doc-src/trees/index.py → doc-src/tests/index.py
File renamed without changes
View
37 doc-src/trees/tree.html → doc-src/tests/tree.html
@@ -15,10 +15,7 @@
This example constructs a simple tree with one __TestContainer__ containing two
__Test__ nodes:
-<!--(block | pySyntax)-->
-$!test_trees!$
-<!--(end)-->
-<div class="fname">(examples/test_trees.py)</div>
+$!examples.py("examples/test_trees.py")!$
As this example shows, trees can be constructed using nested lists. An
equivalent idiom would be to pass the children of each container node as
@@ -41,30 +38,13 @@
command-line tool. The following command gives a graphical representation of
the test tree structure:
-<pre class="output">
-> pry -l test_trees.py
-./test_trees
- MyContainer
- test_one
- test_two
-Total: 2
-</pre>
+$!examples.pry("examples", "-l test_trees.py")!$
We can illustrate the order in which __setUp__ and __tearDown__ methods are run
by running the suite. We silence __pry__'s output using the -q flag, so we can
focus on just the example output:
-<pre class="output">
-> pry -q test_trees.py
-setUpAll
- setUp
- test_one...
- tearDown
- setUp
- test_two...
- tearDown
-tearDownAll
-</pre>
+$!examples.pry("examples", "-q test_trees.py")!$
Test Paths
@@ -74,14 +54,7 @@
For example, we can run just test_one in the example above by specifying its
path to pry:
-<pre class="output">
-> pry -q test_trees.MyContainer.test_one
-setUpAll
- setUp
- test_one...
- tearDown
-tearDownAll
-</pre>
+$!examples.pry("examples", "-q test_trees.MyContainer.test_one")!$
-Note that the module in which the test occurs can be specfied as the initial
+Note that the module in which the test occurs can be specified as the initial
part of the path.
View
6 examples/project/module/one.py
@@ -3,3 +3,9 @@ def method():
return 1
else:
return 2
+
+def method2():
+ x = 2
+ if x:
+ y = 3
+ z = 1
View
2  examples/project/module/two.py
@@ -1,4 +1,3 @@
-
def method():
if True:
return 1
@@ -6,4 +5,3 @@ def method():
else:
return 2
#end nocover
-
View
1  examples/project/test/test_one.py
@@ -4,7 +4,6 @@
class One(libpry.AutoTree):
def test_a(self):
assert module.one.method() == 1
-
tests = [
One()
View
1  examples/project/test/test_two.py
@@ -4,7 +4,6 @@
class Two(libpry.AutoTree):
def test_a(self):
assert module.two.method() == 1
-
tests = [
Two()
View
16 examples/test_profile.py
@@ -0,0 +1,16 @@
+import libpry
+
+def fib1(n):
+ lst, a, b = [], 0, 1
+ while len(lst) < n:
+ lst.append(b)
+ a, b = b, a+b
+ return lst
+
+class ProfTest(libpry.AutoTree):
+ def test_one(self):
+ assert fib1(10) == [1, 1, 2, 3, 5, 8, 13, 21, 34, 55]
+
+tests = [
+ ProfTest()
+]
View
5 libpry/test.py
@@ -217,8 +217,9 @@ def final(self, root):
width, funcs = s.get_print_list([])
s.print_title()
for f in funcs:
- # We don't want to know about libpry itself.
- if not "/libpry/" in f[0]:
+ # We don't want to know about libpry itself or the profile
+ # disable function.
+ if not "/libpry/" in f[0] and not "_lsprof" in f[2]:
s.print_line(f)
lst.append("\n")
lst.append(s.stream.getvalue())
View
16 pry
@@ -5,10 +5,10 @@ import libpry
def main():
from optparse import OptionParser, OptionGroup
- parser = OptionParser(version="%prog 0.1")
- parser.add_option("-a", "--annotate",
- action="store_true", dest="annotate",
- help="Annotated coverage output.")
+ parser = OptionParser(
+ usage = "%prog [options] [testfilter]",
+ version="%prog 0.1",
+ )
parser.add_option("-c", "--clear",
action="store_true", dest="clear",
help="Clear all .pyc and .pyo files in the project base"
@@ -22,7 +22,7 @@ def main():
help="Recurse through child directories.")
parser.add_option("-s", "--stats",
action="store_true", dest="stats",
- help="Give coverage stats")
+ help="Print coverage summary.")
parser.add_option("-n", "--benchmark",
action="store", dest="benchmark", type="int", default=1,
help="Run each test N times.")
@@ -31,11 +31,11 @@ def main():
help="Quiet.")
parser.add_option("-v", "--verbose",
action="count", dest="verbose", default=1,
- help="Verbose.")
+ help="Increase verbosity. Can be passed multiple times.")
parser.add_option(
"--debug-dump",
action="store_true", dest="debug",
- help="For debugging only. Like list,"
+ help="For debugging only. Like -l,"
" but dump the full tree structure."
)
@@ -80,7 +80,7 @@ def main():
else:
parser.error("Please pass only one argument.")
- if options.annotate or options.stats:
+ if options.stats:
coverage = True
else:
coverage = False
Please sign in to comment.
Something went wrong with that request. Please try again.