[py-svn] py-trunk commit cb903127b5c0: move examples to doc directory

commits-noreply at bitbucket.org commits-noreply at bitbucket.org
Thu Oct 29 18:09:46 CET 2009


# HG changeset patch -- Bitbucket.org
# Project py-trunk
# URL http://bitbucket.org/hpk42/py-trunk/overview/
# User holger krekel <holger at merlinux.eu>
# Date 1256835277 -3600
# Node ID cb903127b5c073e41ea3f82c589a097a873ac800
# Parent f0bb4c025c85966f7acec860239eb7df19fb38b9
move examples to doc directory

--- a/example/genhtmlcss.py
+++ /dev/null
@@ -1,23 +0,0 @@
-import py
-html = py.xml.html 
-
-class my(html):
-    "a custom style"  
-    class body(html.body): 
-        style = html.Style(font_size = "120%") 
-
-    class h2(html.h2): 
-        style = html.Style(background = "grey")
-
-    class p(html.p): 
-        style = html.Style(font_weight="bold")
-
-doc = my.html(
-    my.head(), 
-    my.body(
-        my.h2("hello world"),
-        my.p("bold as bold can") 
-    )
-)
-    
-print doc.unicode(indent=2) 

--- a/example/assertion/test_failures.py
+++ /dev/null
@@ -1,14 +0,0 @@
-
-import py
-failure_demo = py.magic.autopath().dirpath('failure_demo.py')
-
-pytest_plugins = "pytest_pytester"
-
-def test_failure_demo_fails_properly(testdir): 
-    reprec = testdir.inline_run(failure_demo)
-    passed, skipped, failed = reprec.countoutcomes() 
-    assert passed == 0 
-    assert failed == 20, failed
-    colreports = reprec.getreports("pytest_collectreport")
-    failed = len([x.failed for x in colreports])
-    assert failed == 4

--- /dev/null
+++ b/doc/example/genxml.py
@@ -0,0 +1,17 @@
+
+import py 
+class ns(py.xml.Namespace): 
+    pass 
+
+doc = ns.books(
+    ns.book(
+        ns.author("May Day"), 
+        ns.title("python for java programmers"),), 
+    ns.book( 
+        ns.author("why", class_="somecssclass"), 
+        ns.title("Java for Python programmers"),),
+    publisher="N.N", 
+    )
+print doc.unicode(indent=2).encode('utf8')
+
+

--- a/example/assertion/global_testmodule_config/test_hello.py
+++ /dev/null
@@ -1,5 +0,0 @@
-
-hello = "world"
-
-def test_func(): 
-    pass

--- a/example/genhtml.py
+++ /dev/null
@@ -1,13 +0,0 @@
-from py.xml import html 
-
-paras = "First Para", "Second para"
-
-doc = html.html(
-   html.head(
-        html.meta(name="Content-Type", value="text/html; charset=latin1")), 
-   html.body(
-        [html.p(p) for p in paras]))
-
-print unicode(doc).encode('latin1')
-
-

--- /dev/null
+++ b/doc/example/funcarg/mysetup2/test_sample.py
@@ -0,0 +1,6 @@
+
+def test_answer(mysetup): 
+    app = mysetup.myapp()
+    answer = app.question()
+    assert answer == 42
+

--- a/MANIFEST.in
+++ b/MANIFEST.in
@@ -5,7 +5,6 @@ include distribute_setup.py
 include LICENSE 
 graft doc
 graft contrib
-graft example
 graft bin 
 exclude *.orig 
 exclude *.rej 

--- a/example/assertion/global_testmodule_config/conftest.py
+++ /dev/null
@@ -1,7 +0,0 @@
-import py
-
-def pytest_runtest_setup(item):
-    if isinstance(item, py.test.collect.Function):
-        mod = item.getparent(py.test.collect.Module).obj
-        if hasattr(mod, 'hello'):
-            py.builtin.print_("mod.hello", mod.hello)

--- /dev/null
+++ b/doc/example/funcarg/mysetup2/conftest.py
@@ -0,0 +1,24 @@
+import py
+from mysetup2.myapp import MyApp
+
+def pytest_funcarg__mysetup(request):
+    return MySetup(request)
+
+def pytest_addoption(parser):
+    parser.addoption("--ssh", action="store", default=None,
+        help="specify ssh host to run tests with")
+    
+
+class MySetup:
+    def __init__(self, request):
+        self.config = request.config 
+
+    def myapp(self):
+        return MyApp()
+
+    def getsshconnection(self):
+        host = self.config.option.ssh
+        if host is None:
+            py.test.skip("specify ssh host with --ssh")
+        return execnet.SshGateway(host)
+        

--- /dev/null
+++ b/doc/example/funcarg/conftest.py
@@ -0,0 +1,3 @@
+import py
+
+collect_ignore = 'mysetup', 'mysetup2', 'test_simpleprovider.py', 'parametrize'

--- a/example/funcarg/costlysetup/sub1/__init__.py
+++ /dev/null
@@ -1,1 +0,0 @@
-#

--- a/example/funcarg/urloption/conftest.py
+++ /dev/null
@@ -1,15 +0,0 @@
-# conftest.py 
-import py
-
-
-def pytest_addoption(parser):
-    grp = parser.getgroup("testserver options") 
-    grp.addoption("--url", action="store", default=None,
-        help="url for testserver") 
-
-def pytest_funcarg__url(request): 
-    url = request.config.getvalue("url") 
-    if url is None: 
-        py.test.skip("need --url") 
-    return url 
-

--- /dev/null
+++ b/doc/example/funcarg/costlysetup/sub1/test_quick.py
@@ -0,0 +1,3 @@
+
+def test_quick():
+    pass

--- a/example/funcarg/costlysetup/sub2/__init__.py
+++ /dev/null
@@ -1,1 +0,0 @@
-#

--- /dev/null
+++ b/doc/example/genhtml.py
@@ -0,0 +1,13 @@
+from py.xml import html 
+
+paras = "First Para", "Second para"
+
+doc = html.html(
+   html.head(
+        html.meta(name="Content-Type", value="text/html; charset=latin1")), 
+   html.body(
+        [html.p(p) for p in paras]))
+
+print unicode(doc).encode('latin1')
+
+

--- a/example/assertion/test_setup_flow_example.py
+++ /dev/null
@@ -1,42 +0,0 @@
-def setup_module(module):
-    module.TestStateFullThing.classcount = 0
-
-class TestStateFullThing:
-    def setup_class(cls):
-        cls.classcount += 1
-
-    def teardown_class(cls):
-        cls.classcount -= 1
-
-    def setup_method(self, method):
-        self.id = eval(method.__name__[5:])
-
-    def test_42(self):
-        assert self.classcount == 1
-        assert self.id == 42
-
-    def test_23(self):
-        assert self.classcount == 1
-        assert self.id == 23
-
-def teardown_module(module):
-    assert module.TestStateFullThing.classcount == 0
-
-""" For this example the control flow happens as follows::
-    import test_setup_flow_example
-    setup_module(test_setup_flow_example)
-       setup_class(TestStateFullThing)
-           instance = TestStateFullThing()
-           setup_method(instance, instance.test_42)
-              instance.test_42()
-           setup_method(instance, instance.test_23)
-              instance.test_23()
-       teardown_class(TestStateFullThing)
-    teardown_module(test_setup_flow_example)
-
-Note that ``setup_class(TestStateFullThing)`` is called and not
-``TestStateFullThing.setup_class()`` which would require you
-to insert ``setup_class = classmethod(setup_class)`` to make
-your setup function callable.
-"""
-

--- /dev/null
+++ b/doc/example/funcarg/parametrize/test_parametrize.py
@@ -0,0 +1,17 @@
+import py
+
+def pytest_generate_tests(metafunc):
+    for funcargs in metafunc.cls.params[metafunc.function.__name__]:
+        metafunc.addcall(funcargs=funcargs)
+ 
+class TestClass:
+    params = {
+        'test_equals': [dict(a=1, b=2), dict(a=3, b=3), dict(a=5, b=4)],
+        'test_zerodivision': [dict(a=1, b=0), dict(a=3, b=2)],
+    }
+   
+    def test_equals(self, a, b):
+        assert a == b
+
+    def test_zerodivision(self, a, b):
+        py.test.raises(ZeroDivisionError, "a/b")

--- /dev/null
+++ b/doc/example/funcarg/parametrize/test_parametrize3.py
@@ -0,0 +1,15 @@
+
+# following hook can be put unchanged into a local or global plugin 
+def pytest_generate_tests(metafunc):
+    for scenario in metafunc.cls.scenarios:
+        metafunc.addcall(id=scenario[0], funcargs=scenario[1])
+
+
+scenario1 = ('basic', {'attribute': 'value'})
+scenario2 = ('advanced', {'attribute': 'value2'})
+
+class TestSampleWithScenarios:
+    scenarios = [scenario1, scenario2]
+
+    def test_demo(self, attribute):
+        assert isinstance(attribute, str) 

--- /dev/null
+++ b/doc/example/funcarg/test_simpleprovider.py
@@ -0,0 +1,7 @@
+# ./test_simpleprovider.py
+def pytest_funcarg__myfuncarg(request):
+    return 42
+
+def test_function(myfuncarg):
+    assert myfuncarg == 17
+

--- a/example/funcarg/mysetup2/myapp.py
+++ /dev/null
@@ -1,5 +0,0 @@
-
-class MyApp:
-    def question(self):
-        return 6 * 9 
-

--- /dev/null
+++ b/doc/example/assertion/global_testmodule_config/test_hello.py
@@ -0,0 +1,5 @@
+
+hello = "world"
+
+def test_func(): 
+    pass

--- /dev/null
+++ b/doc/example/genhtmlcss.py
@@ -0,0 +1,23 @@
+import py
+html = py.xml.html 
+
+class my(html):
+    "a custom style"  
+    class body(html.body): 
+        style = html.Style(font_size = "120%") 
+
+    class h2(html.h2): 
+        style = html.Style(background = "grey")
+
+    class p(html.p): 
+        style = html.Style(font_weight="bold")
+
+doc = my.html(
+    my.head(), 
+    my.body(
+        my.h2("hello world"),
+        my.p("bold as bold can") 
+    )
+)
+    
+print doc.unicode(indent=2) 

--- a/example/funcarg/parametrize/test_parametrize.py
+++ /dev/null
@@ -1,17 +0,0 @@
-import py
-
-def pytest_generate_tests(metafunc):
-    for funcargs in metafunc.cls.params[metafunc.function.__name__]:
-        metafunc.addcall(funcargs=funcargs)
- 
-class TestClass:
-    params = {
-        'test_equals': [dict(a=1, b=2), dict(a=3, b=3), dict(a=5, b=4)],
-        'test_zerodivision': [dict(a=1, b=0), dict(a=3, b=2)],
-    }
-   
-    def test_equals(self, a, b):
-        assert a == b
-
-    def test_zerodivision(self, a, b):
-        py.test.raises(ZeroDivisionError, "a/b")

--- /dev/null
+++ b/doc/example/funcarg/test_multi_python.py
@@ -0,0 +1,65 @@
+"""
+
+module containing a parametrized tests testing cross-python
+serialization via the pickle module. 
+"""
+import py
+
+pythonlist = ['python2.3', 'python2.4', 'python2.5', 'python2.6'] 
+# 'jython' 'python3.1']
+  
+def pytest_generate_tests(metafunc):
+    if 'python1' in metafunc.funcargnames:
+        assert 'python2' in metafunc.funcargnames
+        for obj in metafunc.function.multiarg.obj:
+            for py1 in pythonlist:
+                for py2 in pythonlist:
+                    metafunc.addcall(id="%s-%s-%s" % (py1, py2, obj), 
+                        param=(py1, py2, obj))
+        
+ at py.test.mark.multiarg(obj=[42, {}, {1:3},])
+def test_basic_objects(python1, python2, obj):
+    python1.dumps(obj)
+    python2.load_and_is_true("obj == %s" % obj)
+
+def pytest_funcarg__python1(request):
+    tmpdir = request.getfuncargvalue("tmpdir")
+    picklefile = tmpdir.join("data.pickle")
+    return Python(request.param[0], picklefile)
+
+def pytest_funcarg__python2(request):
+    python1 = request.getfuncargvalue("python1")
+    return Python(request.param[1], python1.picklefile)
+
+def pytest_funcarg__obj(request):
+    return request.param[2]
+
+class Python:
+    def __init__(self, version, picklefile):
+        self.pythonpath = py.path.local.sysfind(version)
+        if not self.pythonpath:
+            py.test.skip("%r not found" %(version,))
+        self.picklefile = picklefile
+    def dumps(self, obj):
+        dumpfile = self.picklefile.dirpath("dump.py")
+        dumpfile.write(py.code.Source("""
+            import pickle
+            f = open(%r, 'wb')
+            s = pickle.dump(%r, f)
+            f.close()
+        """ % (str(self.picklefile), obj)))
+        py.process.cmdexec("%s %s" %(self.pythonpath, dumpfile))
+        
+    def load_and_is_true(self, expression):
+        loadfile = self.picklefile.dirpath("load.py")
+        loadfile.write(py.code.Source("""
+            import pickle
+            f = open(%r, 'rb')
+            obj = pickle.load(f)
+            f.close()
+            res = eval(%r)
+            if not res:
+                raise SystemExit(1)
+        """ % (str(self.picklefile), expression)))
+        print loadfile
+        py.process.cmdexec("%s %s" %(self.pythonpath, loadfile))

--- /dev/null
+++ b/doc/example/funcarg/costlysetup/sub2/__init__.py
@@ -0,0 +1,1 @@
+#

--- a/example/funcarg/conftest.py
+++ /dev/null
@@ -1,3 +0,0 @@
-import py
-
-collect_ignore = 'mysetup', 'mysetup2', 'test_simpleprovider.py', 'parametrize'

--- a/example/funcarg/mysetup2/__init__.py
+++ /dev/null
@@ -1,1 +0,0 @@
-# XXX this file should not need to be here but is here for proper sys.path mangling 

--- /dev/null
+++ b/doc/example/funcarg/mysetup2/__init__.py
@@ -0,0 +1,1 @@
+# XXX this file should not need to be here but is here for proper sys.path mangling 

--- /dev/null
+++ b/doc/example/assertion/test_setup_flow_example.py
@@ -0,0 +1,42 @@
+def setup_module(module):
+    module.TestStateFullThing.classcount = 0
+
+class TestStateFullThing:
+    def setup_class(cls):
+        cls.classcount += 1
+
+    def teardown_class(cls):
+        cls.classcount -= 1
+
+    def setup_method(self, method):
+        self.id = eval(method.__name__[5:])
+
+    def test_42(self):
+        assert self.classcount == 1
+        assert self.id == 42
+
+    def test_23(self):
+        assert self.classcount == 1
+        assert self.id == 23
+
+def teardown_module(module):
+    assert module.TestStateFullThing.classcount == 0
+
+""" For this example the control flow happens as follows::
+    import test_setup_flow_example
+    setup_module(test_setup_flow_example)
+       setup_class(TestStateFullThing)
+           instance = TestStateFullThing()
+           setup_method(instance, instance.test_42)
+              instance.test_42()
+           setup_method(instance, instance.test_23)
+              instance.test_23()
+       teardown_class(TestStateFullThing)
+    teardown_module(test_setup_flow_example)
+
+Note that ``setup_class(TestStateFullThing)`` is called and not
+``TestStateFullThing.setup_class()`` which would require you
+to insert ``setup_class = classmethod(setup_class)`` to make
+your setup function callable.
+"""
+

--- a/example/funcarg/costlysetup/sub1/test_quick.py
+++ /dev/null
@@ -1,3 +0,0 @@
-
-def test_quick():
-    pass

--- a/example/funcarg/mysetup/myapp.py
+++ /dev/null
@@ -1,5 +0,0 @@
-
-class MyApp:
-    def question(self):
-        return 6 * 9
-

--- /dev/null
+++ b/doc/example/funcarg/costlysetup/sub1/__init__.py
@@ -0,0 +1,1 @@
+#

--- a/example/funcarg/parametrize/test_parametrize2.py
+++ /dev/null
@@ -1,25 +0,0 @@
-import py
-
-# test support code
-def params(funcarglist):
-    def wrapper(function):
-        function.funcarglist = funcarglist
-        return function
-    return wrapper
-
-def pytest_generate_tests(metafunc):
-    for funcargs in getattr(metafunc.function, 'funcarglist', ()):
-        metafunc.addcall(funcargs=funcargs)
-
-
-# actual test code
- 
-class TestClass:
-    @params([dict(a=1, b=2), dict(a=3, b=3), dict(a=5, b=4)], )
-    def test_equals(self, a, b):
-        assert a == b
-
-    @params([dict(a=1, b=0), dict(a=3, b=2)])
-    def test_zerodivision(self, a, b):
-        py.test.raises(ZeroDivisionError, "a/b")
-

--- /dev/null
+++ b/doc/example/funcarg/mysetup/myapp.py
@@ -0,0 +1,5 @@
+
+class MyApp:
+    def question(self):
+        return 6 * 9
+

--- a/example/funcarg/parametrize/test_parametrize3.py
+++ /dev/null
@@ -1,15 +0,0 @@
-
-# following hook can be put unchanged into a local or global plugin 
-def pytest_generate_tests(metafunc):
-    for scenario in metafunc.cls.scenarios:
-        metafunc.addcall(id=scenario[0], funcargs=scenario[1])
-
-
-scenario1 = ('basic', {'attribute': 'value'})
-scenario2 = ('advanced', {'attribute': 'value2'})
-
-class TestSampleWithScenarios:
-    scenarios = [scenario1, scenario2]
-
-    def test_demo(self, attribute):
-        assert isinstance(attribute, str) 

--- a/example/funcarg/test_simpleprovider.py
+++ /dev/null
@@ -1,7 +0,0 @@
-# ./test_simpleprovider.py
-def pytest_funcarg__myfuncarg(request):
-    return 42
-
-def test_function(myfuncarg):
-    assert myfuncarg == 17
-

--- a/example/funcarg/costlysetup/sub2/test_two.py
+++ /dev/null
@@ -1,6 +0,0 @@
-def test_something(setup):
-    assert setup.timecostly == 1
-
-def test_something_more(setup):
-    assert setup.timecostly == 1
-

--- a/example/funcarg/mysetup/__init__.py
+++ /dev/null
@@ -1,1 +0,0 @@
-# XXX this file should not need to be here but is here for proper sys.path mangling 

--- /dev/null
+++ b/doc/example/assertion/test_failures.py
@@ -0,0 +1,14 @@
+
+import py
+failure_demo = py.magic.autopath().dirpath('failure_demo.py')
+
+pytest_plugins = "pytest_pytester"
+
+def test_failure_demo_fails_properly(testdir): 
+    reprec = testdir.inline_run(failure_demo)
+    passed, skipped, failed = reprec.countoutcomes() 
+    assert passed == 0 
+    assert failed == 20, failed
+    colreports = reprec.getreports("pytest_collectreport")
+    failed = len([x.failed for x in colreports])
+    assert failed == 4

--- a/example/funcarg/test_multi_python.py
+++ /dev/null
@@ -1,65 +0,0 @@
-"""
-
-module containing a parametrized tests testing cross-python
-serialization via the pickle module. 
-"""
-import py
-
-pythonlist = ['python2.3', 'python2.4', 'python2.5', 'python2.6'] 
-# 'jython' 'python3.1']
-  
-def pytest_generate_tests(metafunc):
-    if 'python1' in metafunc.funcargnames:
-        assert 'python2' in metafunc.funcargnames
-        for obj in metafunc.function.multiarg.obj:
-            for py1 in pythonlist:
-                for py2 in pythonlist:
-                    metafunc.addcall(id="%s-%s-%s" % (py1, py2, obj), 
-                        param=(py1, py2, obj))
-        
- at py.test.mark.multiarg(obj=[42, {}, {1:3},])
-def test_basic_objects(python1, python2, obj):
-    python1.dumps(obj)
-    python2.load_and_is_true("obj == %s" % obj)
-
-def pytest_funcarg__python1(request):
-    tmpdir = request.getfuncargvalue("tmpdir")
-    picklefile = tmpdir.join("data.pickle")
-    return Python(request.param[0], picklefile)
-
-def pytest_funcarg__python2(request):
-    python1 = request.getfuncargvalue("python1")
-    return Python(request.param[1], python1.picklefile)
-
-def pytest_funcarg__obj(request):
-    return request.param[2]
-
-class Python:
-    def __init__(self, version, picklefile):
-        self.pythonpath = py.path.local.sysfind(version)
-        if not self.pythonpath:
-            py.test.skip("%r not found" %(version,))
-        self.picklefile = picklefile
-    def dumps(self, obj):
-        dumpfile = self.picklefile.dirpath("dump.py")
-        dumpfile.write(py.code.Source("""
-            import pickle
-            f = open(%r, 'wb')
-            s = pickle.dump(%r, f)
-            f.close()
-        """ % (str(self.picklefile), obj)))
-        py.process.cmdexec("%s %s" %(self.pythonpath, dumpfile))
-        
-    def load_and_is_true(self, expression):
-        loadfile = self.picklefile.dirpath("load.py")
-        loadfile.write(py.code.Source("""
-            import pickle
-            f = open(%r, 'rb')
-            obj = pickle.load(f)
-            f.close()
-            res = eval(%r)
-            if not res:
-                raise SystemExit(1)
-        """ % (str(self.picklefile), expression)))
-        print loadfile
-        py.process.cmdexec("%s %s" %(self.pythonpath, loadfile))

--- /dev/null
+++ b/doc/example/funcarg/mysetup/test_sample.py
@@ -0,0 +1,5 @@
+
+def test_answer(mysetup): 
+    app = mysetup.myapp()
+    answer = app.question()
+    assert answer == 42

--- /dev/null
+++ b/doc/example/funcarg/urloption/conftest.py
@@ -0,0 +1,15 @@
+# conftest.py 
+import py
+
+
+def pytest_addoption(parser):
+    grp = parser.getgroup("testserver options") 
+    grp.addoption("--url", action="store", default=None,
+        help="url for testserver") 
+
+def pytest_funcarg__url(request): 
+    url = request.config.getvalue("url") 
+    if url is None: 
+        py.test.skip("need --url") 
+    return url 
+

--- /dev/null
+++ b/doc/example/funcarg/parametrize/test_parametrize2.py
@@ -0,0 +1,25 @@
+import py
+
+# test support code
+def params(funcarglist):
+    def wrapper(function):
+        function.funcarglist = funcarglist
+        return function
+    return wrapper
+
+def pytest_generate_tests(metafunc):
+    for funcargs in getattr(metafunc.function, 'funcarglist', ()):
+        metafunc.addcall(funcargs=funcargs)
+
+
+# actual test code
+ 
+class TestClass:
+    @params([dict(a=1, b=2), dict(a=3, b=3), dict(a=5, b=4)], )
+    def test_equals(self, a, b):
+        assert a == b
+
+    @params([dict(a=1, b=0), dict(a=3, b=2)])
+    def test_zerodivision(self, a, b):
+        py.test.raises(ZeroDivisionError, "a/b")
+

--- /dev/null
+++ b/doc/example/assertion/failure_demo.py
@@ -0,0 +1,122 @@
+from py.test import raises
+import py
+
+def otherfunc(a,b):
+    assert a==b
+
+def somefunc(x,y):
+    otherfunc(x,y)
+
+def otherfunc_multi(a,b): 
+    assert (a == 
+            b) 
+
+def test_generative(param1, param2):
+    assert param1 * 2 < param2
+
+def pytest_generate_tests(metafunc):
+    if 'param1' in metafunc.funcargnames:
+        metafunc.addcall(funcargs=dict(param1=3, param2=6))
+
+class TestFailing(object):
+    def test_simple(self):
+        def f():
+            return 42
+        def g():
+            return 43
+
+        assert f() == g()
+
+    def test_simple_multiline(self):
+        otherfunc_multi(
+                  42,
+                  6*9)
+
+    def test_not(self):
+        def f():
+            return 42
+        assert not f()
+
+    def test_complex_error(self):
+        def f():
+            return 44
+        def g():
+            return 43
+        somefunc(f(), g())
+
+    def test_z1_unpack_error(self):
+        l = []
+        a,b  = l
+
+    def test_z2_type_error(self):
+        l = 3
+        a,b  = l
+
+    def test_startswith(self):
+        s = "123"
+        g = "456"
+        assert s.startswith(g)
+
+    def test_startswith_nested(self):
+        def f():
+            return "123"
+        def g():
+            return "456"
+        assert f().startswith(g())
+
+    def test_global_func(self):
+        assert isinstance(globf(42), float)
+
+    def test_instance(self):
+        self.x = 6*7
+        assert self.x != 42
+
+    def test_compare(self):
+        assert globf(10) < 5
+
+    def test_try_finally(self):
+        x = 1
+        try:
+            assert x == 0
+        finally:
+            x = 0
+
+    def test_raises(self):
+        s = 'qwe'
+        raises(TypeError, "int(s)")
+
+    def test_raises_doesnt(self):
+        raises(IOError, "int('3')")
+
+    def test_raise(self):
+        raise ValueError("demo error")
+
+    def test_tupleerror(self):
+        a,b = [1]
+
+    def test_reinterpret_fails_with_print_for_the_fun_of_it(self):
+        l = [1,2,3]
+        print ("l is %r" % l)
+        a,b = l.pop()
+
+    def test_some_error(self):
+        if namenotexi:
+            pass
+
+    def func1(self):
+        assert 41 == 42
+
+
+# thanks to Matthew Scott for this test
+def test_dynamic_compile_shows_nicely():
+    src = 'def foo():\n assert 1 == 0\n'
+    name = 'abc-123'
+    module = py.std.imp.new_module(name)
+    code = py.code.compile(src, name, 'exec')
+    py.builtin.exec_(code, module.__dict__)
+    py.std.sys.modules[name] = module
+    module.foo()
+
+
+def globf(x):
+    return x+1

--- /dev/null
+++ b/doc/example/funcarg/costlysetup/conftest.py
@@ -0,0 +1,16 @@
+
+def pytest_funcarg__setup(request):
+    return request.cached_setup(
+        setup=lambda: CostlySetup(), 
+        teardown=lambda costlysetup: costlysetup.finalize(),
+        scope="session",
+    )
+
+class CostlySetup:
+    def __init__(self):
+        import time
+        time.sleep(5)
+        self.timecostly = 1
+
+    def finalize(self):
+        del self.timecostly 

--- a/example/funcarg/mysetup2/test_ssh.py
+++ /dev/null
@@ -1,5 +0,0 @@
-
-class TestClass:
-    def test_function(self, mysetup):
-        conn = mysetup.getsshconnection()
-        # work with conn 

--- a/example/funcarg/mysetup/conftest.py
+++ /dev/null
@@ -1,9 +0,0 @@
-
-from mysetup.myapp import MyApp
-
-def pytest_funcarg__mysetup(request):
-    return MySetup()
-
-class MySetup:
-    def myapp(self):
-        return MyApp()

--- a/example/funcarg/mysetup2/test_sample.py
+++ /dev/null
@@ -1,6 +0,0 @@
-
-def test_answer(mysetup): 
-    app = mysetup.myapp()
-    answer = app.question()
-    assert answer == 42
-

--- a/example/genxml.py
+++ /dev/null
@@ -1,17 +0,0 @@
-
-import py 
-class ns(py.xml.Namespace): 
-    pass 
-
-doc = ns.books(
-    ns.book(
-        ns.author("May Day"), 
-        ns.title("python for java programmers"),), 
-    ns.book( 
-        ns.author("why", class_="somecssclass"), 
-        ns.title("Java for Python programmers"),),
-    publisher="N.N", 
-    )
-print doc.unicode(indent=2).encode('utf8')
-
-

--- /dev/null
+++ b/doc/example/assertion/global_testmodule_config/conftest.py
@@ -0,0 +1,7 @@
+import py
+
+def pytest_runtest_setup(item):
+    if isinstance(item, py.test.collect.Function):
+        mod = item.getparent(py.test.collect.Module).obj
+        if hasattr(mod, 'hello'):
+            py.builtin.print_("mod.hello", mod.hello)

--- a/example/funcarg/costlysetup/conftest.py
+++ /dev/null
@@ -1,16 +0,0 @@
-
-def pytest_funcarg__setup(request):
-    return request.cached_setup(
-        setup=lambda: CostlySetup(), 
-        teardown=lambda costlysetup: costlysetup.finalize(),
-        scope="session",
-    )
-
-class CostlySetup:
-    def __init__(self):
-        import time
-        time.sleep(5)
-        self.timecostly = 1
-
-    def finalize(self):
-        del self.timecostly 

--- /dev/null
+++ b/doc/example/funcarg/mysetup/__init__.py
@@ -0,0 +1,1 @@
+# XXX this file should not need to be here but is here for proper sys.path mangling 

--- /dev/null
+++ b/doc/example/funcarg/mysetup2/test_ssh.py
@@ -0,0 +1,5 @@
+
+class TestClass:
+    def test_function(self, mysetup):
+        conn = mysetup.getsshconnection()
+        # work with conn 

--- /dev/null
+++ b/doc/example/funcarg/mysetup2/myapp.py
@@ -0,0 +1,5 @@
+
+class MyApp:
+    def question(self):
+        return 6 * 9 
+

--- a/example/funcarg/mysetup2/conftest.py
+++ /dev/null
@@ -1,24 +0,0 @@
-import py
-from mysetup2.myapp import MyApp
-
-def pytest_funcarg__mysetup(request):
-    return MySetup(request)
-
-def pytest_addoption(parser):
-    parser.addoption("--ssh", action="store", default=None,
-        help="specify ssh host to run tests with")
-    
-
-class MySetup:
-    def __init__(self, request):
-        self.config = request.config 
-
-    def myapp(self):
-        return MyApp()
-
-    def getsshconnection(self):
-        host = self.config.option.ssh
-        if host is None:
-            py.test.skip("specify ssh host with --ssh")
-        return execnet.SshGateway(host)
-        

--- /dev/null
+++ b/doc/example/funcarg/costlysetup/sub2/test_two.py
@@ -0,0 +1,6 @@
+def test_something(setup):
+    assert setup.timecostly == 1
+
+def test_something_more(setup):
+    assert setup.timecostly == 1
+

--- a/example/assertion/failure_demo.py
+++ /dev/null
@@ -1,122 +0,0 @@
-from py.test import raises
-import py
-
-def otherfunc(a,b):
-    assert a==b
-
-def somefunc(x,y):
-    otherfunc(x,y)
-
-def otherfunc_multi(a,b): 
-    assert (a == 
-            b) 
-
-def test_generative(param1, param2):
-    assert param1 * 2 < param2
-
-def pytest_generate_tests(metafunc):
-    if 'param1' in metafunc.funcargnames:
-        metafunc.addcall(funcargs=dict(param1=3, param2=6))
-
-class TestFailing(object):
-    def test_simple(self):
-        def f():
-            return 42
-        def g():
-            return 43
-
-        assert f() == g()
-
-    def test_simple_multiline(self):
-        otherfunc_multi(
-                  42,
-                  6*9)
-
-    def test_not(self):
-        def f():
-            return 42
-        assert not f()
-
-    def test_complex_error(self):
-        def f():
-            return 44
-        def g():
-            return 43
-        somefunc(f(), g())
-
-    def test_z1_unpack_error(self):
-        l = []
-        a,b  = l
-
-    def test_z2_type_error(self):
-        l = 3
-        a,b  = l
-
-    def test_startswith(self):
-        s = "123"
-        g = "456"
-        assert s.startswith(g)
-
-    def test_startswith_nested(self):
-        def f():
-            return "123"
-        def g():
-            return "456"
-        assert f().startswith(g())
-
-    def test_global_func(self):
-        assert isinstance(globf(42), float)
-
-    def test_instance(self):
-        self.x = 6*7
-        assert self.x != 42
-
-    def test_compare(self):
-        assert globf(10) < 5
-
-    def test_try_finally(self):
-        x = 1
-        try:
-            assert x == 0
-        finally:
-            x = 0
-
-    def test_raises(self):
-        s = 'qwe'
-        raises(TypeError, "int(s)")
-
-    def test_raises_doesnt(self):
-        raises(IOError, "int('3')")
-
-    def test_raise(self):
-        raise ValueError("demo error")
-
-    def test_tupleerror(self):
-        a,b = [1]
-
-    def test_reinterpret_fails_with_print_for_the_fun_of_it(self):
-        l = [1,2,3]
-        print ("l is %r" % l)
-        a,b = l.pop()
-
-    def test_some_error(self):
-        if namenotexi:
-            pass
-
-    def func1(self):
-        assert 41 == 42
-
-
-# thanks to Matthew Scott for this test
-def test_dynamic_compile_shows_nicely():
-    src = 'def foo():\n assert 1 == 0\n'
-    name = 'abc-123'
-    module = py.std.imp.new_module(name)
-    code = py.code.compile(src, name, 'exec')
-    py.builtin.exec_(code, module.__dict__)
-    py.std.sys.modules[name] = module
-    module.foo()
-
-
-def globf(x):
-    return x+1

--- /dev/null
+++ b/doc/example/funcarg/mysetup/conftest.py
@@ -0,0 +1,9 @@
+
+from mysetup.myapp import MyApp
+
+def pytest_funcarg__mysetup(request):
+    return MySetup()
+
+class MySetup:
+    def myapp(self):
+        return MyApp()

--- a/example/funcarg/mysetup/test_sample.py
+++ /dev/null
@@ -1,5 +0,0 @@
-
-def test_answer(mysetup): 
-    app = mysetup.myapp()
-    answer = app.question()
-    assert answer == 42



More information about the pytest-commit mailing list