Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
stack.enter_context(mock.patch('socket.gethostname', mock.Mock(return_value='test')))
mock_timer = stack.enter_context(mock.patch('dtale.app.Timer', mock.Mock()))
tmp = DtaleFlask('dtale', static_url_path='', reaper_on=False)
tmp.run(port='9999')
mock_run.assert_called_once()
assert not tmp.reaper_on
mock_timer.assert_not_called()
with ExitStack() as stack:
mock_run = stack.enter_context(mock.patch('flask.Flask.run', mock.Mock()))
stack.enter_context(mock.patch('socket.gethostname', mock.Mock(return_value='test')))
mock_timer = stack.enter_context(mock.patch('dtale.app.Timer', mock.Mock()))
tmp = DtaleFlask('dtale', static_url_path='')
tmp.run(debug=True, port='9999')
mock_run.assert_called_once()
assert not tmp.reaper_on
mock_timer.assert_not_called()
args, _ = mock_timer.call_args
assert args[0] == REAPER_TIMEOUT
mock_run.assert_called_once()
assert tmp.reaper is not None
timer_instance = mock_timer.return_value
timer_instance.start.assert_called_once()
tmp.clear_reaper()
timer_instance.cancel.assert_called_once()
with ExitStack() as stack:
mock_run = stack.enter_context(mock.patch('flask.Flask.run', mock.Mock()))
stack.enter_context(mock.patch('socket.gethostname', mock.Mock(return_value='test')))
mock_timer = stack.enter_context(mock.patch('dtale.app.Timer', mock.Mock()))
tmp = DtaleFlask('dtale', static_url_path='', reaper_on=False)
tmp.run(port='9999')
mock_run.assert_called_once()
assert not tmp.reaper_on
mock_timer.assert_not_called()
with ExitStack() as stack:
mock_run = stack.enter_context(mock.patch('flask.Flask.run', mock.Mock()))
stack.enter_context(mock.patch('socket.gethostname', mock.Mock(return_value='test')))
mock_timer = stack.enter_context(mock.patch('dtale.app.Timer', mock.Mock()))
tmp = DtaleFlask('dtale', static_url_path='')
tmp.run(debug=True, port='9999')
mock_run.assert_called_once()
assert not tmp.reaper_on
def test_DtaleFlask():
from dtale.app import DtaleFlask, REAPER_TIMEOUT
with ExitStack() as stack:
mock_run = stack.enter_context(mock.patch('flask.Flask.run', mock.Mock()))
stack.enter_context(mock.patch('socket.gethostname', mock.Mock(return_value='test')))
mock_timer = stack.enter_context(mock.patch('dtale.app.Timer'))
tmp = DtaleFlask('dtale', static_url_path='', url='http://test:9999')
tmp.run(port='9999')
assert tmp.reaper_on
assert tmp.shutdown_url == 'http://test:9999/shutdown'
mock_timer.assert_called_once()
args, _ = mock_timer.call_args
assert args[0] == REAPER_TIMEOUT
mock_run.assert_called_once()
assert tmp.reaper is not None
timer_instance = mock_timer.return_value
timer_instance.start.assert_called_once()
tmp.clear_reaper()
timer_instance.cancel.assert_called_once()
with ExitStack() as stack:
def build_app(url, reaper_on=True, hide_shutdown=False, host=None):
"""
Builds :class:`flask:flask.Flask` application encapsulating endpoints for D-Tale's front-end
:return: :class:`flask:flask.Flask` application
:rtype: :class:`dtale.app.DtaleFlask`
"""
app = DtaleFlask('dtale', reaper_on=reaper_on, static_url_path='', url=url)
app.config['SECRET_KEY'] = 'Dtale'
app.config['HIDE_SHUTDOWN'] = hide_shutdown
app.jinja_env.trim_blocks = True
app.jinja_env.lstrip_blocks = True
app.register_blueprint(dtale)
compress = Compress()
compress.init_app(app)
_, version = retrieve_meta_info_and_version('dtale')
template = dict(
info={
'title': 'D-Tale',
'version': version,
'description': 'Web Client for Visualizing Pandas Objects',
def __init__(self, import_name, reaper_on=True, url=None, *args, **kwargs):
"""
Constructor method
:param reaper_on: whether to run auto-reaper subprocess
:type reaper_on: bool
"""
self.reaper_on = reaper_on
self.reaper = None
self.shutdown_url = build_shutdown_url(url)
self.port = None
super(DtaleFlask, self).__init__(import_name, *args, **kwargs)