# Module:   test_workers
# Date:     7th October 2008
# Author:   James Mills, prologic at shortcircuit dot net dot au

"""Workers Tests"""

import pytest

from circuits import Task, Worker

def f():
    x = 0
    i = 0
    while i < 1000000:
        x += 1
        i += 1
    return x

def test():
    w = Worker()

    x = w.fire(Task(f))

    assert pytest.wait_for(x, "result")

    assert x.result
    assert x.value == 1000000

    w.stop()

@@ -184,16 +184,401 @@
 Worker%0A%0A
+%0A@pytest.fixture(scope=%22module%22)%0Adef worker(request):%0A    worker = Worker()%0A%0A    def finalizer():%0A        worker.stop()%0A%0A    request.addfinalizer(finalizer)%0A%0A    if request.config.option.verbose:%0A        from circuits import Debugger%0A        Debugger().register(worker)%0A%0A    waiter = pytest.WaitEvent(worker, %22started%22)%0A    worker.start()%0A    assert waiter.wait()%0A%0A    return worker%0A%0A%0A
 def f():
@@ -665,16 +665,17 @@
 turn x%0A%0A
+%0A
 def test
@@ -679,28 +679,16 @@
 est(
-):%0A    w = W
+w
 orker
-()%0A
+):
 %0A   
@@ -693,16 +693,21 @@
    x = w
+orker
 .fire(Ta
@@ -809,18 +809,4 @@
 000%0A
-%0A    w.stop()%0A

Rewrite test_workers using pytest fixtures