diff --git a/.travis.yml b/.travis.yml index f58cecc..5ce4a00 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,8 +3,12 @@ python: - "2.7" - "3.3" - "3.4" +env: + - TORNADO_VERSION=3.2.2 + - TORNADO_VERSION=4.0.2 install: - "pip install -r requirements.txt --use-mirrors" + - "pip install tornado==$TORNADO_VERSION" - "pip install pytest" - "pip install pytest-cov" - "pip install coverage" diff --git a/README.md b/README.md index c5941bf..12a884c 100644 --- a/README.md +++ b/README.md @@ -55,3 +55,12 @@ These dependencies can be satisfied by running `pip install -r requirements.txt` * [tornado](http://www.tornadoweb.org/en/stable/) * [jsonschema](https://python-jsonschema.readthedocs.org/en/latest/) + + +## Running Tests + +```bash +sudo pip2 install tox +sudo pip3 install tox +sudo tox # Will run test matrix +``` diff --git a/README.rst b/README.rst index ae5f2e6..16fc62c 100644 --- a/README.rst +++ b/README.rst @@ -1,5 +1,5 @@ .. contents:: - :depth: 3 + :depth: 3.0 .. Tornado-JSON @@ -79,6 +79,15 @@ These dependencies can be satisfied by running - `tornado `__ - `jsonschema `__ +Running Tests +------------- + +.. code:: bash + + sudo pip2 install tox + sudo pip3 install tox + sudo tox # Will run test matrix + .. |Build Status| image:: https://travis-ci.org/hfaran/Tornado-JSON.png?branch=master :target: https://travis-ci.org/hfaran/Tornado-JSON .. |PyPI version| image:: https://badge.fury.io/py/Tornado-JSON.png diff --git a/maintenance.md b/maintenance.md index fdac771..64a9a7d 100644 --- a/maintenance.md +++ b/maintenance.md @@ -3,21 +3,23 @@ * Update README.rst - ```$ pandoc -s -t rst --toc README.md -o README.rst``` + ```pandoc -s -t rst --toc README.md -o README.rst``` * Install project with files.txt record - ```$ sudo python setup.py install --record files.txt``` + ```sudo python setup.py install --record files.txt``` * "uninstall" package installed with files.txt record - ```$ cat files.txt | sudo xargs rm -rf``` + ```cat files.txt | sudo xargs rm -rf``` * Generate/update base docs/ folder with Sphinx - ```$ sphinx-apidoc -F -o docs tornado_json``` + ```sphinx-apidoc -F -o docs tornado_json``` * Run tests from root project directory - ```$ py.test --cov="tornado_json" --cov-report=term --cov-report=html``` - ```$ nosetests --with-cov --cov-report term-missing --cov tornado_json tests/``` + * `py.test --cov="tornado_json" --cov-report=term --cov-report=html` + * `nosetests --with-cov --cov-report term-missing --cov tornado_json tests/` + * With `tox>=1.8.0` installed for both py27 and py34 + * `sudo tox # runs test matrix with py27,py34 and tornado322,402` diff --git a/tornado_json/application.py b/tornado_json/application.py index 155cb5f..c5b8775 100755 --- a/tornado_json/application.py +++ b/tornado_json/application.py @@ -1,6 +1,7 @@ import tornado.web from tornado_json.api_doc_gen import api_doc_gen +from tornado_json.constants import TORNADO_MAJOR class Application(tornado.web.Application): @@ -21,9 +22,11 @@ def __init__(self, routes, settings, db_conn=None): # Generate API Documentation api_doc_gen(routes) - # Unless gzip was specifically set to False in settings, enable it - if "gzip" not in list(settings.keys()): - settings["gzip"] = True + # Unless compress_response was specifically set to False in + # settings, enable it + compress_response = "compress_response" if TORNADO_MAJOR >= 4 else "gzip" + if compress_response not in settings: + settings[compress_response] = True tornado.web.Application.__init__( self, diff --git a/tornado_json/constants.py b/tornado_json/constants.py index 8b2634d..3ed4698 100644 --- a/tornado_json/constants.py +++ b/tornado_json/constants.py @@ -1 +1,8 @@ +from tornado import version_info as tornado_version_info + + +(TORNADO_MAJOR, + TORNADO_MINOR, + TORNADO_PATCH) = tornado_version_info[:3] + HTTP_METHODS = ["get", "put", "post", "patch", "delete", "head", "options"] diff --git a/tornado_json/schema.py b/tornado_json/schema.py index e39fd6a..d8a501b 100644 --- a/tornado_json/schema.py +++ b/tornado_json/schema.py @@ -4,6 +4,11 @@ from functools import wraps from tornado import gen from tornado.concurrent import Future +try: + from tornado.concurrent import is_future +except ImportError: + # For tornado 3.x.x + is_future = lambda x: isinstance(x, Future) from tornado_json.utils import container @@ -62,7 +67,7 @@ def _wrapper(self, *args, **kwargs): output = rh_method(self, *args, **kwargs) # If the rh_method returned a Future a la `raise Return(value)` # we grab the output. - if isinstance(output, Future): + if is_future(output): output = yield output if output_schema is not None: diff --git a/tox.ini b/tox.ini index 095751b..856fae7 100644 --- a/tox.ini +++ b/tox.ini @@ -1,11 +1,12 @@ [tox] -envlist = py27 +envlist = {py27,py34}-tornado{322,402} [testenv] deps= pytest pytest-cov - tornado + tornado322: tornado==3.2.2 + tornado402: tornado==4.0.2 jsonschema commands=