<commit_before># -*- coding: utf-8 -*-
"""
Integration tests for the multiprocess invoker.
"""
# Future
from __future__ import absolute_import, division, print_function, \
    unicode_literals, with_statement

# Third Party
import nose
from mock import Mock

# First Party
from metaopt.core.arg.util.creator import ArgsCreator
from metaopt.core.returnspec.returnspec import ReturnSpec
from metaopt.core.returnspec.util.wrapper import ReturnValuesWrapper
from metaopt.concurrent.invoker.multiprocess import MultiProcessInvoker
from metaopt.optimizer.singleinvoke import SingleInvokeOptimizer
from metaopt.objective.integer.failing.f import f as f_failing
from metaopt.objective.integer.fast.explicit.f import f as f_working


f_working = f_working
f_failing = f_failing


class TestMultiProcessInvoker(object):
    """
    Integration tests for the multiprocess invoker.
    """

    def __init__(self):
        self._invoker = None

    def setup(self):
        resources = 2 # 1  # Use only one CPU for reproducible results.
        self._invoker = MultiProcessInvoker(resources=resources)

    def teardown(self):
        self._invoker.stop()

    def test_instanciation(self):
        return  # TODO
        self._invoker = MultiProcessInvoker()
        self._invoker.f = f_working
        caller = Mock()
        fargs = {'a': 0}
        self._invoker.invoke(caller=caller, fargs=fargs)
        self._invoker.wait()

    def test_invoke_calls_on_result(self):
        caller = Mock()
        caller.on_result = Mock()
        caller.on_error = Mock()

        self._invoker.f = f_working
        self._invoker.param_spec = f_working.param_spec
        self._invoker.return_spec = ReturnSpec(f_working)

        args = ArgsCreator(f_working.param_spec).args()<commit_msg>fix and extend mpi test<commit_after># -*- coding: utf-8 -*-
"""
Integration tests for the multiprocess invoker.
"""
# Future
from __future__ import absolute_import, division, print_function, \
    unicode_literals, with_statement

# Third Party
import nose
from mock import Mock

# First Party
from metaopt.core.arg.util.creator import ArgsCreator
from metaopt.core.returnspec.returnspec import ReturnSpec
from metaopt.core.returnspec.util.wrapper import ReturnValuesWrapper
from metaopt.concurrent.invoker.multiprocess import MultiProcessInvoker
from metaopt.optimizer.singleinvoke import SingleInvokeOptimizer
from metaopt.objective.integer.failing.f import f as f_failing
from metaopt.objective.integer.fast.explicit.f import f as f_working


f_working = f_working
f_failing = f_failing


class TestMultiProcessInvoker(object):
    """
    Integration tests for the multiprocess invoker.
    """

    def __init__(self):
        self._invoker = None

    def setup(self):
        resources = 1  # Use only one CPU for reproducible results.
        self._invoker = MultiProcessInvoker(resources=resources)

    def teardown(self):
        self._invoker.stop()

    def test_instanciation(self):
        return  # really do nothing here, setup and teardown do everything.

    def test_single_call(self):
        self._invoker.f = f_working
        caller = Mock()
        fargs = {'a': 0}
        self._invoker.invoke(caller=caller, fargs=fargs)
        self._invoker.wait()

    def test_invoke_calls_on_result(self):
        caller = Mock()
        caller.on_result = Mock()
        caller.on_error = Mock()

        self._invoker.f = f_working
        self._invoker.param_spec = f_working.param_spec
        self._invoker.return_spec = ReturnSpec(f_working)

        args = ArgsCreator(f_working.param_spec).args()
{'fraction_non_alphanumeric': 0.08458542014468559, 'fraction_numerical': 0.0019476905954368391, 'mean_word_length': 3.411042944785276, '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': '7582992', 'n_tokens_mistral': 1093, 'n_tokens_neox': 1074, 'n_words': 260}