Exemple #1
0
    def test_server_changes_go_to_client(self, ManagedServerLoop) -> None:
        application = Application()
        with ManagedServerLoop(application) as server:
            doc = document.Document()

            client_session = push_session(
                doc,
                session_id='test_server_changes_go_to_client',
                url=url(server),
                io_loop=server.io_loop)
            server_session = server.get_session('/', client_session.id)

            assert len(client_session.document.roots) == 0
            server_root = SomeModelInTestClientServer(foo=42)

            def do_add_server_root():
                server_session.document.add_root(server_root)

            server.io_loop.spawn_callback(server_session.with_document_locked,
                                          do_add_server_root)

            def client_has_root():
                return len(doc.roots) > 0

            client_session._connection._loop_until(client_has_root)
            client_root = next(iter(client_session.document.roots))

            assert client_root.foo == 42
            assert server_root.foo == 42

            # Now try setting title on server side
            def do_set_server_title():
                server_session.document.title = "Server Title"

            server.io_loop.spawn_callback(server_session.with_document_locked,
                                          do_set_server_title)

            def client_title_set():
                return client_session.document.title != document.DEFAULT_TITLE

            client_session._connection._loop_until(client_title_set)

            assert client_session.document.title == "Server Title"

            # Now modify a model within the server document
            def do_set_property_on_server():
                server_root.foo = 57

            server.io_loop.spawn_callback(server_session.with_document_locked,
                                          do_set_property_on_server)

            # there is no great way to block until the server
            # has applied changes, since patches are sent
            # asynchronously. We use internal _loop_until API.
            def client_change_made():
                return client_root.foo == 57

            client_session._connection._loop_until(client_change_made)
            assert client_root.foo == 57

            def do_remove_server_root():
                server_session.document.remove_root(server_root)

            server.io_loop.spawn_callback(server_session.with_document_locked,
                                          do_remove_server_root)

            def client_lacks_root():
                return len(doc.roots) == 0

            client_session._connection._loop_until(client_lacks_root)
            assert len(client_session.document.roots) == 0

            client_session.close()
            client_session._loop_until_closed()
            assert not client_session.connected
Exemple #2
0
 def _sample_doc(self):
     doc = document.Document()
     another = AnotherModelInTestPatchDoc()
     doc.add_root(SomeModelInTestPatchDoc(child=another))
     doc.add_root(SomeModelInTestPatchDoc())
     return doc
Exemple #3
0
def test_unit_spec_changes_do_not_boomerang(monkeypatch,
                                            ManagedServerLoop) -> None:
    application = Application()
    with ManagedServerLoop(application) as server:
        doc = document.Document()
        client_root = UnitsSpecModel()
        doc.add_root(client_root)

        client_session = push_session(
            doc,
            session_id='test_unit_spec_changes_do_not_boomerang',
            url=url(server),
            io_loop=server.io_loop)
        server_session = server.get_session('/', client_session.id)

        assert len(server_session.document.roots) == 1
        server_root = next(iter(server_session.document.roots))

        assert client_root.distance == 42
        assert server_root.angle == 0

        def change_to(new_distance, new_angle):
            got_angry = {}
            got_angry['result'] = None

            # trap any boomerang
            def get_angry(message):
                got_angry['result'] = message

            monkeypatch.setattr(client_session, '_handle_patch', get_angry)

            server_previous_distance = server_root.distance
            server_previous_angle = server_root.angle

            # Now modify the client document
            client_root.distance = new_distance
            client_root.angle = new_angle

            # wait until server side change made ... but we may not have the
            # boomerang yet
            def server_change_made():
                return server_root.distance != server_previous_distance and \
                    server_root.angle != server_previous_angle

            client_session._connection._loop_until(server_change_made)

            # force a round trip to be sure we get the boomerang if we're going to
            client_session.force_roundtrip()

            assert got_angry['result'] is None

        change_to(57, 1)
        change_to({'value': 58}, {'value': 2})
        change_to({'field': 'foo'}, {'field': 'bar'})
        change_to({
            'value': 59,
            'units': 'screen'
        }, {
            'value': 30,
            'units': 'deg'
        })

        client_session.close()
        client_session._loop_until_closed()
        assert not client_session.connected
        server.unlisten()  # clean up so next test can run
Exemple #4
0
 def test_serialization_has_version(self):
     from bokeh import __version__
     d = document.Document()
     json = d.to_json()
     assert json['version'] == __version__
Exemple #5
0
 def test_set_title(self):
     d = document.Document()
     assert d.title == document.DEFAULT_TITLE
     d.title = "Foo"
     assert d.title == "Foo"
Exemple #6
0
 def test_add_roots(self):
     d = document.Document()
     assert not d.roots
     d.add_root(AnotherModelInTestDocument())
     assert len(d.roots) == 1
     assert next(iter(d.roots)).document == d
Exemple #7
0
 def test_empty(self):
     d = document.Document()
     assert not d.roots
Exemple #8
0
 def test_default_template_vars(self):
     d = document.Document()
     assert not d.roots
     assert d.template_variables == {}
Exemple #9
0
 def test_basic(self):
     d = document.Document()
     self.assertEqual(d.autostore, True)
     self.assertEqual(d.autoadd, True)
     self.assertEqual(d.ref, d.context.ref)
Exemple #10
0
from __future__ import print_function

import sys
import requests

import numpy as np

from bokeh.glyphs import *
from bokeh.objects import (Plot, Range1d, LinearAxis, Grid, Glyph,
                           ColumnDataSource, PanTool, WheelZoomTool)
from bokeh import session
from bokeh import document

document = document.Document()
session = session.Session()
session.use_doc('prim_server')
session.load_document(document)

x = np.arange(1, 6)
y = np.arange(5, 0, -1)

source = ColumnDataSource(data=dict(x=x, y=y))

xdr = Range1d(start=0, end=10)
ydr = Range1d(start=0, end=10)


def make_plot(name, glyph):
    glyph_renderer = Glyph(
        data_source=source,
        xdata_range=xdr,