<commit_before>import pytest

from circuits.node import Node, Remote
from circuits import Component, Debugger, Event, handler
from circuits.net.sockets import UDPServer
from circuits.net.sockets import Close
from circuits.core.events import Unregister

class Foo(Event):
    """Foo Event"""


class App(Component):
    disconnected = False
    ready = False
    value = False

    def foo(self):
        return "Hello World!"

    def ready(self, component):
        self.ready = True

    def disconnect(self, component):
        self.disconnected = True

    def remote_value_changed(self, value):
        self.value = True


def get_free_port(manager):
    server = UDPServer(0)
    server.register(manager)
    assert pytest.wait_for(manager, "ready")
    host, port = server.host, server.port
    manager.fire(Close())
    assert pytest.wait_for(manager, "disconnected")
    manager.fire(Unregister(server))
    return host, port


def test_return_value():
    a1 = App()
    n1 = Node().register(a1)
    a1.start()

    host, port = get_free_port(a1)

    a2 = App()
    n2 = Node((host, port)).register(a2)
    a2.start(process=True)

    n1.add('bar', host, port)

    e = Event.create('foo')
    e.notify = True
    r = Remote(e, 'bar')
    r.notify = True
    value = a1.fire(r)

    assert pytest.wait_for(a1, "value")

    assert value.value == "Hello World!"

<commit_msg>Tidied up code<commit_after>import pytest

from circuits import Component, Event
from circuits.net.sockets import Close
from circuits.node import Node, Remote
from circuits.net.sockets import UDPServer
from circuits.core.events import Unregister


class Foo(Event):
    """Foo Event"""


class App(Component):
    disconnected = False
    ready = False
    value = False

    def foo(self):
        return "Hello World!"

    def ready(self, component):
        self.ready = True

    def disconnect(self, component):
        self.disconnected = True

    def remote_value_changed(self, value):
        self.value = True


def get_free_port(manager):
    server = UDPServer(0)
    server.register(manager)
    assert pytest.wait_for(manager, "ready")
    host, port = server.host, server.port
    manager.fire(Close())
    assert pytest.wait_for(manager, "disconnected")
    manager.fire(Unregister(server))
    return host, port


def test_return_value():
    a1 = App()
    n1 = Node().register(a1)
    a1.start()

    host, port = get_free_port(a1)
    (App() + Node((host, port))).start(process=True)

    n1.add('bar', host, port)

    e = Event.create('foo')
    e.notify = True
    r = Remote(e, 'bar')
    r.notify = True
    value = a1.fire(r)

    assert pytest.wait_for(a1, "value")

    assert value.value == "Hello World!"
{'fraction_non_alphanumeric': 0.11911764705882352, 'fraction_numerical': 0.008088235294117648, 'mean_word_length': 3.1227272727272726, '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': '2097325', 'n_tokens_mistral': 901, 'n_tokens_neox': 869, 'n_words': 227}