Пример #1
0
def test_session_registering_component_classes():
    try:
        from flexx import ui
    except ImportError:
        skip('no flexx.ui')

    store = AssetStore()
    store.update_modules()

    s = Session('', store)
    commands = []
    s._send_command = lambda x: commands.append(x)
    assert not s.present_modules

    s._register_component_class(ui.Button)
    assert len(s.present_modules) == 2
    assert 'flexx.ui._widget' in s.present_modules
    assert 'flexx.ui.widgets._button' in s.present_modules
    assert len(s._present_classes
               ) == 6  # Because a module was loaded that has more widgets
    assert ui.Button in s._present_classes
    assert ui.RadioButton in s._present_classes
    assert ui.CheckBox in s._present_classes
    assert ui.ToggleButton in s._present_classes
    assert ui.BaseButton in s._present_classes
    assert ui.Widget in s._present_classes

    with raises(TypeError):
        s._register_component_class(3)
Пример #2
0
def test_session_registering_model_classes():
    
    from flexx import ui
    
    store = AssetStore()
    store.update_modules()
    
    s = Session('', store)
    commands = []
    s._send_command = lambda x: commands.append(x)
    assert not s.present_modules
    
    s._register_model_class(ui.Button)
    assert len(s.present_modules) == 2
    assert 'flexx.ui._widget' in s.present_modules
    assert 'flexx.ui.widgets._button' in s.present_modules
    assert len(s._present_classes) == 6  # Because a module was loaded that has more widgets
    assert ui.Button in s._present_classes
    assert ui.RadioButton in s._present_classes
    assert ui.CheckBox in s._present_classes
    assert ui.ToggleButton in s._present_classes
    assert ui.BaseButton in s._present_classes
    assert ui.Widget in s._present_classes
    
    with raises(TypeError):
         s._register_model_class(3)
Пример #3
0
def test_session_assets_data():

    store = AssetStore()
    store.add_shared_data('ww', b'wwww')
    s = Session('', store)
    s._send_command = lambda x: None
    assert s.id

    # Add data
    s.add_data('xx', b'xxxx')
    s.add_data('yy', b'yyyy')
    assert len(s.get_data_names()) == 2
    assert 'xx' in s.get_data_names()
    assert 'yy' in s.get_data_names()

    # get_data()
    assert s.get_data('xx') == b'xxxx'
    assert s.get_data('zz') is None
    assert s.get_data('ww') is b'wwww'

    # # Add url data
    # s.add_data('readme', 'https://github.com/flexxui/flexx/blob/master/README.md')
    # #assert 'Flexx is' in s.get_data('readme').decode()
    # assert s.get_data('readme').startswith('https://github')

    # Add data with same name
    with raises(ValueError):
        s.add_data('xx', b'zzzz')

    # Add BS data
    with raises(TypeError):
        s.add_data('dd')  # no data
    with raises(TypeError):
        s.add_data('dd', 4)  # not an asset
    if sys.version_info > (3, ):
        with raises(TypeError):
            s.add_data('dd', 'not bytes')
        with raises(TypeError):
            s.add_data(b'dd', b'yes, bytes')  # name not str
    with raises(TypeError):
        s.add_data(4, b'zzzz')  # name not a str

    # get_data()
    assert s.get_data('xx') is b'xxxx'
    assert s.get_data('ww') is store.get_data('ww')
    assert s.get_data('ww') == b'wwww'
    assert s.get_data('bla') is None
Пример #4
0
def test_session_basics():

    s = Session('xx')
    assert s.app_name == 'xx'
    assert 'xx' in repr(s)
Пример #5
0
def test_session_assets_data():
    
    store = AssetStore()
    store.add_shared_data('ww', b'wwww')
    s = Session('', store)
    s._send_command = lambda x: None
    assert s.id
    
    # Add data
    s.add_data('xx', b'xxxx')
    s.add_data('yy', b'yyyy')
    assert len(s.get_data_names()) == 2
    assert 'xx' in s.get_data_names()
    assert 'yy' in s.get_data_names()
    
    # get_data()
    assert s.get_data('xx') == b'xxxx'
    assert s.get_data('zz') is None
    assert s.get_data('ww') is b'wwww'
    
    # # Add url data
    # s.add_data('readme', 'https://github.com/zoofIO/flexx/blob/master/README.md')
    # #assert 'Flexx is' in s.get_data('readme').decode()
    # assert s.get_data('readme').startswith('https://github')
    
    # Add data with same name
    with raises(ValueError):
        s.add_data('xx', b'zzzz')
    
    # Add BS data
    with raises(TypeError):
        s.add_data('dd')  # no data
    with raises(TypeError):
        s.add_data('dd', 4)  # not an asset
    if sys.version_info > (3, ):
        with raises(TypeError):
            s.add_data('dd', 'not bytes')
        with raises(TypeError):
            s.add_data(b'dd', b'yes, bytes')  # name not str
    with raises(TypeError):
        s.add_data(4, b'zzzz')  # name not a str
    
    # get_data()
    assert s.get_data('xx') is b'xxxx'
    assert s.get_data('ww') is store.get_data('ww')
    assert s.get_data('ww') == b'wwww'
    assert s.get_data('bla') is None