Download presentation
Presentation is loading. Please wait.
Published byJoan Cox Modified over 9 years ago
1
Testing Tools for Programmers (twill, scotch, figleaf, wsgi_intercept, and pinocchio) C. Titus Brown titus@idyll.org C. Titus Brown titus@idyll.org Talk slides & code at ‘http://www.idyll.org/pycon07.zip’
2
This is a concept & demo talk. I’m not selling anything. I’m not giving a tutorial. This stuff is useful and fun. I have published the slides and demo code if you want to look into anything.
3
Testing tools for programmers must be simple, easy to deploy & use, and configurable. Otherwise people won’t use them.
4
Functional Web testing with twill go http://www.google.com/http://www.google.com/ showforms formvalue 1 q “google query statistics” submit show forms, cookies, redirects, http basic auth, link following, link checking, http code assertions, test for text presence/nonpresence, tidy checking, etc. no JavaScript support ;( go http://www.google.com/http://www.google.com/ showforms formvalue 1 q “google query statistics” submit show forms, cookies, redirects, http basic auth, link following, link checking, http code assertions, test for text presence/nonpresence, tidy checking, etc. no JavaScript support ;(
5
twill is Python from twill.commands import * go(‘http://www.google.com/’)http://www.google.com/’) showforms() formvalue(‘1’, ‘q’, “google query statistics”) submit() show() All base twill commands directly accessible from Python. Additionally, a “nice” wrapper around mechanize is available. from twill.commands import * go(‘http://www.google.com/’)http://www.google.com/’) showforms() formvalue(‘1’, ‘q’, “google query statistics”) submit() show() All base twill commands directly accessible from Python. Additionally, a “nice” wrapper around mechanize is available.
6
wsgi_intercept lets twill talk directly to WSGI apps. app = get_wsgi_app() import twill twill.add_wsgi_intercept(‘localhost’, 80, lambda: app) twill.commands.go(‘http://localhost/’) … twill.remove_wsgi_intercept(‘http://localhost/’) This is fairly close in concept to paste.fixture, but you can use the same script for testing a direct WSGI connection as you can for testing your whole “Web stack” (server + middleware + app). (Will show you demo) app = get_wsgi_app() import twill twill.add_wsgi_intercept(‘localhost’, 80, lambda: app) twill.commands.go(‘http://localhost/’) … twill.remove_wsgi_intercept(‘http://localhost/’) This is fairly close in concept to paste.fixture, but you can use the same script for testing a direct WSGI connection as you can for testing your whole “Web stack” (server + middleware + app). (Will show you demo)
7
scotch lets you record & replay WSGI data, and generate twill scripts too. app = get_wsgi_app() import scotch.recorder recorder = scotch.recorder.Recorder(app) serve_wsgi(recorder) … app = get_wsgi_app() for record in recorder.record_holder: print record.replay(app) app = get_wsgi_app() import scotch.recorder recorder = scotch.recorder.Recorder(app) serve_wsgi(recorder) … app = get_wsgi_app() for record in recorder.record_holder: print record.replay(app)
8
figleaf is a code coverage recording tool. import figleaf figleaf.start() … figleaf.stop() figleaf.write_coverage(‘.figleaf’) Intended for programmatic use; can take coverage from multiple runs/deployments/platforms, and intersect/union results. Can retrieve from running Web server. import figleaf figleaf.start() … figleaf.stop() figleaf.write_coverage(‘.figleaf’) Intended for programmatic use; can take coverage from multiple runs/deployments/platforms, and intersect/union results. Can retrieve from running Web server.
9
Demos, part I CherryPy: 1. Unit tests with twill are easy. 2. Unit tests with twill talking directly to WSGI are easier. 3. Some simple code coverage analysis. 4. Some not-so-simple code coverage analysis. 5. A twill extension to do simple “fuzz” testing.
10
Demos, part II Django: 1. You can also test Django apps. 2. Recording a new Django test with scotch. 3. Converting the Django test into a twill script. 4. Playing back the Django test.
11
Next steps twill/scotch/figleaf/pinocchio/wsgi_intercept release (much of this stuff is in “-latest”, not released) Improve figleaf dramatically (only minimally usable ;) Document. Now y’all test, y’here? twill/scotch/figleaf/pinocchio/wsgi_intercept release (much of this stuff is in “-latest”, not released) Improve figleaf dramatically (only minimally usable ;) Document. Now y’all test, y’here?
12
Resources Google “python” + package. http://ivory.idyll.org/blog/ titus@idyll.org New! ‘testing-in-python’ mailing list.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.