<commit_before>""" Test a live app connection.
"""

import os
import time
import sys

from flexx import app, event, webruntime

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


ON_TRAVIS = os.getenv('TRAVIS', '') == 'true'
ON_PYPY = '__pypy__' in sys.builtin_module_names

TIMEOUT1 = 10.0 if ON_TRAVIS else 3.0
TIMEOUT2 = 1.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()


class ModelA(app.Model):
    
    @event.prop
    def foo1(self, v=0):
        return float(v+1)
    
    @event.prop
    def foo2(self, v=0):
        return float(v+1)

    @event.prop
    def result(self, v=None):
        if v:
            #app.stop()
            print('stopping by ourselves', v)
            app.call_later(TIMEOUT2, app.stop)
        return v
    
    def test_init(self):
        
        assert self.foo1 == 1
        assert self.bar1 is None  # not yet initialized<commit_msg>Maybe should not close session on Travis? did not do this earlier<commit_after>""" Test a live app connection.
"""

import os
import time
import sys

from flexx import app, event, webruntime

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


ON_TRAVIS = os.getenv('TRAVIS', '') == 'true'
ON_PYPY = '__pypy__' in sys.builtin_module_names

TIMEOUT1 = 10.0 if ON_TRAVIS else 3.0
TIMEOUT2 = 1.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()
    if not ON_TRAVIS:
        t.session.close()


class ModelA(app.Model):
    
    @event.prop
    def foo1(self, v=0):
        return float(v+1)
    
    @event.prop
    def foo2(self, v=0):
        return float(v+1)

    @event.prop
    def result(self, v=None):
        if v:
            #app.stop()
            print('stopping by ourselves', v)
            app.call_later(TIMEOUT2, app.stop)
        return v
    
    def test_init(self):
        
        assert self.foo1 == 1
        assert self.bar1 is None  # not yet initialized
{'fraction_non_alphanumeric': 0.10956521739130434, 'fraction_numerical': 0.018260869565217393, 'mean_word_length': 2.4394618834080717, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4094040', 'n_tokens_mistral': 836, 'n_tokens_neox': 818, 'n_words': 223}