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

Discussion in 'Python' started by Makoto Kuwata, Feb 15, 2011.

  1. 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
    Makoto Kuwata, Feb 15, 2011
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. kwatch
    Replies:
    0
    Views:
    256
    kwatch
    Apr 19, 2010
  2. kwatch
    Replies:
    0
    Views:
    193
    kwatch
    May 16, 2010
  3. Makoto Kuwata
    Replies:
    0
    Views:
    250
    Makoto Kuwata
    Jun 27, 2010
  4. Makoto Kuwata
    Replies:
    0
    Views:
    175
    Makoto Kuwata
    Jan 23, 2011
  5. Makoto Kuwata
    Replies:
    0
    Views:
    132
    Makoto Kuwata
    Aug 27, 2011
Loading...

Share This Page