It’s just data

Unbundling Pirate Tests

Pirate's unittests were structured in the conventional way: one class with a large number of test_* methods, each containing a single test case.  One of my first changes to Pirate was to unbundle these into separate files.  I did this using a trick I picked up from Mark Pilgrim, namely to create a loop which dynamically created test_* methods, one per file, thus:

# For every test/*/filename.py file, create a test_filename method
for test in sys.argv[1:] or glob("test/*/*.py"):
    testName = "test_" + os.path.splitext(os.path.split(test)[1])[0]
    testFunc = lambda self, test=test: self.runTest(test)
    testFunc.__doc__ = testName
    instanceMethod = new.instancemethod(testFunc, None, PirateTest)
    setattr(PirateTest, testName, instanceMethod)

I admire your ability to get paid for this.

Posted by Mark at

A pattern to dynamically create single-test testcases...

Excerpt from del.icio.us/tag/python at

What's the advantage of having each test in a separate file?

Posted by Ken MacLeod at

Ken: Got a script that fails?  Copy it into the test directory.  Instant test case!

Best of all, output is compared against what CPython produces, instead of what you might guess the output to be.

In the case of the feedvalidator tests, a description and an indication of the expected results needed to be added to the sample feed.

In both cases, another benefit is that the test can be run standalone, and independent of any unit test environment.  For example, do you see what is wrong with this issued date?

Posted by Sam Ruby at

Dynamic testing

Kickstarting a new test suite for a RSS parser is a good chance to verify Ruby's dynamic testing capabilities....

Excerpt from Through the blogging-glass at

Sharing exceptions between Python and Ruby

An essential piece of software behind Blogamundo is a full-fledged multi-user RSS (and Atom) aggregator. We’re building the web UI with Rails, so we were naturally looking forward to writing our feed poller in Ruby. As it turns out, though,...

Excerpt from Blogamundo Hacklog at

Sam Ruby: Unbundling Pirate Tests

‘I admire your ability to get paid for this.’ — Mark Pilgrim...

Excerpt from del.icio.us/tag/python at

Pirate Testing (Because Only Ninjas Write Unit Tests)

I’ve got a new favorite development technique, “pirate testing”. I’ve used it on 3 recent projects, and it rocks. And while Sam might have meant it literally, I’ve found it perfectly describes the practice of shanghaiing another tool’s test suite...

Excerpt from Laughing Meme at

On rFeedParser

This post is huge but I have not the time to make it smaller. I’m so very tired. A Quick Introduction rFeedParser is a RSS/Atom feed parser. It is a translation of Mark Pilgrim’s feedparser from Python to Ruby. It behaves almost exactly...

Excerpt from Something Similar at

Pirate testing

This is an example of pirate testing. It’s using a test-suite consisting of language-neutral data . There’s also a ruby implementation . So what’s pirate testing? It’s a form of data-driven testing. The tests are specified in a language neutral...

Excerpt from Heuristic Outcomes at

Add your comment