Пример #1
0
def test_all_used(buttons):
    """Test all cells are used."""

    app = App(rows=2, columns=2)
    for i in range(4):
        app.add(buttons[i])

    check_all_cells_used(app._root)

    app = App(rows=2, columns=2)
    app[0, 0] = buttons[0]
    app[0, 1] = buttons[1]
    app[1, 0] = buttons[2]
    app[1, 1] = buttons[3]

    check_all_cells_used(app._root)

    app.add(buttons[2])

    assert len(app[1, 1]) == 2

    app = App(rows=2, columns=2)
    app[0] = buttons[0]
    app[1, 0] = buttons[2]
    app[1, 1] = buttons[3]

    check_all_cells_used(app._root)

    app.add(buttons[2])
    assert len(app[1, 1]) == 2
Пример #2
0
def test_all_used(buttons):
    """Test all cells are used."""

    app = App(rows=2, columns=2)
    for i in range(4):
        app.add(buttons[i])

    assert list(app._root._used.values()) == 4 * [True]

    app = App(rows=2, columns=2)
    app[0, 0] = buttons[0]
    app[0, 1] = buttons[1]
    app[1, 0] = buttons[2]
    app[1, 1] = buttons[3]

    assert list(app._root._used.values()) == 4 * [True]

    with pytest.raises(NoUnusedCellsError):
        app.add(buttons[2])

    app = App(rows=2, columns=2)
    app[0] = buttons[0]
    app[1, 0] = buttons[2]
    app[1, 1] = buttons[3]

    assert list(app._root._used.values()) == 4 * [True]

    with pytest.raises(NoUnusedCellsError):
        app.add(buttons[2])
Пример #3
0
def main():
    from bowtie import App
    app = App(debug=True)
    app.add_sidebar(sigma)
    app.add(mainplot)
    app.schedule(0.1, walk)
    return app
Пример #4
0
def components(build_reset, monkeypatch):
    """App with all components."""
    controllers, visuals, htmls = create_components()

    app = App(__name__, rows=len(visuals), sidebar=True)
    for controller in controllers:
        # pylint: disable=protected-access
        assert COMPONENT_REGISTRY[controller._uuid] == controller
        app.add_sidebar(controller)

    for vis in visuals:
        # pylint: disable=protected-access
        assert COMPONENT_REGISTRY[vis._uuid] == vis
        app.add(vis)

    for htm in htmls:
        # pylint: disable=protected-access
        assert COMPONENT_REGISTRY[htm._uuid] == htm
        app.add_sidebar(htm)

    assert len(
        COMPONENT_REGISTRY) == len(controllers) + 2 * len(visuals) + len(htmls)

    # pylint: disable=protected-access
    app._build()

    # run second time to make sure nothing weird happens with subsequent builds
    app._build()

    with server_check(app) as server:
        yield server
Пример #5
0
def main():
    from bowtie import App
    app = App(title='Network DownScaler')

    app.add(sine_plot)

    app.add_sidebar(upload)
    app.subscribe(upload_listener, upload.on_upload)

    app.add_sidebar(scale_factor_input)
    app.subscribe(update_scale_factor, scale_factor_input.on_change)

    app.add_sidebar(mark)

    #app.add_sidebar(text)
    #app.subscribe(write, text.on_change)

    app.add_sidebar(run_button)
    app.subscribe(button_listener, run_button.on_click)

    app.add_sidebar(freq_slider)
    app.subscribe(slider_listener, freq_slider.on_change)

    app.add_sidebar(dropdown_src)
    app.add_sidebar(dropdown_dst)

    app.subscribe(dropdown_src_listener, dropdown_src.on_change)
    app.subscribe(dropdown_dst_listener, dropdown_dst.on_change)

    return app
Пример #6
0
def test_components(chrome_driver, build_path):
    """Tests plotly."""

    app = App(rows=len(visuals), directory=build_path)
    for controller in controllers:
        app.add_sidebar(controller)

    for vis in visuals:
        app.add(vis)
    app.build()

    env['PYTHONPATH'] = '{}:{}'.format(os.getcwd(),
                                       os.environ.get('PYTHONPATH', ''))
    server = subprocess.Popen(os.path.join(build_path, 'src/server.py'),
                              env=env)

    time.sleep(5)

    chrome_driver.get('http://localhost:9991')
    chrome_driver.implicitly_wait(5)

    logs = chrome_driver.get_log('browser')
    for log in logs:
        if log['level'] == 'SEVERE':
            raise Exception(log['message'])

    server.kill()
Пример #7
0
def components(build_path, monkeypatch):
    """App with all components."""
    monkeypatch.setattr(App, '_sourcefile',
                        lambda self: 'bowtie.tests.test_components')

    controllers, visuals = create_components()

    app = App(rows=len(visuals))
    for controller in controllers:
        # pylint: disable=protected-access
        assert COMPONENT_REGISTRY[controller._uuid] == controller
        app.add_sidebar(controller)

    for vis in visuals:
        # pylint: disable=protected-access
        assert COMPONENT_REGISTRY[vis._uuid] == vis
        app.add(vis)

    # pylint: disable=protected-access
    app._build()

    env['PYTHONPATH'] = '{}:{}'.format(os.getcwd(),
                                       os.environ.get('PYTHONPATH', ''))
    server = subprocess.Popen(os.path.join(build_path, 'src/server.py'),
                              env=env)

    time.sleep(5)
    yield
    server.kill()
Пример #8
0
def multiple_views(build_path, monkeypatch):
    """Create multiple views app."""
    monkeypatch.setattr(App, '_sourcefile',
                        lambda self: 'bowtie.tests.test_multiple')

    app = App()
    view1 = View()  # pylint: disable=unused-variable
    assert view1._uuid == 2  # pylint: disable=protected-access
    view2 = View()
    view2.add(table)
    app.add_route(view2, 'view2')

    app.add(table)
    app.add_sidebar(ctrl)
    app.add_sidebar(ctrl2)
    app.subscribe(callback, ctrl.on_change)
    app.subscribe(callback, ctrl2.on_click)

    app._build()  # pylint: disable=protected-access

    env['PYTHONPATH'] = '{}:{}'.format(os.getcwd(),
                                       os.environ.get('PYTHONPATH', ''))
    server = subprocess.Popen(os.path.join(build_path, 'src/server.py'),
                              env=env)

    time.sleep(5)
    yield
    server.kill()
Пример #9
0
def test_append_to_partial(buttons):
    """Append button to partial cell."""
    app = App(columns=2)
    app[0] = buttons[0]
    with pytest.raises(KeyError):
        app[0, 0] += buttons[1]
    with pytest.raises(SpanOverlapError):
        app[0, 0] = buttons[1]
Пример #10
0
def construct():
    from bowtie import App
    app = App(debug=True)
    app.add_sidebar(sigma)
    app.add(mainplot)
    app.schedule(0.1, walk)

    app.build()
Пример #11
0
def dummy(build_reset, monkeypatch):
    """Create basic app."""
    app = App(__name__)
    app.add(button)
    app.subscribe(button.on_click)(click)
    app._build()  # pylint: disable=protected-access

    with server_check(app) as server:
        yield server
Пример #12
0
def test_used(buttons):
    """Test cell usage checks."""

    app = App(rows=2, columns=2)
    for i in range(3):
        app.add(buttons[i])

    app[0, 0] = buttons[3]
    app[0:1, 1] = buttons[3]
    app[1, 0:1] = buttons[3]
    app[1, 1] = buttons[3]
Пример #13
0
def main():
    app = App(rows=3, columns=2, sidebar=False, debug=True)
    app.rows[0].auto()
    app[0] = catdd
    app[1] = stars
    app[2, 0] = busy
    app[2, 1] = revdate

    app.subscribe(viz, catdd.on_change)
    app.subscribe(vizplace, stars.on_click)
    return app
Пример #14
0
def test_build(build_path):
    """Tests the build process."""
    reset_uuid()
    ctrl = Nouislider()
    viz = Plotly()

    app = App(directory=build_path)
    app.add_sidebar(ctrl)
    app.add(viz)
    app.subscribe(callback, ctrl.on_change)
    app.build()
Пример #15
0
def dummy(build_path, monkeypatch):
    """Create basic app."""
    monkeypatch.setattr(App, '_sourcefile', lambda self: 'bowtie.tests.test_cache')

    app = App()
    app.add(button)
    app.subscribe(click, button.on_click)
    # pylint: disable=protected-access
    app._build()

    with server_check(build_path) as server:
        yield server
Пример #16
0
def test_build(build_reset, monkeypatch):
    """Tests the build process."""
    reset_uuid()
    ctrl = Nouislider()
    viz = Plotly()

    app = App(__name__, sidebar=True)
    app.add_sidebar(ctrl)
    app.add(viz)
    app.subscribe(ctrl.on_change)(callback)
    # pylint: disable=protected-access
    app._build()
Пример #17
0
def markdown(build_reset, monkeypatch):
    """Create markdown and text widgets."""
    app = App(__name__, sidebar=True)
    app.add(mark)
    app.add_sidebar(side)
    app.add_sidebar(text)
    app.subscribe(text.on_change)(write)
    # pylint: disable=protected-access
    app._build()

    with server_check(app) as server:
        yield server
Пример #18
0
def test_grid_index(buttons):
    """Test grid indexing checks."""

    app = App(rows=2, columns=2)
    with pytest.raises(GridIndexError):
        app[-5] = buttons[0]

    app[-1] = buttons[0]

    with pytest.raises(GridIndexError):
        app[2] = buttons[0]

    app[1] = buttons[0]
Пример #19
0
def test_getitem(buttons):
    """Test grid indexing checks."""

    but = buttons[0]

    app = App(rows=2, columns=2)

    with pytest.raises(GridIndexError):
        app[3] = but

    with pytest.raises(GridIndexError):
        app[1, 2, 3] = but

    with pytest.raises(GridIndexError):
        # pylint: disable=invalid-slice-index
        app['a':3] = but

    with pytest.raises(GridIndexError):
        app['a'] = but

    with pytest.raises(GridIndexError):
        app[3, 'a'] = but

    with pytest.raises(GridIndexError):
        app['a', 3] = but

    with pytest.raises(GridIndexError):
        app[0, 0::2] = but

    with pytest.raises(GridIndexError):
        app[0, 1:-1:-1] = but

    app[1, ] = but
    assert sum(app._root._used.values()) == 2
    app[0, :] = but
    assert sum(app._root._used.values()) == 4

    app = App(rows=2, columns=2)
    app[0:1, 1:2] = but
    assert sum(app._root._used.values()) == 1
    app[1:, 0:] = but
    assert sum(app._root._used.values()) == 3

    app = App(rows=2, columns=2)
    app[-1, :2] = but
    assert sum(app._root._used.values()) == 2

    app = App(rows=1, columns=2)
    app[0, :2] = but
    assert sum(app._root._used.values()) == 2

    app = App(rows=1, columns=2)
    app[0] = but
    assert sum(app._root._used.values()) == 2

    app = App(rows=2, columns=2)
    app[:2] = but
    assert sum(app._root._used.values()) == 4
Пример #20
0
def test_build(build_path, monkeypatch):
    """Tests the build process."""
    monkeypatch.setattr(App, '_sourcefile',
                        lambda self: 'bowtie.tests.test_compile')
    reset_uuid()
    ctrl = Nouislider()
    viz = Plotly()

    app = App()
    app.add_sidebar(ctrl)
    app.add(viz)
    app.subscribe(callback, ctrl.on_change)
    # pylint: disable=protected-access
    app._build()
Пример #21
0
def test_used(buttons):
    """Test cell usage checks."""

    app = App(rows=2, columns=2)
    for i in range(3):
        app.add(buttons[i])

    with pytest.raises(UsedCellsError):
        app[0, 0] = buttons[3]

    with pytest.raises(UsedCellsError):
        app[0:1, 1] = buttons[3]

    with pytest.raises(UsedCellsError):
        app[1, 0:1] = buttons[3]

    app[1, 1] = buttons[3]
Пример #22
0
def multiple_views(build_reset, monkeypatch):
    """Create multiple views app."""
    app = App(__name__, sidebar=True)
    view1 = View()  # pylint: disable=unused-variable
    assert view1._uuid == 2  # pylint: disable=protected-access
    view2 = View()
    view2.add(table)
    app.add_route(view2, 'view2')

    app.add(table)
    app.add_sidebar(ctrl)
    app.add_sidebar(ctrl2)
    app.subscribe(ctrl.on_change)(app.subscribe(ctrl2.on_click)(callback))

    app._build()  # pylint: disable=protected-access

    with server_check(app) as server:
        yield server
Пример #23
0
def plotly(build_path, monkeypatch):
    """Create plotly app."""
    monkeypatch.setattr(App, '_sourcefile', lambda self: 'bowtie.tests.test_plotly')

    app = App()
    app.add(viz)
    app.add_sidebar(ctrl)
    app.add_sidebar(ctrl_range)
    app.add_sidebar(ctrl2)
    app.subscribe(callback, ctrl.on_change)
    app.subscribe(callback, ctrl2.on_click)
    # pylint: disable=protected-access
    app._build()

    env['PYTHONPATH'] = '{}:{}'.format(os.getcwd(), os.environ.get('PYTHONPATH', ''))
    server = subprocess.Popen(os.path.join(build_path, 'src/server.py'), env=env)

    time.sleep(5)
    yield
    server.kill()
Пример #24
0
def test_markdown(chrome_driver, build_path):
    """Test markdown and text widgets."""
    app = App(directory=build_path)
    app.add(mark)
    app.add_sidebar(side)
    app.add_sidebar(text)
    app.subscribe(write, text.on_change)
    app.build()

    env['PYTHONPATH'] = '{}:{}'.format(os.getcwd(),
                                       os.environ.get('PYTHONPATH', ''))
    server = subprocess.Popen(os.path.join(build_path, 'src/server.py'),
                              env=env)

    time.sleep(5)

    chrome_driver.get('http://*****:*****@style='grid-area: 1 / 2 / 2 / 3; position: relative;']")

    assert 'top' in output.text
    assert 'middle' in output.text
    assert 'link' in output.text

    txtctrl.send_keys('apple')
    time.sleep(1)

    assert 'apple' in output.text

    txtctrl.send_keys('banana')
    time.sleep(1)

    assert 'apple' in output.text
    assert 'banana' in output.text

    server.kill()
Пример #25
0
def markdown(build_path, monkeypatch):
    """Create markdown and text widgets."""
    monkeypatch.setattr(App, '_sourcefile',
                        lambda self: 'bowtie.tests.test_editor')

    app = App()
    app.add(mark)
    app.add_sidebar(side)
    app.add_sidebar(text)
    app.subscribe(write, text.on_change)
    # pylint: disable=protected-access
    app._build()

    env['PYTHONPATH'] = '{}:{}'.format(os.getcwd(),
                                       os.environ.get('PYTHONPATH', ''))
    server = subprocess.Popen(os.path.join(build_path, 'src/server.py'),
                              env=env)

    time.sleep(5)
    yield
    server.kill()
Пример #26
0
def test_plotly(chrome_driver, build_path):
    """Tests plotly."""

    app = App(directory=build_path)
    app.add(viz)
    app.add_sidebar(ctrl)
    app.add_sidebar(ctrl2)
    app.subscribe(callback, ctrl.on_change)
    app.subscribe(callback, ctrl2.on_click)
    app.build()

    env['PYTHONPATH'] = '{}:{}'.format(os.getcwd(),
                                       os.environ.get('PYTHONPATH', ''))
    server = subprocess.Popen(os.path.join(build_path, 'src/server.py'),
                              env=env)

    time.sleep(5)

    chrome_driver.get('http://localhost:9991')
    chrome_driver.implicitly_wait(5)

    assert chrome_driver.title == 'Bowtie App'

    button = chrome_driver.find_element_by_class_name('ant-btn')
    button.click()

    points = chrome_driver.find_elements_by_class_name('point')

    logs = chrome_driver.get_log('browser')
    for log in logs:
        if log['level'] == 'SEVERE':
            raise Exception(log['message'])

    assert len(points) == 4

    server.kill()
Пример #27
0
#!/usr/bin/env python
"""Example Bowtie App."""

from bowtie import App
from bowtie.control import Nouislider
from bowtie.visual import Plotly
from bowtie import Pager, cache, command

import numpy as np
from numpy import random as rng
import plotlywrapper as pw

app = App(debug=True, sidebar=True)
pager = Pager()
sigma = Nouislider(start=0., minimum=0.1, maximum=50.)
mainplot = Plotly()

app.add_sidebar(sigma)
app.add(mainplot)


def initialize():
    cache.save('data', [0.] * 100)


@app.subscribe(pager)
def upgraph():
    data = cache.load('data')
    value = float(sigma.get())
    data.pop(0)
    data.append(value * rng.randn() + data[-1])
Пример #28
0
def app():
    """Simple app."""
    return App(rows=2, columns=2)
Пример #29
0
def test_subscribe_error():
    """Subscribe with incorrect argument order."""
    app = App()
    with pytest.raises(IndexError):
        app.subscribe()
Пример #30
0
def test_subscribe_error():
    """Subscribe with incorrect argument order."""
    app = App()
    button = Button()
    with pytest.raises(TypeError):
        app.subscribe(3, button.on_click)