Beispiel #1
0
def test_add_variable():
    import flxtest.foo
    import flxtest.bar
    store = {}
    
    m = JSModule('flxtest.foo', store)
    
    assert not m.variables
    m.add_variable('Foo')
    assert 'Foo' in m.variables
    
    # add_variable is ignored for pyscript mods
    assert not store['flxtest.lib1'].deps
    with capture_log('info') as log:
        store['flxtest.lib1'].add_variable('spam')  
    assert not log
    
    # add_variable warns for other mods
    with capture_log('info') as log:
        store['flxtest.lib2'].add_variable('spam')  
    assert len(log) == 1 and 'undefined variable' in log[0]
    
    
    m = JSModule('flxtest.bar', store)
    
    # Can use stuff from module if its a __pyscript__ modules
    m.add_variable('use_lib1')
    
    # Even if name makes no sense; maybe it has exports that we do not know of
    m.add_variable('use_lib1_wrong')
    
    # But not for regular modules
    with raises(ValueError) as err:
        m.add_variable('use_lib2')
    assert '__pyscript__' in str(err)
    
    
    # Has changed flag
    our_time = time.time(); time.sleep(0.01)
    m = JSModule('flxtest.bar', {})
    assert m.changed_time > our_time
    time.sleep(0.01); our_time = time.time();
    m.get_js()
    assert m.changed_time < our_time
    #
    our_time = time.time(); time.sleep(0.01)
    m.add_variable('use_lib1')
    m.add_variable('AA')
    assert m.changed_time > our_time
    #
    our_time = time.time(); time.sleep(0.01)
    m.add_variable('use_lib1')  # no effect because already known
    assert m.changed_time <= our_time
    #
    m.add_variable('AA')  # no effect bacause is imported name
    assert m.changed_time <= our_time
Beispiel #2
0
def test_subclasses():
    
    import flxtest.foo
    import flxtest.bar
    
    # Using a class CC > BB > AA > object
    store = {}
    JSModule('flxtest.foo', store).add_variable('Foo')
    m = JSModule('flxtest.bar', store)
    #
    assert 'CC' not in m.get_js()
    assert 'BB' not in m.get_js()
    assert 'AA' not in store['flxtest.lib2'].get_js()
    #
    m.add_variable('CC')
    assert 'CC' in m.get_js()
    assert 'BB' in m.get_js()
    assert 'AA' in store['flxtest.lib2'].get_js()
    
    # Using a class Spam > Bar > Foo > Model
    store = {}
    m = JSModule('flxtest.bar', store)
    assert 'flxtest.foo' not in store
    #
    m.add_variable('Spam')
    assert 'flxtest.foo' in store
    assert 'flexx.app.model' in store
    
    # Using Foo in modules that imports it
    store = {}
    m = JSModule('flxtest.bar', store)
    assert 'flxtest.foo' not in store
    #
    m.add_variable('Foo')
    assert 'flxtest.foo' in store
    assert 'flexx.app.model' in store