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

Makoto Kuwata kwa at kuwata-lab.com
Tue Feb 15 10:44:52 EST 2011


I released Oktest 0.8.0.
http://pypi.python.org/pypi/Oktest/
http://packages.python.org/Oktest/

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"
    chdir("/tmp").run(fn)
    ## 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__":
      run()

    ## 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.


--
regards,
makoto kuwata



More information about the Python-list mailing list