def test_globals(): import flxtest.globals0 import flxtest.globals1 import flxtest.globals2 store = {} m0 = JSModule('flxtest.globals0', store) m1 = JSModule('flxtest.globals1', store) m2 = JSModule('flxtest.globals2', store) with capture_log('info') as log: m0.add_variable('main') assert len(log) == 1 and 'undefined variable' in log[0] with capture_log('info') as log: m1.add_variable('main') assert not log with capture_log('info') as log: m2.add_variable('main') assert not log # m0 has local definitions, but no global assert '\nvar console' not in m0.get_js() assert ' var console' in m0.get_js() # m1 has global definition but no local assert '\nvar console' in m1.get_js() assert ' var console' not in m1.get_js() # m2 has neither assert 'var console' not in m2.get_js()
def test_globals(): import flxtest.globals0 import flxtest.globals1 import flxtest.globals2 store = {} m0 = JSModule('flxtest.globals0', store) m1 = JSModule('flxtest.globals1', store) m2 = JSModule('flxtest.globals2', store) with capture_log('info') as log: m0.add_variable('main') assert len(log) == 1 and 'undefined variable' in log[0] with capture_log('info') as log: m1.add_variable('main') assert not log with capture_log('info') as log: m2.add_variable('main') assert not log # m0 has local definitions, but no global assert '\nvar console' not in m0.get_js() assert ' var console' in m0.get_js() # m1 has global definition but no local assert '\nvar console' in m1.get_js() assert ' var console' not in m1.get_js() # m2 has neither assert 'var console' not in m2.get_js()
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
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] with capture_log('info') as log: store['flxtest.lib2'].add_variable('spam', is_global=True) assert not log m = JSModule('flxtest.bar', store) # Can use stuff from module if its a __pyscript__ modules m.add_variable('use_lib1') # The module code is smart enough that lib1 does not contain sinasappel with raises(RuntimeError): m.add_variable('use_lib1_wrong') # Also for dotted names m.add_variable('use_lib2') # Has changed flag our_time = time.time() time.sleep(0.01) m = JSModule('flxtest.bar', {}) time.sleep(0.01) our_time = time.time() m.get_js() # our_time = time.time() time.sleep(0.01) m.add_variable('use_lib1') m.add_variable('AA') # our_time = time.time() time.sleep(0.01) m.add_variable('use_lib1') # no effect because already known # m.add_variable('AA') # no effect bacause is imported name
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 pscript 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] with capture_log('info') as log: store['flxtest.lib2'].add_variable('spam', is_global=True) assert not log m = JSModule('flxtest.bar', store) # Can use stuff from module if its a __pscript__ modules m.add_variable('use_lib1') # The module code is smart enough that lib1 does not contain sinasappel with raises(RuntimeError): m.add_variable('use_lib1_wrong') # Also for dotted names m.add_variable('use_lib2') # Has changed flag our_time = time.time(); time.sleep(0.01) m = JSModule('flxtest.bar', {}) time.sleep(0.01); our_time = time.time(); m.get_js() # our_time = time.time(); time.sleep(0.01) m.add_variable('use_lib1') m.add_variable('AA') # our_time = time.time(); time.sleep(0.01) m.add_variable('use_lib1') # no effect because already known # m.add_variable('AA') # no effect bacause is imported name
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
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 > Component store = {} m = JSModule('flxtest.bar', store) assert 'flxtest.foo' not in store # m.add_variable('Spam') assert 'flxtest.foo' in store assert 'flexx.app._component2' 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._component2' in store