<commit_before>#!/usr/bin/python -i

from os import getpid

import pytest
pytest.importorskip("multiprocessing")

from circuits import Event, Component


class Hello(Event):
    """Hello Event"""


class App(Component):

    def hello(self):
        return "Hello from {0:d}".format(getpid())


def test():
    app = App()
    waiter = pytest.WaitEvent(app, "ready")
    app.start(process=True, link=True)
    assert waiter.wait()

    x = app.fire(Hello())

    def test(obj, attr):
        return isinstance(obj._value, list)

    assert pytest.wait_for(x, None, test)

    expected_set = set(
        [
            "Hello from {0:d}".format(getpid()),
            "Hello from {0:d}".format(app._process.pid)
        ]
    )

    actual_set = set(x.value)

    assert actual_set == expected_set

    app.stop()<commit_msg>Added unit test for testing a component in process mode linked with another parent system separately<commit_after>#!/usr/bin/python -i

from os import getpid

import pytest
pytest.importorskip("multiprocessing")

from circuits import Component, Event


class Hello(Event):
    """Hello Event"""


class App(Component):

    def hello(self):
        return "Hello from {0:d}".format(getpid())


def test_parent_child():
    app = App()
    waiter = pytest.WaitEvent(app, "ready")
    app.start(process=True, link=True)
    assert waiter.wait()

    x = app.fire(Hello())

    def test(obj, attr):
        return isinstance(obj._value, list)

    assert pytest.wait_for(x, None, test)

    expected_set = set(
        [
            "Hello from {0:d}".format(getpid()),
            "Hello from {0:d}".format(app._process.pid)
        ]
    )

    actual_set = set(x.value)

    assert actual_set == expected_set

    app.stop()


def test_child(manager, watcher):
    app = App()
    app.start(process=True, link=manager)
    assert watcher.wait("ready")

    x = manager.fire(Hello())

    assert pytest.wait_for(x, "result")

    assert x.value == "Hello from {0:d}".format(app._process.pid)

    app.stop()
{'fraction_non_alphanumeric': 0.13694581280788176, 'fraction_numerical': 0.0034482758620689655, 'mean_word_length': 2.9208494208494207, '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': '4707605', 'n_tokens_mistral': 690, 'n_tokens_neox': 661, 'n_words': 160}