Esempio n. 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)
Esempio n. 2
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) == 7  # 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)
Esempio n. 3
0
def test_collect_classes():
    skip('we did not go the metaclass way')  # Not if we don't use the meta class
    class Foo123(event.HasEvents):
        pass
    class Bar456(event.HasEvents):
        pass
    
    assert Foo123 in event.HasEvents.CLASSES
    assert Bar456 in event.HasEvents.CLASSES
Esempio n. 4
0
def test_apps():

    # if os.getenv('TRAVIS', '') == 'true':
    # skip('This live test is skipped on Travis for now.')
    if not webruntime.has_firefox():
        skip('This live test needs firefox.')

    runner(TesterApp1)
    runner(TesterApp2)
Esempio n. 5
0
def test_apps():
    
    if not webruntime.has_firefox():
        skip('This live test needs firefox.')
    
    runner(ModelA)
    runner(ModelB)
    runner(ModelC)
    runner(ModelD)
    runner(ModelE)
Esempio n. 6
0
 def test_that_all_dict_methods_are_tested(self):
     if sys.version_info[0] == 2:
         skip('On legacy py, the dict methods are different')
     tested = set([x.split('_')[1] for x in dir(self) if x.startswith('test_')])
     needed = set([x for x in dir(dict) if not x.startswith('_')])
     ignore = 'fromkeys'
     needed = needed.difference(ignore.split(' '))
     
     not_tested = needed.difference(tested)
     assert not not_tested
Esempio n. 7
0
def test_apps():
    
    if not webruntime.FirefoxRuntime().is_available():
        skip('This live test needs firefox.')
    
    runner(ModelA)
    runner(ModelB)
    runner(ModelC)
    runner(ModelD)
    runner(ModelE)
Esempio n. 8
0
def test_apps():

    if not webruntime.FirefoxRuntime().is_available():
        skip('This live test needs firefox.')

    runner(ModelA)
    runner(ModelB)
    runner(ModelC)
    runner(ModelD)
    runner(ModelE)
Esempio n. 9
0
def test_collect_classes():
    skip('we did not go the metaclass way'
         )  # Not if we don't use the meta class

    class Foo123(event.HasEvents):
        pass

    class Bar456(event.HasEvents):
        pass

    assert Foo123 in event.HasEvents.CLASSES
    assert Bar456 in event.HasEvents.CLASSES
Esempio n. 10
0
def test_asset_store_collect2():
    try:
        from flexx import ui
    except ImportError:
        skip('no flexx.ui')

    s = AssetStore()
    s.update_modules()
    assert len(s.modules) > 10
    assert 'flexx.ui._widget' 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()
Esempio n. 11
0
def test_asset_store_collect2():
    try:
        from flexx import ui
    except ImportError:
        skip('no flexx.ui')
    
    s = AssetStore()
    s.update_modules()
    assert len(s.modules) > 10
    assert 'flexx.ui._widget' 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()
Esempio n. 12
0
def test_with_numpy():
    
    if np is None:
        skip('Numpy not available')
    
    im = np.random.normal(100, 50, (100, 100, 1)).astype(np.float32)
    with raises(TypeError):  # need uint8
        write_png(im)
    
    im = np.ones((100, 100, 1), np.uint8) * (7*16+7)
    blob = write_png(im)
    assert blob == write_png(im0, shape0)
    
    im = np.random.normal(100, 50, (100, 100)).astype(np.uint8)
    blob = write_png(im)
    
    im_bytes, shape = read_png(blob)
    assert isinstance(im_bytes, (bytearray, bytes))
    im_check = np.frombuffer(im_bytes, 'uint8').reshape(shape)
    assert im_check.shape == im.shape + (3, )
    for i in range(3):
        assert (im_check[:,:,i] == im).all()
Esempio n. 13
0
def test_mutate_array2():
    """
    [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
    [0, 1, 2, 0, 0, 0, 0, 7, 8, 9, 10, 11]
    [0, 1, 2, 3, 4, 5, 0, 0, 8, 9, 0, 0]
    """

    try:
        import numpy as np
    except ImportError:
        skip('No numpy')

    a = np.arange(12)
    print(list(a.flat))

    mutate_array(a, dict(mutation='replace', index=3, objects=np.zeros((4,))))
    print(list(a.flat))

    a = np.arange(12)
    a.shape = 3, 4

    mutate_array(a, dict(mutation='replace', index=(1, 2), objects=np.zeros((2,2))))
    print(list(a.flat))
Esempio n. 14
0
"""
Test that importing flexx subpackages does not pull in any more flexx
submodules than strictly necessary, and not any more 3d party
dependencies than expected.
"""

import os
import sys
import subprocess

from flexx.util.testing import run_tests_if_main, raises, skip

import flexx

if "__pypy__" in sys.builtin_module_names and os.getenv("TRAVIS", "") == "true":
    skip("These import tests are slow on pypy")

# minimum that will be imported when importing flexx
PROJECT_MODULE = flexx
MIN_MODULES = ["flexx"]
PROJECT_NAME = PROJECT_MODULE.__name__

## Generic code


def loaded_modules(import_module, depth=None, all_modules=False):
    """ Import the given module in subprocess and return loaded modules

    Import a certain module in a clean subprocess and return the
    projects modules that are subsequently loaded. The given depth
    indicates the module level (i.e. depth=1 will only yield 'X.app'
Esempio n. 15
0
def test_notrail_firefox():
    if not webruntime.FirefoxRuntime().is_available():
        skip('no firefox')
    notrailtester('firefox-app')
Esempio n. 16
0
def test_notrail_nw():
    if not webruntime.NWRuntime().is_available():
        skip('no nw')
    notrailtester('nw-app')
Esempio n. 17
0
def test_bundle():

    try:
        from flexx import ui
    except ImportError:
        skip('no flexx.ui')

    store = {}
    m1 = app.JSModule('flexx.ui.widgets._button', store)
    m1.add_variable('Button')
    m2 = app.JSModule('flexx.ui.widgets._tree', store)
    m2.add_variable('TreeWidget')
    m3 = store['flexx.ui._widget']  # because its a dep of the above

    # JS bundle
    bundle = app.Bundle('flexx.ui.js')
    assert 'flexx.ui' in repr(bundle)

    bundle.add_module(m1)
    bundle.add_module(m2)
    bundle.add_module(m3)

    # Modules are sorted
    assert bundle.modules == (m3, m1, m2)

    # Deps are agregated
    assert 'flexx.app.js' in bundle.deps
    assert 'flexx.app._component2.js' in bundle.deps
    assert not any('flexx.ui' in dep for dep in bundle.deps)

    # Strings are combined
    code = bundle.to_string()
    assert '$Widget =' in code
    assert '$Button =' in code
    assert '$TreeWidget =' in code

    # CSS bundle
    bundle = app.Bundle('flexx.ui.css')
    bundle.add_module(m1)
    bundle.add_module(m2)
    bundle.add_module(m3)
    #
    code = bundle.to_string()
    assert '.Widget =' not in code
    assert '.flx-Widget {' in code
    assert '.flx-TreeWidget {' in code

    # This works too
    bundle = app.Bundle('-foo.js')
    bundle.add_module(m1)

    # But this does not
    bundle = app.Bundle('foo.js')
    with raises(ValueError):
        bundle.add_module(m1)

    # Assets can be bundled too

    bundle = app.Bundle('flexx.ui.css')
    bundle.add_module(m1)
    bundle.add_module(m2)

    a1 = app.Asset('foo.css', 'foo-xxx')
    a2 = app.Asset('bar.css', 'bar-yyy')
    bundle.add_asset(a1)
    bundle.add_asset(a2)

    assert a1 in bundle.assets
    assert a2 in bundle.assets

    code = bundle.to_string()
    assert 'foo-xxx' in code
    assert 'bar-yyy' in code

    with raises(TypeError):
        bundle.add_asset()
    with raises(TypeError):
        bundle.add_asset(3)
    with raises(TypeError):
        bundle.add_asset(bundle)  # no bundles
Esempio n. 18
0
"""
Test that importing flexx subpackages does not pull in any more flexx
submodules than strictly necessary, and not any more 3d party
dependencies than expected.
"""

import os
import sys
import subprocess

from flexx.util.testing import run_tests_if_main, raises, skip

import flexx

if '__pypy__' in sys.builtin_module_names and os.getenv('TRAVIS', '') == 'true':
    skip('These import tests are slow on pypy')

# minimum that will be imported when importing flexx
PROJECT_MODULE = flexx
MIN_MODULES = ['flexx']
PROJECT_NAME = 'flexx'

## Generic code

def loaded_modules(import_module, depth=None, all_modules=False):
    """ Import the given module in subprocess and return loaded modules

    Import a certain module in a clean subprocess and return the
    projects modules that are subsequently loaded. The given depth
    indicates the module level (i.e. depth=1 will only yield 'X.app'
    but not 'X.app.backends').
Esempio n. 19
0
Test that importing flexx subpackages does not pull in any more flexx
submodules than strictly necessary, and not any more 3d party
dependencies than expected.
"""

import os
import sys
import subprocess

from flexx.util.testing import run_tests_if_main, raises, skip

import flexx

if '__pypy__' in sys.builtin_module_names and os.getenv('TRAVIS',
                                                        '') == 'true':
    skip('These import tests are slow on pypy')

# minimum that will be imported when importing flexx
PROJECT_MODULE = flexx
MIN_MODULES = ['flexx', 'flexx.util', 'flexx._config']
PROJECT_NAME = 'flexx'

## Generic code


def loaded_modules(import_module, depth=None, all_modules=False):
    """ Import the given module in subprocess and return loaded modules

    Import a certain module in a clean subprocess and return the
    projects modules that are subsequently loaded. The given depth
    indicates the module level (i.e. depth=1 will only yield 'X.app'
Esempio n. 20
0
def test_notrail_firefox():
    if not webruntime.FirefoxRuntime().is_available():
        skip('no firefox')
    notrailtester('firefox-app')
Esempio n. 21
0
def test_notrail_nw():
    if not webruntime.NWRuntime().is_available():
        skip('no nw')
    notrailtester('nw-app')