コード例 #1
0
ファイル: test_module.py プロジェクト: zoofIO/flexx
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()
コード例 #2
0
ファイル: test_logging.py プロジェクト: zoofIO/flexx
def test_match():

    # Match based on string
    with capture_log('info', 'foo') as log:
        logger.info('AA foo')
        logger.info('BB bar')  # no foo
        logger.debug('CC foo')  # too high level
        logger.info('DD fXo')  # no foo

    assert len(log) == 1
    assert 'AA' in log[0]

    # Match based on regexp
    with capture_log('info', re.compile('f.o')) as log:
        logger.info('AA foo')
        logger.info('BB bar')  # no foo
        logger.debug('CC foo')  # too high level
        logger.info('DD fXo')

    assert len(log) == 2
    assert 'AA' in log[0]
    assert 'DD' in log[1]

    # No match
    with capture_log('info', '') as log:
        logger.info('AA foo')
        logger.info('BB bar')
        logger.debug('CC foo')  # too high level
        logger.info('DD fXo')

    assert len(log) == 3
コード例 #3
0
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()
コード例 #4
0
def test_match():

    # Match based on string
    with capture_log('info', 'foo') as log:
        logger.info('AA foo')
        logger.info('BB bar')  # no foo
        logger.debug('CC foo')  # too high level
        logger.info('DD fXo')  # no foo

    assert len(log) == 1
    assert 'AA' in log[0]

    # Match based on regexp
    with capture_log('info', re.compile('f.o')) as log:
        logger.info('AA foo')
        logger.info('BB bar')  # no foo
        logger.debug('CC foo')  # too high level
        logger.info('DD fXo')

    assert len(log) == 2
    assert 'AA' in log[0]
    assert 'DD' in log[1]

    # No match
    with capture_log('info', '') as log:
        logger.info('AA foo')
        logger.info('BB bar')
        logger.debug('CC foo')  # too high level
        logger.info('DD fXo')

    assert len(log) == 3
コード例 #5
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
コード例 #6
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]

    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
コード例 #7
0
ファイル: test_handlers.py プロジェクト: Konubinix/flexx
def test_connectors2():
    """ test connectors with sub """
    
    x = MyHasEvents()
    y = MyHasEvents()
    x.sub = [y]
    
    def foo(*events):
        pass
    
    # Warn if no known event
    with capture_log('warning') as log:
        h = x.connect(foo, 'sub*.b')
    assert log
    y._HasEvents__handlers.pop('b')
    
    # Supress warn
    with capture_log('warning') as log:
        h = x.connect(foo, '!sub*.b')
    assert not log
    y._HasEvents__handlers.pop('b')
    
    # Supress warn, with label
    with capture_log('warning') as log:
        h = x.connect(foo, '!sub*.b:meh')
    assert not log
    y._HasEvents__handlers.pop('b')
    
    # Invalid syntax - but fix and warn
    with capture_log('warning') as log:
        h = x.connect(foo, 'sub*.!b:meh')
    assert log
    assert 'Exclamation mark' in log[0]
    y._HasEvents__handlers.pop('b')
    
    # Position of *
    with capture_log('warning') as log:
        h = x.connect(foo, 'sub*.a')
    assert not log
    with capture_log('warning') as log:
        h = x.connect(foo, 'sub.*.a')
    assert log
    with raises(ValueError):
        h = x.connect(foo, 'sub.*a')  # fail

    # No star, no connection, fail!
    with raises(RuntimeError):
        h = x.connect(foo, 'sub.b')
    
    # Mix it
    with capture_log('warning') as log:
        h = x.connect(foo, '!aa*')
    assert not log
    with capture_log('warning') as log:
        h = x.connect(foo, '!aa**')
    assert not log
    with capture_log('warning') as log:
        h = x.connect(foo, '!aa**:meh')  # why not
    assert not log
コード例 #8
0
ファイル: test_handlers.py プロジェクト: silky/flexx
def test_connectors2():
    """ test connectors with sub """
    
    x = MyHasEvents()
    y = MyHasEvents()
    x.sub = [y]
    
    def foo(*events):
        pass
    
    # Warn if no known event
    with capture_log('warning') as log:
        h = x.connect(foo, 'sub*.b')
    assert log
    y._HasEvents__handlers.pop('b')
    
    # Supress warn
    with capture_log('warning') as log:
        h = x.connect(foo, '!sub*.b')
    assert not log
    y._HasEvents__handlers.pop('b')
    
    # Supress warn, with label
    with capture_log('warning') as log:
        h = x.connect(foo, '!sub*.b:meh')
    assert not log
    y._HasEvents__handlers.pop('b')
    
    # Invalid syntax - but fix and warn
    with capture_log('warning') as log:
        h = x.connect(foo, 'sub*.!b:meh')
    assert log
    assert 'Exclamation mark' in log[0]
    y._HasEvents__handlers.pop('b')
    
    # Position of *
    with capture_log('warning') as log:
        h = x.connect(foo, 'sub*.a')
    assert not log
    with capture_log('warning') as log:
        h = x.connect(foo, 'sub.*.a')
    assert log
    with raises(ValueError):
        h = x.connect(foo, 'sub.*a')  # fail

    # No star, no connection, fail!
    with raises(RuntimeError):
        h = x.connect(foo, 'sub.b')
    
    # Mix it
    with capture_log('warning') as log:
        h = x.connect(foo, '!aa*')
    assert not log
    with capture_log('warning') as log:
        h = x.connect(foo, '!aa**')
    assert not log
    with capture_log('warning') as log:
        h = x.connect(foo, '!aa**:meh')  # why not
    assert not log
コード例 #9
0
ファイル: test_module.py プロジェクト: zoofIO/flexx
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
コード例 #10
0
def test_unsupported_platform1():
    """ Unsupported platform, fallback to terminal. """

    o_platform = sys.platform
    o_stdin = sys.stdin
    o_app = dialite._the_app

    sys.platform = 'meh'

    sys.stdin = FakeStdin()

    try:

        app = dialite._select_app()
        assert app.works()
        assert isinstance(app, TerminalApp)
        dialite._the_app = app

        assert dialite.is_supported()

        with capture_log('info') as log:
            dialite.inform()
        assert len(log) == 1 and '[I' in log[0]

        with capture_log('info') as log:
            dialite.warn()  # no problem
        assert len(log) == 1 and '[W' in log[0]

        with capture_log('info') as log:
            dialite.fail()
        assert len(log) == 1 and '[E' in log[0]

        assert dialite.ask_ok()
        assert dialite.ask_retry()
        assert dialite.ask_yesno()

        sys.stdin.answer = 'no'
        assert not dialite.ask_ok()
        assert not dialite.ask_retry()
        assert not dialite.ask_yesno()

    finally:
        sys.platform = o_platform
        sys.stdin = o_stdin
        dialite._the_app = o_app
コード例 #11
0
ファイル: test_funcs.py プロジェクト: zxjlm/flexx
def test_serving_apps_at_output_message():
    """ Test for 'Serving apps at' ready signal.
    """
    with capture_log('info') as log:
        server = app.create_server()
        app.stop()  # triggers event to stop
        app.start()

    assert 'Serving apps at' in ''.join(log)
コード例 #12
0
ファイル: test_dialite.py プロジェクト: Konubinix/flexx
def test_unsupported_platform1():
    """ Unsupported platform, fallback to terminal. """
    
    o_platform = sys.platform
    o_stdin = sys.stdin
    o_app = dialite._the_app
    
    sys.platform = 'meh'
    
    sys.stdin = FakeStdin()
    
    try:
        
        app = dialite._get_app(True)
        assert app.works()
        assert isinstance(app, TerminalApp)
        
        assert dialite.is_supported()
        
        with capture_log('info') as log:
            dialite.inform()
        assert len(log) == 1 and '[I' in log[0]
        
        with capture_log('info') as log:
            dialite.warn()  # no problem
        assert len(log) == 1 and '[W' in log[0]
        
        with capture_log('info') as log:
            dialite.fail()
        assert len(log) == 1 and '[E' in log[0]
        
        assert dialite.ask_ok()
        assert dialite.ask_retry()
        assert dialite.ask_yesno()
        
        sys.stdin.answer = 'no'
        assert not dialite.ask_ok()
        assert not dialite.ask_retry()
        assert not dialite.ask_yesno()
    
    finally:
        sys.platform = o_platform
        sys.stdin = o_stdin
        dialite._the_app = o_app
コード例 #13
0
def test_debug_does_more():
    def caller_func_bla():
        logger.debug('AA foo')
        logger.info('BB bar')

    with capture_log('debug') as log:
        caller_func_bla()

    assert len(log) == 2
    assert 'caller_func_bla' in log[0]
    assert 'caller_func_bla' in log[1]
コード例 #14
0
ファイル: test_logging.py プロジェクト: zoofIO/flexx
def test_debug_does_more():

    def caller_func_bla():
        logger.debug('AA foo')
        logger.info('BB bar')

    with capture_log('debug') as log:
        caller_func_bla()

    assert len(log) == 2
    assert 'caller_func_bla' in log[0]
    assert 'caller_func_bla' in log[1]
コード例 #15
0
ファイル: test_asset.py プロジェクト: zxjlm/flexx
def test_dependency_resolution_3():
    """ Unkown deps are ignored (but warned for) """

    a1 = Thing('a1.js', ['b1.js'])
    b1 = Thing('b1.js', ['bar.js', 'c1.js'])
    c1 = Thing('c1.js', ['d1.js', 'foo.js'])
    d1 = Thing('d1.js', ['e1.js'])
    e1 = Thing('e1.js', [])

    aa = a1, b1, c1, d1, e1
    with capture_log('warning') as logs:
        aa = solve_dependencies(aa, warn_missing=True)
    assert logs and 'missing dependency' in logs[0]
    assert [a.name for a in aa] == ['e1.js', 'd1.js', 'c1.js', 'b1.js', 'a1.js']
コード例 #16
0
ファイル: test_logging.py プロジェクト: zoofIO/flexx
def test_capture():

    with capture_log('info') as log:
        logger.warning('AA')
        logger.info('BB')

    msg1 = log[0]
    msg2 = log[1]

    assert 'flexx' in msg1
    assert 'AA' in msg1
    assert '[W ' in msg1

    assert 'flexx' in msg2
    assert 'BB' in msg2
    assert '[I' in msg2
コード例 #17
0
ファイル: test_logging.py プロジェクト: Python-PyBD/flexx
def test_capture():
    
    with capture_log('info') as log:
        logger.warn('AA')
        logger.info('BB')
    
    msg1 = log[0]
    msg2 = log[1]
    
    assert 'flexx' in msg1
    assert 'AA' in msg1
    assert 'WARNING' in msg1
    
    assert 'flexx' in msg2
    assert 'BB' in msg2
    assert 'INFO' in msg2
コード例 #18
0
def test_capture():

    with capture_log('info') as log:
        logger.warn('AA')
        logger.info('BB')

    msg1 = log[0]
    msg2 = log[1]

    assert 'flexx' in msg1
    assert 'AA' in msg1
    assert '[W ' in msg1

    assert 'flexx' in msg2
    assert 'BB' in msg2
    assert '[I' in msg2
コード例 #19
0
def test_connectors1():
    """ test connectors """

    x = MyComponent()

    def foo(*events):
        pass

    # Can haz any char in label
    with capture_log('warning') as log:
        h = x.reaction(foo, 'a:+asdkjb&^*!')
    type = h.get_connection_info()[0][1][0]
    assert type.startswith('a:')
    assert not log

    # Warn if no known event
    with capture_log('warning') as log:
        h = x.reaction(foo, 'b')
    assert log
    x._Component__handlers.pop('b')

    # Supress warn
    with capture_log('warning') as log:
        h = x.reaction(foo, '!b')
    assert not log
    x._Component__handlers.pop('b')

    # Supress warn, with label
    with capture_log('warning') as log:
        h = x.reaction(foo, '!b:meh')
    assert not log
    x._Component__handlers.pop('b')

    # Supress warn, with label - not like this
    with capture_log('warning') as log:
        h = x.reaction(foo, 'b:meh!')
    assert log
    assert 'does not exist' in log[0]
    x._Component__handlers.pop('b')

    # Invalid syntax - but fix and warn
    with capture_log('warning') as log:
        h = x.reaction(foo, 'b!:meh')
    assert log
    assert 'Exclamation mark' in log[0]
コード例 #20
0
def test_connectors1():
    """ test connectors """

    x = MyComponent()

    def foo(*events):
        pass

    # Can haz any char in label
    with capture_log('warning') as log:
        h = x.reaction(foo, 'a:+asdkjb&^*!')
    type = h.get_connection_info()[0][1][0]
    assert type.startswith('a:')
    assert not log

    # Warn if no known event
    with capture_log('warning') as log:
        h = x.reaction(foo, 'b')
    assert log
    x._Component__handlers.pop('b')

    # Supress warn
    with capture_log('warning') as log:
        h = x.reaction(foo, '!b')
    assert not log
    x._Component__handlers.pop('b')

    # Supress warn, with label
    with capture_log('warning') as log:
        h = x.reaction(foo, '!b:meh')
    assert not log
    x._Component__handlers.pop('b')

    # Supress warn, with label - not like this
    with capture_log('warning') as log:
        h = x.reaction(foo, 'b:meh!')
    assert log
    assert 'does not exist' in log[0]
    x._Component__handlers.pop('b')

    # Invalid syntax - but fix and warn
    with capture_log('warning') as log:
        h = x.reaction(foo, 'b!:meh')
    assert log
    assert 'Exclamation mark' in log[0]