Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > [ANN] Oktest 0.4.0 released - a new-style testing library

Reply
Thread Tools

[ANN] Oktest 0.4.0 released - a new-style testing library

 
 
Makoto Kuwata
Guest
Posts: n/a
 
      06-26-2010
I released Oktest 0.4.0.
http://pypi.python.org/pypi/Oktest/
http://packages.python.org/Oktest/


Overview
--------

Oktest is a new-style testing library for Python.
::

from oktest import ok
ok (x) > 0 # same as assert_(x > 0)
ok (s) == 'foo' # same as assertEqual(s, 'foo')
ok (s) != 'foo' # same as assertNotEqual(s, 'foo')
ok (f).raises(ValueError) # same as assertRaises(ValueError, f)
ok (u'foo').is_a(unicode) # same as assert_(isinstance(u'foo', unicode))
not_ok (u'foo').is_a(int) # same as assert_(not isinstance(u'foo', int))
ok ('A.txt').is_file() # same as assert_(os.path.isfile('A.txt'))
not_ok ('A.txt').is_dir() # same as assert_(not os.path.isdir('A.txt'))

You can use ok() instead of 'assertXxx()' in unittest.

Oktest requires Python 2.3 or later. Oktest is ready for Python 3.

NOTICE!! Oktest is a young project and specification may change in the future.


Download
--------

http://pypi.python.org/pypi/Oktest/

Installation::

## if you have installed easy_install:
$ sudo easy_install Oktest
## or download Oktest-$Release$.tar.gz and install it
$ wget http://pypi.python.org/packages/source/O/Oktest/Oktest-$Release$.tar.gz
$ tar xzf Oktest-$Release$.tar.gz
$ cd Oktest-$Release$/
$ sudo python setup.py install


Example
-------

test_example.py::

from oktest import ok, run
import sys, os

## no need to extend TestCase class
class Example1Test(object):

@classmethod
def before_all(self): # invoked only once before all tests
os.mkdir('tmp.d')

@classmethod
def after_all(self): # invoked only once after all tests done
import shutil
shutil.rmtree('tmp.d')

def before(self): # invoked before each test
self.val = ['aaa', 'bbb', 'ccc']

def after(self): # invoked after each test
pass

def test_valtype(self):
ok (type(self.val)) == list

def test_length(self):
ok (len(self.val)) == 3


## 'ok()' is available with unittest.TestCase
import unittest
class Example2Test(unittest.TestCase):

def setUp(self):
self.val = ['aaa', 'bbb', 'ccc']

def test_valtype(self):
ok (type(self.val)) == list

def test_length(self):
ok (len(self.val)) == 3

## invoke tests
if __name__ == '__main__':
from oktest import run
run(Example1Test, Example2Test)
## or
#run('.*Test$') # specify class names by regular expression


Changes in release 0.4.0
------------------------

* enhanced to support 'ok (x).in_delta(y, d)' which raises assertion exception
unless y-d < x < y+d.
* change test script to support Python 2.7 and 3.x.
* fixed a few bugs.



Have fun!

--
regards,
makoto kuwata
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[ANN] Oktest 0.8.0 released - a new-style testing library Makoto Kuwata Python 0 02-15-2011 03:44 PM
Oktest 0.7.0 released - a new-style testing library Makoto Kuwata Python 0 02-05-2011 10:25 PM
[ANN] Oktest 0.6.0 released - a new-style testing library Makoto Kuwata Python 0 01-23-2011 02:00 AM
[ANN] Oktest 0.3.0 released - a new style testing library kwatch Python 0 05-16-2010 07:46 AM
ANN: Oktest 0.2.1 released - a new style testing library. kwatch Python 0 04-19-2010 10:25 PM



Advertisments