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: 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 mock_timer.assert_not_called() with ExitStack() as stack: stack.enter_context( mock.patch("socket.gethostname", mock.Mock(return_value="test"))) tmp = DtaleFlask("dtale", static_url_path="", url="http://test:9999", app_root="/test_route/") assert tmp.url_for("static", "test_path") == "/test_route/test_path" assert (tmp.url_for("static", "test_path", filename="test_file") == "/test_route/test_file")
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: 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 mock_timer.assert_not_called()