Tuesday, November 21, 2006

Python talk at NSS Palakkad, Kerala

Yesterday, I had a talk on Python at N S S College of
Engineering, Palakkad (http://www.nssce.ac.in/) . The talk was
arranged by the computer science student's free software
community. There were 100+ students. I used the same slides
which I prepared for my another talk in last
September (http://baijum81.livejournal.com/14649.html)
I took almost 1 and 1/2 hours.

Sunday, November 5, 2006

My Marriage

My marriage is on next Sunday (12 November 2006).
I will be away from net for few days :)

Wednesday, November 1, 2006

First look at test layers from zope.testing

Recently Zope team has released zope.testing version 3.0 .
For more info : http://cheeseshop.python.org/pypi/zope.testing
To install : # easy_install zope.testing

This is an independent testing framework which can be used outside Zope.
One of the interesting feature is test layers. I think next Zope 3 release (3.4)
will make use test layers heavily, so I started looking at this feature.

The test layer API is here:
http://svn.zope.org/zope.testing/trunk/src/zope/testing/testrunner-layers-api.txt?view=auto

I will show you a simple example.

First a 'hello.py':

def hello():
return 'Hello'


Then 'tests.py':

import hello
import unittest

class FirstLayer(object):
pass

class TestHello(unittest.TestCase):
layer = FirstLayer
def test_hello(self):
assert hello.hello() == 'Hello'

def test_suite():
return unittest.TestSuite((unittest.makeSuite(TestHello)))


The only thing to note here is the 'layer' attribute of 'TestHello' class.
We can add 'setUp' and 'tearDown' methods to 'FirstLayer' class.

Now create a script, 'runtest.py':

import sys
from zope.testing import testrunner
defaults = ['--test-path', '.', '--tests-pattern', 'tests$',]
testrunner.run(defaults)


When running the script, you will get something like:

Running tests.FirstLayer tests:
Set up tests.FirstLayer in 0.000 seconds.
Ran 1 tests with 0 failures and 0 errors in 0.000 seconds.
Tearing down left over layers:
Tear down tests.FirstLayer in 0.000 seconds.