Skip to content

Commit

Permalink
Merge pull request #48 from hfaran/develop
Browse files Browse the repository at this point in the history
Tornado 4.0.x compatibility
  • Loading branch information
hfaran committed Nov 22, 2014
2 parents 4a18f33 + 0782319 commit 14e1a8b
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 13 deletions.
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
11 changes: 10 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.. contents::
:depth: 3
:depth: 3.0
..
Tornado-JSON
Expand Down Expand Up @@ -79,6 +79,15 @@ These dependencies can be satisfied by running
- `tornado <http://www.tornadoweb.org/en/stable/>`__
- `jsonschema <https://python-jsonschema.readthedocs.org/en/latest/>`__

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
Expand Down
14 changes: 8 additions & 6 deletions maintenance.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
9 changes: 6 additions & 3 deletions tornado_json/application.py
Original file line number Diff line number Diff line change
@@ -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):
Expand All @@ -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,
Expand Down
7 changes: 7 additions & 0 deletions tornado_json/constants.py
Original file line number Diff line number Diff line change
@@ -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"]
7 changes: 6 additions & 1 deletion tornado_json/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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:
Expand Down
5 changes: 3 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -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=
Expand Down

0 comments on commit 14e1a8b

Please sign in to comment.