From cdd7f2967065a90be6cef0b382029d917d60a8b0 Mon Sep 17 00:00:00 2001 From: hfaran Date: Fri, 21 Nov 2014 13:52:39 -0800 Subject: [PATCH 1/7] Replace deprecated gzip with compress_response --- tornado_json/application.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tornado_json/application.py b/tornado_json/application.py index 155cb5f..c252fd5 100755 --- a/tornado_json/application.py +++ b/tornado_json/application.py @@ -21,9 +21,10 @@ 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 + if "compress_response" not in settings: + settings["compress_response"] = True tornado.web.Application.__init__( self, From 98d0634fcd27d92ce6e93a4e7b778ec5894f5549 Mon Sep 17 00:00:00 2001 From: hfaran Date: Fri, 21 Nov 2014 14:19:57 -0800 Subject: [PATCH 2/7] Be backwards compatible with tornado 3 for gzip --- tornado_json/application.py | 6 ++++-- tornado_json/constants.py | 7 +++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/tornado_json/application.py b/tornado_json/application.py index c252fd5..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): @@ -23,8 +24,9 @@ def __init__(self, routes, settings, db_conn=None): # Unless compress_response was specifically set to False in # settings, enable it - if "compress_response" not in settings: - settings["compress_response"] = True + 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"] From 12a6ba38ef40343b65588c166c17d73e1d041bd6 Mon Sep 17 00:00:00 2001 From: hfaran Date: Fri, 21 Nov 2014 14:31:02 -0800 Subject: [PATCH 3/7] Test both tornado==3.2.2 and tornado==4.0.2 --- .travis.yml | 4 ++++ 1 file changed, 4 insertions(+) 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" From e3576c9ea7646701354b7728b53ecfce91531107 Mon Sep 17 00:00:00 2001 From: hfaran Date: Fri, 21 Nov 2014 14:41:37 -0800 Subject: [PATCH 4/7] Use tornado.gen.is_future for checking if result is a Future --- tornado_json/schema.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tornado_json/schema.py b/tornado_json/schema.py index e39fd6a..3b37bc2 100644 --- a/tornado_json/schema.py +++ b/tornado_json/schema.py @@ -3,7 +3,6 @@ from functools import wraps from tornado import gen -from tornado.concurrent import Future from tornado_json.utils import container @@ -62,7 +61,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 gen.is_future(output): output = yield output if output_schema is not None: From d1a6ea1cbc308b7343ee7821a33901310228aeb6 Mon Sep 17 00:00:00 2001 From: hfaran Date: Fri, 21 Nov 2014 15:08:14 -0800 Subject: [PATCH 5/7] tornado 3.x.x does not have tornado.concurrent.is_future --- tornado_json/schema.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tornado_json/schema.py b/tornado_json/schema.py index 3b37bc2..d8a501b 100644 --- a/tornado_json/schema.py +++ b/tornado_json/schema.py @@ -3,6 +3,12 @@ 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 @@ -61,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 gen.is_future(output): + if is_future(output): output = yield output if output_schema is not None: From 652a5a7b088b622adc076a787cc51ad78328dd94 Mon Sep 17 00:00:00 2001 From: hfaran Date: Fri, 21 Nov 2014 15:28:02 -0800 Subject: [PATCH 6/7] Use generative envlist for tox run --- maintenance.md | 6 ++++-- tox.ini | 5 +++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/maintenance.md b/maintenance.md index fdac771..a180aca 100644 --- a/maintenance.md +++ b/maintenance.md @@ -19,5 +19,7 @@ * 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/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= From 078231959a4aa231bce5554f48535145ab7c7c53 Mon Sep 17 00:00:00 2001 From: hfaran Date: Fri, 21 Nov 2014 15:30:22 -0800 Subject: [PATCH 7/7] Add Running Tests section to README --- README.md | 9 +++++++++ README.rst | 11 ++++++++++- maintenance.md | 8 ++++---- 3 files changed, 23 insertions(+), 5 deletions(-) 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 a180aca..64a9a7d 100644 --- a/maintenance.md +++ b/maintenance.md @@ -3,19 +3,19 @@ * 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