Skip to content

Update Kernel Gateway test base class to be compatible with Tornado 5.0 #285

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions kernel_gateway/tests/test_gatewayapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import os
from kernel_gateway.gatewayapp import KernelGatewayApp, ioloop
from ..notebook_http.swagger.handlers import SwaggerSpecHandler
from tornado.testing import AsyncHTTPTestCase, LogTrapTestCase
from tornado.testing import AsyncHTTPTestCase, ExpectLog

RESOURCES = os.path.join(os.path.dirname(__file__), 'resources')

Expand Down Expand Up @@ -66,7 +66,7 @@ def test_config_env_vars(self):
self.assertEqual(app.certfile, '/test/fake.crt')
self.assertEqual(app.client_ca, '/test/fake_ca.crt')

class TestGatewayAppBase(AsyncHTTPTestCase, LogTrapTestCase):
class TestGatewayAppBase(AsyncHTTPTestCase, ExpectLog):
"""Base class for integration style tests using HTTP/Websockets against an
instance of the gateway app.

Expand Down
13 changes: 11 additions & 2 deletions kernel_gateway/tests/test_notebook_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import os
import sys
import json
import tornado

from .test_gatewayapp import TestGatewayAppBase, RESOURCES
from ..notebook_http.swagger.handlers import SwaggerSpecHandler
Expand Down Expand Up @@ -381,13 +382,21 @@ def test_concurrent_request_should_not_be_blocked(self):
method='GET',
raise_error=False
)
self.assertTrue(response_long_running.running(), 'Long HTTP Request is not running')
if tornado.version.startswith("4"):
Copy link
Contributor

@rolweber rolweber May 14, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we avoid the version check and instead duck-type the object? Something like:

  if callable(getattr(response_long_running, 'done', Null)):
    # Tornado 5 or higher
  else:
    # Tornado 4

Found the idea on Stack Overflow.
By the way, the check as it is now will yield a wrong result for Tornado 40 to 49 ;-)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @rolweber ! Made the changes you suggested.

self.assertTrue(response_long_running.running(), 'Long HTTP Request is not running')
else:
self.assertFalse(response_long_running.done(), 'Long HTTP Request is not running')

response_short_running = yield self.http_client.fetch(
self.get_url('/sleep/3'),
method='GET',
raise_error=False
)
self.assertTrue(response_long_running.running(), 'Long HTTP Request is not running')
if tornado.version.startswith("4"):
self.assertTrue(response_long_running.running(), 'Long HTTP Request is not running')
else:
self.assertFalse(response_long_running.done(), 'Long HTTP Request is not running')

self.assertEqual(response_short_running.code, 200, 'Short HTTP Request did not return proper status code of 200')

@gen_test
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ jupyter_core>=4.0
jupyter_client>=4.2.0
notebook>=5.0.0
traitlets>=4.2.0
tornado>=4.2.0,<5.0
tornado>=4.2.0
requests>=2.7,<3.0
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
'jupyter_client>=4.2.0',
'notebook>=5.0.0,<6.0',
'traitlets>=4.2.0',
'tornado>=4.2.0,<5.0',
'tornado>=4.2.0',
'requests>=2.7,<3.0'
],
classifiers=[
Expand Down