A cool post
on combining KCacheGrind with cProfile. This is something I need to
Web testing in other languages
On the off chance that you want to actually develop Web sites in a
non-Ruby/non-Python environment, it's useful to know that you can
also test them in the same languages. (I do think twill is a
perfectly fine way to test non-Python Web sites; more on that anon.)
Here's a PHP
framework called Web Tester, and it looks like Perl's
WWW::Mechanize::Shell is very similar to twill.
One entertaining thing is how enthusiastic
people get about Web testing when they discover things like Web Tester
(and, dare I say, twill ;). (I wuz there myself, back when.) It's
really a moment of enlightenment for people when they realize that it's
in fact relatively easy to write functional Web tests.
I sent Bruce
Schneier's article on false positives/false negatives on to several Bush
supporter friends of mine. (Such people are rare at Caltech, admittedly!)
One friend responded with an argument that (as far as I could tell) boiled
down to (a) we don't have any better way to look for terrorist plots, and (b)
we're all doomed anyway. I guess that's a variant of the Christian fatalist
attitude that "Armageddon will be here soon anyway, so who cares what we do"?
Not sure. Very odd.
Buying books online
Between Baen and Fictionwise, there are some good options out there for the kind of
trashy books I like to read...
Potential twill coolness
One the of most rewarding things about working on a medium-term
project like twill is the ability to periodically indulge in a nifty hack
that people might actually use.
Here are two such minor hacks.
First, last night I whipped a quick link checker into shape. With the
latest (0.8.4a5) version
of twill, you can do this:
>> go http://www.idyll.org/
>> extend_with check_links
Gathered URL http://pywx.idyll.org.
Gathered URL http://alife7.alife.org/.
Gathered URL http://www.wrightflyer.org/.
Gathered URL http://www.idyll.org/~t/.
Trying http://www.wrightflyer.org/ ==> at http://www.wrightflyer.org/ ...success!
Trying http://www.idyll.org/~t/ ==> at http://www.idyll.org/~t/ ...success!
Trying http://pywx.idyll.org ==> at http://pywx.idyll.org ...success!
Trying http://alife7.alife.org/ ==> at http://alife7.alife.org/ ...success!
Particularly nifty things about this link checker:
- since the link checker is built on top of twill, you can navigate to pages,
log in, get/set cookies, set auth headers, etc. before link checking.
- likewise, because the links are actually followed, referrer
headers are set correctly.
- as an extension, it serves as both a simple example of how to write
more complex link checkers, and it doesn't get in the way of normal twill
(I plan to also add a little site crawler along the same lines as the
link checker. Stay tuned.)
Second hack: tracebacks now give you the line number in twill scripts.
Suppose you have an error (in this case, a contrived error asserting
that a page failed with 'code 400') in a script. There are other ways
of figuring what line it's at, but here's one that fits right into your
File "/usr/local/lib/python2.3/site-packages/twill-0.8.4a5-py2.3.egg/EGG-INFO/scripts/twill-sh", line 20, in ?
File "/usr/local/lib/python2.3/site-packages/twill-0.8.4a5-py2.3.egg/twill/shell.py", line 248, in main
File "/usr/local/lib/python2.3/site-packages/twill-0.8.4a5-py2.3.egg/twill/parse.py", line 155, in execute_file
File "/usr/local/lib/python2.3/site-packages/twill-0.8.4a5-py2.3.egg/twill/parse.py", line 196, in _execute_script
execute_command(cmd, args, globals_dict, locals_dict, cmdinfo)
File "/usr/local/lib/python2.3/site-packages/twill-0.8.4a5-py2.3.egg/twill/parse.py", line 106, in execute_command
result = eval(codeobj, globals_dict, locals_dict)
File "tst3:2", line 0, in ?
File "/usr/local/lib/python2.3/site-packages/twill-0.8.4a5-py2.3.egg/twill/commands.py", line 119, in code
raise TwillAssertionError("code is %s != %s" % (browser.get_code(),
twill.errors.TwillAssertionError: code is 200 != 400
Yep, the bold line is the actual line in the script file that I ran.
(I actually whipped this together for some unit tests where only the
traceback was being printed. Very handy in that particular instance.)
One very amusing side effect is that coverage analysis records that line in
that file, despite the fact that it's not actually Python code. Heh**2.
Automating your tests to run in buildbot
I spent many hours writing up a fairly shallow
summary of how we automated the heck out of every damn type of
test we used for our PyCon tutorial. (Grig even claims that
it's entertaining. OK, so I am your monkey. ;)
This is the thing to read if you want to know how we automated
Selenium tests, FitNesse tests, twill tests, texttest tests, and
egg build/install tests. It's structured as a narrative
with explicit links to source and config files.
Let me say that I am immensely proud of this stuff and I think
it could be very valuable to people setting up any kind of
continuous integration framework. It took us many moons to work out
the details of how to get this stuff to actually run automatically in
buildbot, and it wasn't easy. But it all works!
Also, please comment on it.