I released Oktest 0.8.0.

Oktest is a new-style testing library for Python.

from oktest import ok, NG
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))
NG (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'))
NG ('A.txt').is_dir() # same as assert_(not os.path.isdir('A.txt'))

See http://packages.python.org/Oktest/ for details.

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

Enhancements and Changes

* add ``NG()`` which is same as not_ok().

* enhanced to proive egg files for Python 3.

* enhanced to support assertion method chaining. ::

ok ("sos".upper()).is_a(str).matches(r'^[A-Z]+$') == "SOS"

* ``ok().matches()`` can take flag parameter which is passed to re.compile().

ok ("\nSOS\n").matches(r'^[A-Z]+$', re.M)
## same as:
#ok("\nSOS\n").matches(r.compile(r'^[A-Z]$', re.M))

* enhance helper methods to be available without with-statement.
(this is necessary for Python 2.4 which is default version on CentOS.)

from oktest.helper import chdir

def fn():
ok (os.getcwd()) == "/tmp"
## this is same as:
#with chdir("/tmp"):
# ok (os.getcwd()) == "/tmp"

from oktest.dummy import dummy_file

def fn():
ok ("A.txt").is_file()
ok (open("A.txt").read()) == "SOS"
dummy_file("A.txt", "SOS").run(fun)
## this is same as:
#with dummy_file("A.txt", "SOS"):
# ok (open("A.txt").read()) == "SOS"

* ``spec()`` now checks environment variable $SPEC.
This is useful to filter test cases.

## test script
from oktest import oktest, run
class StrTest(object):
def test_upper(self):
if spec("returns upper case string"):
ok ("sos".upper()) == "SOS"
if spec("doesn't change non-alphabetics"):
ok ("sos123<>".upper()) == "SOS123<>"
if __name__ == "__main__":

## terminal
$ SPEC="returns upper case string" python test1.py

* fix ``oktest.run()`` to print correct traceback if ok() is called from
nested function.

* fix content of README.txt.

makoto kuwata

Search Discussions

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 1 of 1 | next ›
Discussion Overview
grouppython-list @
postedFeb 15, '11 at 3:44p
activeFeb 15, '11 at 3:44p

1 user in discussion

Makoto Kuwata: 1 post



site design / logo © 2023 Grokbase