Example #1
0
def test_asset_store_collect():

    from flexx import ui

    s = AssetStore()
    s.update_modules()
    assert len(s.modules) > 10
    assert 'flexx.ui._widget' in s.modules
    assert 'flexx.app.model' in s.modules

    assert '.Widget =' in s.get_asset('flexx.ui._widget.js').to_string()
    assert '.Widget =' in s.get_asset('flexx.ui.js').to_string()
    assert '.Widget =' in s.get_asset('flexx.js').to_string()
    assert '.Widget =' not in s.get_asset('flexx.app.js').to_string()

    assert '.Model =' in s.get_asset('flexx.app.model.js').to_string()
    assert '.Model =' in s.get_asset('flexx.app.js').to_string()
    assert '.Model =' in s.get_asset('flexx.js').to_string()
    assert '.Model =' not in s.get_asset('flexx.ui.js').to_string()
Example #2
0
def test_asset_store_export():

    from flexx import ui

    dir = os.path.join(tempfile.gettempdir(), 'flexx_export')
    if os.path.isdir(dir):
        shutil.rmtree(dir)

    # os.mkdir(dir) -> No, export can create this dir!

    store = AssetStore()
    store.update_modules()

    # Getting an asset marks them as used
    store.get_asset('flexx.ui.js')
    store.get_asset('flexx.app.js')
    store.get_asset('flexx.js')
    store.get_asset('reset.css')

    store.add_shared_data('foo.png', b'x')

    s = SessionAssets(store)
    s.add_data('bar.png', b'x')

    store.export(dir)
    s._export(dir)
    assert len(os.listdir(dir)) == 2
    assert os.path.isfile(os.path.join(dir, '_assets', 'shared', 'reset.css'))
    assert os.path.isfile(os.path.join(dir, '_assets', 'shared',
                                       'flexx.ui.js'))
    assert os.path.isfile(
        os.path.join(dir, '_assets', 'shared', 'flexx.app.js'))
    assert os.path.isfile(os.path.join(dir, '_assets', 'shared', 'flexx.js'))
    assert not os.path.isfile(
        os.path.join(dir, '_assets', 'shared', 'flexx.ui._widget.js'))
    assert os.path.isfile(os.path.join(dir, '_data', 'shared', 'foo.png'))
    assert os.path.isfile(os.path.join(dir, '_data', s.id, 'bar.png'))

    # Will only create a dir that is one level deep
    with raises(ValueError):
        store.export(os.path.join(dir, 'not', 'exist'))