def test_session_registering_model_classes(): store = AssetStore() s = SessionAssets(store) s._send_command = lambda x: None store.create_module_assets('flexx.ui.layouts') raises(ValueError, s.register_model_class, 4) # must be a Model class s.register_model_class(ui.Slider) assert len(s._known_classes) == 3 # Slider, Widget, and Model s.register_model_class(ui.Slider) # no duplicates! assert len(s._known_classes) == 3 s.register_model_class(ui.BoxLayout) s.register_model_class(ui.Button) # Get result js = s.get_js_only() assert js.count('.Button = function ') == 1 assert js.count('.Slider = function ') == 1 assert js.count('.Widget = function ') == 1 assert js.count('.BoxLayout = function ') == 1 # Check that module indeed only has layout widgets jsmodule = store.load_asset('flexx-ui-layouts.js').decode() assert jsmodule.count('.BoxLayout = function ') == 1 assert jsmodule.count('.Button = function ') == 0 assert jsmodule.count('.Widget = function ') == 0 # Check that page contains the rest page = s.get_page() assert page.count('.BoxLayout = function ') == 0 assert page.count('.Button = function ') == 1 assert page.count('.Widget = function ') == 1 # Check that a single page export has it all export = s.get_page_for_export([], True) assert export.count('.BoxLayout = function ') == 1 assert export.count('.Button = function ') == 1 assert export.count('.Widget = function ') == 1 # Patch - this func is normally provided by the Session subclass commands = [] s._send_command = lambda x: commands.append(x) # Dynamic s.register_model_class(ui.BoxLayout) assert len(commands) == 0 # already known s.register_model_class(ui.FormLayout) assert len(commands) == 0 # already in module asset # s.register_model_class(ui.Label) assert '.Label = function' in commands[0] # JS assert 'flx-' in commands[1] # CSS
def test_session_registering_model_classes(): store = AssetStore() s = SessionAssets(store) s._send_command = lambda x: None store.create_module_assets('flexx.ui.layouts') raises(ValueError, s.register_model_class, 4) # must be a Model class s.register_model_class(ui.Slider) assert len(s._known_classes) == 3 # Slider, Widget, and Model s.register_model_class(ui.Slider) # no duplicates! assert len(s._known_classes) == 3 s.register_model_class(ui.BoxLayout) s.register_model_class(ui.Button) # Get result js = s.get_js_only() assert js.count('.Button = function ') == 1 assert js.count('.Slider = function ') == 1 assert js.count('.Widget = function ') == 1 assert js.count('.BoxLayout = function ') == 1 # Check that module indeed only has layout widgets jsmodule = store.load_asset('flexx-ui-layouts.js').decode() assert jsmodule.count('.BoxLayout = function ') == 1 assert jsmodule.count('.Button = function ') == 0 assert jsmodule.count('.Widget = function ') == 0 # Check that page contains the rest page = s.get_page() assert page.count('.BoxLayout = function ') == 0 assert page.count('.Button = function ') == 1 assert page.count('.Widget = function ') == 1 # Check that a single page export has it all export = s.get_page_for_export([], True) assert export.count('.BoxLayout = function ') == 1 assert export.count('.Button = function ') == 1 assert export.count('.Widget = function ') == 1 # Patch - this func is normally provided by the Session subclass commands = [] s._send_command = lambda x: commands.append(x) # Dynamic s.register_model_class(ui.BoxLayout) assert len(commands) == 0 # already known s.register_model_class(ui.FormLayout) assert len(commands) == 0 # already in module asset # s.register_model_class(ui.Label) assert '.Label = function' in commands[0] # JS assert 'flx-' in commands[1] # CSS
def test_cache_submodules(): s = AssetStore() s.create_module_assets('flexx.ui.widgets') s.create_module_assets('flexx.ui.widgets._button') s.create_module_assets('flexx.ui') s.get_module_name_for_model_class(ui.Slider) == 'flexx.ui.widgets' s.get_module_name_for_model_class(ui.Button) == 'flexx.ui.widgets._button' s.get_module_name_for_model_class(ui.BoxLayout) == 'flexx.ui'
def test_cache_submodules(): s = AssetStore() s.create_module_assets('flexx.ui.widgets') s.create_module_assets('flexx.ui.widgets._button') s.create_module_assets('flexx.ui') s.get_module_name_for_model_class(ui.Slider) == 'flexx.ui.widgets' s.get_module_name_for_model_class(ui.Button) == 'flexx.ui.widgets._button' s.get_module_name_for_model_class(ui.BoxLayout) == 'flexx.ui'