Ejemplo n.º 1
0
 def _update_participants(self):
     proxies = app.manager.get_connections(self.__class__.__name__)
     names = [p.app.name.text() for p in proxies]
     text = '<br />%i persons in this chat:<br /><br />' % len(names)
     text += '<br />'.join([name or 'anonymous' for name in sorted(names)])
     self.people.text(text)
     app.call_later(3, self._update_participants)
Ejemplo n.º 2
0
def runner(cls):

    # Run with a fresh server
    server = app.create_server(port=0, new_loop=True)

    t = app.launch(cls, 'firefox-app')
    t.test_init()
    t.test_set_result()
    # Install failsafe. Use a closure so failsafe wont spoil a future test
    isrunning = True

    def stop():
        if isrunning:
            app.stop()

    app.call_later(TIMEOUT1, stop)
    # Enter main loop until we get out
    t0 = time.time()
    app.start()
    print('ran %f seconds' % (time.time() - t0))
    isrunning = False
    # Check result
    if True:  # not (ON_TRAVIS and ON_PYPY):  # has intermittent fails on pypy3
        t.test_check()
    # Shut down
    t.session.close()
Ejemplo n.º 3
0
def runner(cls):
    t = app.launch(cls, 'firefox')
    t.test_init()
    app.call_later(5, app.stop)
    app.run()
    if not (ON_TRAVIS and ON_PYPY):  # has intermittent fails on pypy3
        t.test_check()
Ejemplo n.º 4
0
 def tick(self):
     t = time.time()
     for i, circle in enumerate(self._circles):
         x = math.sin(i*0.2 + t)*0.3 + 0.5
         y = math.cos(i*0.2 + t)*0.3 + 0.5
         circle.pos((x, y))
     app.call_later(0.03, self.tick)
Ejemplo n.º 5
0
 def _update_participants(self):
     proxies = app.manager.get_connections(self.__class__.__name__)
     names = [p.app.name.text() for p in proxies]
     text = '<br />%i persons in this chat:<br /><br />' % len(names)
     text += '<br />'.join([name or 'anonymous' for name in sorted(names)])
     self.people.text(text)
     app.call_later(3, self._update_participants)
Ejemplo n.º 6
0
def runner(cls):
    t = app.launch(cls, 'firefox')  # fails somehow with XUL
    t.test_init()
    app.call_later(TIMEOUT1, app.stop)
    app.run()
    if not (ON_TRAVIS and ON_PYPY):  # has intermittent fails on pypy3
        t.test_check()
    t.session.close()
Ejemplo n.º 7
0
 def _update_participants(self):
     """ Keep track of the number of participants. """
     if not self.session.status:
         return  # and dont't invoke a new call
     proxies = app.manager.get_connections(self.__class__.__name__)
     n = len(proxies)
     del proxies
     self.people.text = '%i persons are painting' % n
     app.call_later(3, self._update_participants)
Ejemplo n.º 8
0
 def _update_participants(self):
     if not self.session.status:
         relay.disconnect('new_dot:' + self.id)
         return  # and dont't invoke a new call
     proxies = app.manager.get_connections(self.__class__.__name__)
     n = len(proxies)
     del proxies
     self.people.text = '%i persons are painting' % n
     app.call_later(3, self._update_participants)
Ejemplo n.º 9
0
 def _update_participants(self):
     """ Keep track of the number of participants. """
     if not self.session.status:
         return  # and dont't invoke a new call
     proxies = app.manager.get_connections(self.__class__.__name__)
     n = len(proxies)
     del proxies
     self.people.text = '%i persons are painting' % n
     app.call_later(3, self._update_participants)
Ejemplo n.º 10
0
 def _update_participants(self):
     if not self.session.status:
         relay.disconnect('new_dot:' + self.id)
         return  # and dont't invoke a new call
     proxies = app.manager.get_connections(self.__class__.__name__)
     n = len(proxies)
     del proxies
     self.people.text = '%i persons are painting' % n
     app.call_later(3, self._update_participants)
Ejemplo n.º 11
0
 def tick(self):
     if not self.session.status:
         return
     import time
     t = time.time()
     for i, circle in enumerate(self._circles):
         x = math.sin(i * 0.2 + t) * 0.3 + 0.5
         y = math.cos(i * 0.2 + t) * 0.3 + 0.5
         circle.pos = x, y
     app.call_later(0.03, self.tick)
Ejemplo n.º 12
0
 def _update_participants(self):
     if not self.session.status:
         return  # and dont't invoke a new call
     sessions = app.manager.get_connections(self.session.app_name)
     names = [p._chatroom_name for p in sessions]  # _chatroom_name is what we set
     del sessions
     text = '<br />%i persons in this chat:<br /><br />' % len(names)
     text += '<br />'.join([name or 'anonymous' for name in sorted(names)])
     self.people.text = text
     app.call_later(3, self._update_participants)
Ejemplo n.º 13
0
 def _update_participants(self):
     if not self.session.status:
         return  # and dont't invoke a new call
     proxies = app.manager.get_connections(self.__class__.__name__)
     names = [p.app.name.text for p in proxies]
     del proxies
     text = '<br />%i persons in this chat:<br /><br />' % len(names)
     text += '<br />'.join([name or 'anonymous' for name in sorted(names)])
     self.people.text = text
     app.call_later(3, self._update_participants)
Ejemplo n.º 14
0
 def _update_participants(self):
     if not self.session.status:
         relay.disconnect('new_message:' + self.id)
         return  # and dont't invoke a new call
     proxies = app.manager.get_connections(self.__class__.__name__)
     names = [p.app.name.text for p in proxies]
     del proxies
     text = '<br />%i persons in this chat:<br /><br />' % len(names)
     text += '<br />'.join([name or 'anonymous' for name in sorted(names)])
     self.people.text = text
     app.call_later(3, self._update_participants)
Ejemplo n.º 15
0
 def _update_participants(self):
     if not self.session.status:
         return  # and dont't invoke a new call
     sessions = app.manager.get_connections(self.session.app_name)
     names = [p._chatroom_name
              for p in sessions]  # _chatroom_name is what we set
     del sessions
     text = '<br />%i persons in this chat:<br /><br />' % len(names)
     text += '<br />'.join([name or 'anonymous' for name in sorted(names)])
     self.people.text = text
     app.call_later(3, self._update_participants)
Ejemplo n.º 16
0
 def main():
     # Create fresh ioloop and make flexx use it
     loop = IOLoop()
     loop.make_current()
     app.create_server()
     # Create model and manipulate prop
     model = MyModel1()
     model.foo = 3
     model.foo = 4
     # Run mainloop for one iterartion
     app.call_later(0, app.stop)
     app.start()
Ejemplo n.º 17
0
 def main():
     # Create fresh ioloop and make flexx use it
     loop = IOLoop()
     loop.make_current()
     app.create_server()
     # Create model and manipulate prop
     model = MyModel1()
     model.foo = 3
     model.foo = 4
     # Run mainloop for one iterartion
     app.call_later(0, app.stop)
     app.start()
Ejemplo n.º 18
0
def test_more_stopping():
    """ Test calling stop multiple times.
    """
    
    # This is why you want to create new IOLoop instances for each test
    
    # Create new ioloop and make Flexx use it
    loop = IOLoop()
    loop.make_current()
    server = app.create_server()
    
    app.stop()  # triggers event to stop
    app.start()
    
    app.stop()  # Extra stop - pending stop event
    
    # Which means the next stop does hardly block
    t0 = time.time()
    app.call_later(0.2, app.stop)
    app.start()
    assert time.time() - t0 < 0.1
    
    
    loop = IOLoop()
    loop.make_current()
    server = app.create_server()
    
    # But stops dont stack
    app.stop()
    app.stop()
    app.stop()
    app.stop()
    
    # Flush all stops ...
    app.stop()
    app.start()
    
    # ... so that we now have an expected loop
    t0 = time.time()
    app.call_later(0.2, app.stop)
    app.start()
    assert time.time() - t0 >= 0.1
Ejemplo n.º 19
0
def test_more_stopping():
    """ Test calling stop multiple times.
    """

    # This is why you want to create new IOLoop instances for each test

    # Create new ioloop and make Flexx use it
    loop = IOLoop()
    loop.make_current()
    server = app.create_server()

    app.stop()  # triggers event to stop
    app.start()

    app.stop()  # Extra stop - pending stop event

    # Which means the next stop does hardly block
    t0 = time.time()
    app.call_later(0.2, app.stop)
    app.start()
    assert time.time() - t0 < 0.1

    loop = IOLoop()
    loop.make_current()
    server = app.create_server()

    # But stops dont stack
    app.stop()
    app.stop()
    app.stop()
    app.stop()

    # Flush all stops ...
    app.stop()
    app.start()

    # ... so that we now have an expected loop
    t0 = time.time()
    app.call_later(0.2, app.stop)
    app.start()
    assert time.time() - t0 >= 0.1
Ejemplo n.º 20
0
def runner(cls):
    
    # Run with a fresh server
    server = app.create_server(port=0, new_loop=True)
    
    t = app.launch(cls, 'firefox-app')
    t.test_init()
    t.test_set_result()
    # Install failsafe. Use a closure so failsafe wont spoil a future test
    isrunning = True
    def stop():
        if isrunning:
            app.stop()
    app.call_later(TIMEOUT1, stop)
    # Enter main loop until we get out
    t0 = time.time()
    app.start()
    print('ran %f seconds' % (time.time()-t0))
    isrunning = False
    # Check result
    if True:  # not (ON_TRAVIS and ON_PYPY):  # has intermittent fails on pypy3
        t.test_check()
    # Shut down
    t.session.close()
Ejemplo n.º 21
0
 def result(self, v=None):
     if v:
         #app.stop()
         print('stopping by ourselves', v)
         app.call_later(TIMEOUT2, app.stop)
     return v
Ejemplo n.º 22
0
 def test_init(self):
     app.call_later(0.2, self._emit_foo)
     app.call_later(0.3, lambda:self.call_js('set_result()'))
Ejemplo n.º 23
0
def multiprocessing_func():
    import flexx
    app.create_server(port=0)  # Explicitly ask for unused port
    app.call_later(0.1, app.stop)
    app.start()
Ejemplo n.º 24
0
def refresh():
    global_cpu_usage._set(psutil.cpu_percent())
    app.call_later(1, refresh)
Ejemplo n.º 25
0
def refresh():
    global_cpu_usage._set(psutil.cpu_percent())
    global_mem_usage._set(psutil.virtual_memory().percent)
    app.call_later(1, refresh)
Ejemplo n.º 26
0
 def result(self, v=None):
     if not this_is_js():
         if v:
             print('stopping by ourselves', v)
             app.call_later(TIMEOUT2, app.stop)
     return v
Ejemplo n.º 27
0
def multiprocessing_func():
    import flexx
    app.create_server(port=0)  # Explicitly ask for unused port
    app.call_later(0.1, app.stop)
    app.start()
Ejemplo n.º 28
0
 def result(self, v=None):
     if not this_is_js():
         if v:
             print('stopping by ourselves', v)
             app.call_later(TIMEOUT2, app.stop)
     return v
Ejemplo n.º 29
0
def refresh():
    global_cpu_usage._set(psutil.cpu_percent())
    app.call_later(1, refresh)
Ejemplo n.º 30
0
def test_restarting():
    """ Test stopping and starting the ioloop.
    """
    res = []
    def add_res(i):
        res.append(i)
    
    def try_start():
        try:
            app.start()
        except RuntimeError:
            res.append('RTE')
        
    # Create new ioloop always
    loop = IOLoop()
    loop.make_current()
    # Make Flexx use it
    server = app.create_server()
    
    app.call_later(0, add_res, 1)
    app.call_later(0, add_res, 2)
    app.call_later(0, app.stop)  # actually, just calling stop() would work as well
    app.start()
    assert server._running == False
    
    app.call_later(0, try_start)  # test that cannot start twice
    app.call_later(0, add_res, 3)
    app.call_later(0, add_res, 4)
    app.call_later(0, app.stop)
    app.start()
    assert server._running == False
    
    app.call_later(0, try_start)  # test that cannot start twice
    app.call_later(0, add_res, 5)
    app.call_later(0, add_res, 6)
    app.call_later(0, app.stop)
    app.start()
    assert server._running == False
    
    assert res == [1, 2, 'RTE', 3, 4, 'RTE', 5, 6]
Ejemplo n.º 31
0
def test_restarting():
    """ Test stopping and starting the ioloop.
    """
    res = []

    def add_res(i):
        res.append(i)

    def try_start():
        try:
            app.start()
        except RuntimeError:
            res.append('RTE')

    # Create new ioloop always
    loop = IOLoop()
    loop.make_current()
    # Make Flexx use it
    server = app.create_server()

    app.call_later(0, add_res, 1)
    app.call_later(0, add_res, 2)
    app.call_later(
        0, app.stop)  # actually, just calling stop() would work as well
    app.start()
    assert server._running == False

    app.call_later(0, try_start)  # test that cannot start twice
    app.call_later(0, add_res, 3)
    app.call_later(0, add_res, 4)
    app.call_later(0, app.stop)
    app.start()
    assert server._running == False

    app.call_later(0, try_start)  # test that cannot start twice
    app.call_later(0, add_res, 5)
    app.call_later(0, add_res, 6)
    app.call_later(0, app.stop)
    app.start()
    assert server._running == False

    assert res == [1, 2, 'RTE', 3, 4, 'RTE', 5, 6]
Ejemplo n.º 32
0
 def refresh(self):
     self.system_info()
     app.call_later(1, self.refresh)