Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #64546
| Date | 2014-01-23 10:14 +0900 |
|---|---|
| Subject | [ANN] Oktest.py 0.13.0 - a new style testing library |
| From | Makoto Kuwata <kwa@kuwata-lab.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.5854.1390439699.18130.python-list@python.org> (permalink) |
[Multipart message — attachments visible in raw view] - view raw
Oktest 0.13.0 is released.
https://pypi.python.org/pypi/Oktest/
Oktest is a new-style testing library for Python.
## unittest
self.assertEqual(x, y)
self.assertNotEqual(x, y)
self.assertGreaterEqual(x, y)
self.assertIsInstance(obj, cls)
self.assertRegexpMatches(text, rexp)
## Oktest.py
ok (x) == y
ok (x) != y
ok (x) >= y
ok (obj).is_a(cls)
ok (text).match(rexp)
It is possible to assert WebOb/Werkzeug/Requests response object easily.
ok (response).is_response(200).json({"status":"OK"})
Install
$ easy_install oktest
User's Guide
http://www.kuwata-lab.com/oktest/oktest-py_users-guide.html
Changes
http://www.kuwata-lab.com/oktest/oktest-py_CHANGES.txt
What's New
----------
* [enhance] `ok().is_response()' now supports Requests.
Example::
import requests
resp = requests.get('http://www.example.com/')
ok (resp).is_response(200, 'text/html')
* [enhance] (Experimental) Add 'oktest.web' module to help WSGI app testing.
Example::
## create WSGI application
class App(object):
def __call__(self, environ, start_response):
status = '200 OK'
headers = [('Content-Type', 'application/json')]
body = [b'''{"message":"Hello!"}'''] # bytes, not unicode
start_response(status, headers)
return body
app = App()
## test for app
import unittest
import oktest
from oktest import test, ok, subject
from oktest.web import WSGITest # !!!!!
http = WSGITest(app) # !!!!!
https = WSGITest(app, {'HTTPS': 'on'}) # !!!!!
class AppTest(unittest.TestCase):
with subject('GET /'):
@test("Returns messaging JSON.")
def _(self):
resp = http.GET('/') # or http('GET', '/')
ok (resp).is_response(200).json({"message": "Hello!"})
## or
status, headers, body = http.GET('/') # or http('GET',
'/')
ok (status) == '200 OK'
ok (headers) == [('Content-Type', 'application/json')]
ok (body) == [b'''{"message":"Hello!"}''']
if __name__ == '__main__':
oktest.main()
--
regars,
makoto kuwata
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
[ANN] Oktest.py 0.13.0 - a new style testing library Makoto Kuwata <kwa@kuwata-lab.com> - 2014-01-23 10:14 +0900
csiph-web