Velocity Reviews - Computer Hardware Reviews

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

Reply
Thread Tools

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

 
 
Makoto Kuwata
Guest
Posts: n/a
 
      08-27-2011
Hi,

I released Oktest 0.9.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.


Main Enhancements
-----------------

* New '@test' decorator provided. It is simple but very powerful.
Using @test decorator, you can write test description in free text
instead of test method.
ex::

class FooTest(unittest.TestCase):

def test_1_plus_1_should_be_2(self): # not cool...
self.assertEqual(2, 1+1)

@test("1 + 1 should be 2") # cool! easy to read & write!
def _(self):
self.assertEqual(2, 1+1)

* Fixture injection support by '@test' decorator.
Arguments of test method are regarded as fixture names and
they are injected by @test decorator automatically.
Instance methods or global functions which name is 'provide_xxxx' are
regarded as fixture provider (or builder) for fixture 'xxxx'.
ex::

class SosTest(unittest.TestCase):

##
## fixture providers.
##
def provide_member1(self):
return {"name": "Haruhi"}

def provide_member2(self):
return {"name": "Kyon"}

##
## fixture releaser (optional)
##
def release_member1(self, value):
assert value == {"name": "Haruhi"}

##
## testcase which requires 'member1' and 'member2' fixtures.
##
@test("validate member's names")
def _(self, member1, member2):
assert member1["name"] == "Haruhi"
assert member2["name"] == "Kyon"

Dependencies between fixtures are resolved automatically.
ex::

class BarTest(unittest.TestCase):

##
## for example:
## - Fixture 'a' depends on 'b' and 'c'.
## - Fixture 'c' depends on 'd'.
##
def provide_a(b, c): return b + c + ["A"]
def provide_b(): return ["B"]
def provide_c(d): return d + ["C"]
def provide_d(): reutrn ["D"]

##
## Dependencies between fixtures are solved automatically.
##
@test("dependency test")
def _(self, a):
assert a == ["B", "D", "C", "A"]

If loop exists in dependency then @test reports error.

If you want to integrate with other fixture library, see the following
example::

class MyFixtureManager(object):
def __init__(self):
self.values = { "x": 100, "y": 200 }
def provide(self, name):
return self.values[name]
def release(self, name, value):
pass

oktest.fixure_manager = MyFixtureResolver()



Other Enhancements and Changes
------------------------------

* Supports command-line interface to execute test scripts.
* Reporting style is changed.
* New assertion method ``ok(x).attr(name, value)`` to check attribute.
* New assertion method ``ok(x).length(n)``.
* New feature``ok().should`` helps you to check boolean method.
* 'ok(str1) == str2' displays diff if text1 != text2, even when using
with unittest module.
* Assertion ``raises()`` supports regular expression to check error message.
* Helper functions in oktest.dummy module are now available as decorator.
* 'AssertionObject.expected' is renamed to 'AssertionObject.boolean'.
* ``oktest.run()`` is changed to return number of failures and errors of tests.
* ``before_each()`` and ``after_each()`` are now non-supported.
* (Experimental) New function ``NOT()`` provided which is same as ``NG()``.
* (Experimental) ``skip()`` and ``@skip.when()`` are provided to skip tests::

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


Have a nice testing life!

--
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
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.4.0 released - a new-style testing library Makoto Kuwata Python 0 06-26-2010 11:28 PM
[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