[ANN] Oktest.py 0.14.0 released - a new-style testing library

Makoto Kuwata kwa at kuwata-lab.com
Mon Mar 10 15:23:46 CET 2014


I released Oktest.py 0.14.0.
http://pypi.python.org/pypi/Oktest/
http://packages.python.org/Oktest/

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

    from oktest import ok, NG
    ok (x) > 0                 # same as assertTrue(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 assertTrue(isinstance(u'foo',
unicode))
    ok ('A.txt').is_file()     # same as assertTrue(os.path.isfile('A.txt'))

It supports WSGI Application testing::

    from oktest.web import WSGITest
    http = WSGITest(app)
    resp = http.GET('/')
    ok (resp).is_response(200).json({"status": "OK"})

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


New features
------------

* [enhance] Response object returned by `WSGITest#GET()' or '#POST()' now
  supports `body_json' property.
  Example::

      from oktest.web import WSGITest
      http = WSGITest(app)
      resp = http.GET('/')
      print(resp.body_json)

* [change] `headers` argument of `WSGITest#GET()' (or '#POST()' and so on)
  now means HTTP headers, not environ values.
  Example::

      ## version <= 0.13
      http.GET('/', headers={'HTTP_COOKIE': 'name=val'})

      ## version >= 0.14
      http.GET('/', headers={'Cookie': 'name=val'})
      ## or
      http.GET('/', environ={'HTTP_COOKIE': 'name=val'})

* [enhance] (Experimental) `oktest.validator.Validator' class is added.
  It is convenient to test complex data structure.
  Example::

      from oktest.validator import Validator as V
      ok (resp.body_json) == {
        "status": "OK",
        "member": {
          "name":     "Haruhi",
          "gender":   V('gender', enum=('F', 'M')),
          "age":      V('age', type=int, between=(15, 18)),
          "birthday": V('created_at', pattern=r'^\d\d\d\d-\d\d-\d\d$')
        }
      }

  See users guide for details.
  http://www.kuwata-lab.com/oktest/oktest-py_users-guide.html#validator


--
regars,
makoto kuwata
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20140310/2e0984d8/attachment.html>


More information about the Python-list mailing list