<commit_before># Module:   test_timers
# Date:     10th February 2010
# Author:   <NAME>, prologic at shortcircuit dot net dot au

"""Timers Tests"""

from time import sleep

from circuits import Event, Component, Timer

class Test(Event):
    """Test Event"""

class App(Component):

    flag = False

    def timer(self):
        self.flag = True

app = App()
app.start()

def test_timer():
    timer = Timer(0.1, Test(), "timer")
    timer.register(app)
    sleep(0.1)
    while app: pass
    assert app.flag

def test_persistentTimer():
    timer = Timer(0.1, Test(), "timer", persist=True)
    timer.register(app)

    for i in xrange(2):
        sleep(0.1)
        while app: pass
        assert app.flag
        app.flag = False

    timer.unregister()<commit_msg>tests.core.test_timers: Use a sleep of 0.01s longer than what we're testing for<commit_after># Module:   test_timers
# Date:     10th February 2010
# Author:   <NAME>, prologic at shortcircuit dot net dot au

"""Timers Tests"""

from time import sleep

from circuits import Event, Component, Timer

class Test(Event):
    """Test Event"""

class App(Component):

    flag = False

    def timer(self):
        self.flag = True

app = App()
app.start()

def test_timer():
    timer = Timer(0.1, Test(), "timer")
    timer.register(app)
    sleep(0.11)
    assert app.flag

def test_persistentTimer():
    timer = Timer(0.1, Test(), "timer", persist=True)
    timer.register(app)

    for i in xrange(2):
        sleep(0.11)
        assert app.flag
        app.flag = False

    timer.unregister()
{'fraction_non_alphanumeric': 0.12452107279693486, 'fraction_numerical': 0.02234993614303959, 'mean_word_length': 2.869135802469136, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '3797081', 'n_tokens_mistral': 537, 'n_tokens_neox': 501, 'n_words': 158}