def test_decorator_resolve_fail_by_exit_value_str(): context.set_pycompss_context(context.MASTER) fail_by_exit_value = "true" my_deco = PyCOMPSsDecorator(decorator_name="@decorator", fail_by_exit_value=fail_by_exit_value) my_deco.__resolve_fail_by_exit_value__() assert my_deco.kwargs['fail_by_exit_value'] == fail_by_exit_value, \ "Wrong fail_by_exit_value."
def test_decorator_resolve_workingDir(): # noqa context.set_pycompss_context(context.MASTER) working_dir = "/tmp" my_deco = PyCOMPSsDecorator(decorator_name="@decorator", workingDir=working_dir) my_deco.__resolve_working_dir__() assert my_deco.kwargs['working_dir'] == working_dir, \ "Wrong working directory."
def test_decorator_core_element_exception(): context.set_pycompss_context(context.MASTER) my_deco = PyCOMPSsDecorator(decorator_name="@decorator") raised = False try: my_deco.__configure_core_element__(dict()) except MissingImplementedException: # noqa raised = True # expected exception caught assert raised, "Expected MissingImplementedException but not raised."
def test_decorator_process_computing_nodes(): context.set_pycompss_context(context.MASTER) decorator_name = "@decorator" computing_nodes = 1 my_deco = PyCOMPSsDecorator(decorator_name=decorator_name, computingNodes=computing_nodes) my_deco.__process_computing_nodes__(decorator_name=decorator_name) assert my_deco.kwargs['computing_nodes'] == computing_nodes, \ "Wrong computing_nodes value."
def test_decorator_core_element_exception(): context.set_pycompss_context(context.MASTER) my_deco = PyCOMPSsDecorator(decorator_name=DECORATOR_NAME) raised = False try: my_deco.__configure_core_element__(dict(), None) except MissingImplementedException: # noqa raised = True # expected exception caught context.set_pycompss_context(context.OUT_OF_SCOPE) assert raised, "Expected MissingImplementedException but not raised."
def test_decorator_resolve_fail_by_exit_value_str(): context.set_pycompss_context(context.MASTER) fail_by_exit_value = "true" my_deco = PyCOMPSsDecorator( decorator_name=DECORATOR_NAME, fail_by_exit_value=fail_by_exit_value ) my_deco.__resolve_fail_by_exit_value__() context.set_pycompss_context(context.OUT_OF_SCOPE) assert ( my_deco.kwargs["fail_by_exit_value"] == fail_by_exit_value ), "Wrong fail_by_exit_value string."
def test_decorator_resolve_fail_by_exit_value_bool_false(): context.set_pycompss_context(context.MASTER) fail_by_exit_value = False my_deco = PyCOMPSsDecorator( decorator_name=DECORATOR_NAME, fail_by_exit_value=fail_by_exit_value ) my_deco.__resolve_fail_by_exit_value__() context.set_pycompss_context(context.OUT_OF_SCOPE) assert my_deco.kwargs["fail_by_exit_value"] == str( fail_by_exit_value ), "Wrong fail_by_exit_value false."
def test_decorator_resolve_fail_by_exit_value_exception(): context.set_pycompss_context(context.MASTER) fail_by_exit_value = [1, 2] # any object my_deco = PyCOMPSsDecorator(decorator_name="@decorator", fail_by_exit_value=fail_by_exit_value) raised = False try: my_deco.__resolve_fail_by_exit_value__() except Exception: # noqa raised = True assert raised, \ "Expected exception with wrong fail_by_exit_value not raised."
def test_decorator_process_computing_nodes(): context.set_pycompss_context(context.MASTER) decorator_name = DECORATOR_NAME computing_nodes = 1 my_deco = PyCOMPSsDecorator( decorator_name=decorator_name, computingNodes=computing_nodes ) my_deco.__process_computing_nodes__(decorator_name=decorator_name) context.set_pycompss_context(context.OUT_OF_SCOPE) assert ( my_deco.kwargs["computing_nodes"] == computing_nodes ), "Wrong computing_nodes value."
def test_decorator_resolve_workingDir(): # NOSONAR context.set_pycompss_context(context.MASTER) working_dir = tempfile.mkdtemp() my_deco = PyCOMPSsDecorator( decorator_name=DECORATOR_NAME, workingDir=working_dir ) my_deco.__resolve_working_dir__() context.set_pycompss_context(context.OUT_OF_SCOPE) assert ( my_deco.kwargs["working_dir"] == working_dir ), "Wrong working directory." shutil.rmtree(working_dir)
def test_decorator_resolve_fail_by_exit_value_exception(): context.set_pycompss_context(context.MASTER) fail_by_exit_value = [1, 2] # any object my_deco = PyCOMPSsDecorator( decorator_name=DECORATOR_NAME, fail_by_exit_value=fail_by_exit_value ) raised = False try: my_deco.__resolve_fail_by_exit_value__() except Exception: # noqa raised = True context.set_pycompss_context(context.OUT_OF_SCOPE) assert ( raised ), "Expected exception with wrong fail_by_exit_value not raised."
def test_decorator_instantiation(): context.set_pycompss_context(context.MASTER) my_deco = PyCOMPSsDecorator(decorator_name=DECORATOR_NAME) context.set_pycompss_context(context.OUT_OF_SCOPE) assert ( my_deco.decorator_name == DECORATOR_NAME ), "The decorator name must be @decorator."
def __init__(self, *args, **kwargs): # type: (*typing.Any, **typing.Any) -> None """ Store arguments passed to the decorator # self = itself. # args = not used. # kwargs = dictionary with the given Reduce parameters :param args: Arguments :param kwargs: Keyword arguments """ decorator_name = "".join(("@", self.__class__.__name__.lower())) # super(self.__class__, self).__init__(decorator_name, *args, **kwargs) # Instantiate superclass explicitly to support mypy. pd = PyCOMPSsDecorator(decorator_name, *args, **kwargs) self.decorator_name = decorator_name self.args = args self.kwargs = kwargs self.scope = context.in_pycompss() self.core_element = None # type: typing.Any self.core_element_configured = False self.__configure_core_element__ = pd.__configure_core_element__ if self.scope: # Check the arguments check_arguments(MANDATORY_ARGUMENTS, DEPRECATED_ARGUMENTS, SUPPORTED_ARGUMENTS | DEPRECATED_ARGUMENTS, list(kwargs.keys()), decorator_name) # Get the computing nodes self.__process_reduction_params__()
def test_decorator_resolve_workingDir(): # noqa context.set_pycompss_context(context.MASTER) working_dir = tempfile.mkdtemp() kwargs = {"decorator_name": DECORATOR_NAME, "workingDir": working_dir} resolve_working_dir(kwargs) my_deco = PyCOMPSsDecorator(**kwargs) context.set_pycompss_context(context.OUT_OF_SCOPE) assert (my_deco.kwargs["working_dir"] == working_dir ), "Wrong working directory." shutil.rmtree(working_dir)
def __evaluate_fail_by_exit_value__(fail_by_exit_value): context.set_pycompss_context(context.MASTER) kwargs = { "decorator_name": DECORATOR_NAME, "fail_by_exit_value": fail_by_exit_value } resolve_fail_by_exit_value(kwargs) my_deco = PyCOMPSsDecorator(**kwargs) context.set_pycompss_context(context.OUT_OF_SCOPE) assert my_deco.kwargs["fail_by_exit_value"] == str( fail_by_exit_value), "Wrong fail_by_exit_value value (%s != %s)" % ( my_deco.kwargs["fail_by_exit_value"], str(fail_by_exit_value))
def test_decorator_process_computing_nodes(): context.set_pycompss_context(context.MASTER) decorator_name = DECORATOR_NAME computing_nodes = 1 kwargs = { "decorator_name": decorator_name, "computing_odes": computing_nodes } process_computing_nodes(decorator_name, kwargs) my_deco = PyCOMPSsDecorator(**kwargs) context.set_pycompss_context(context.OUT_OF_SCOPE) assert (my_deco.kwargs["computing_nodes"] == str(computing_nodes) ), "Wrong computing_nodes value."
def test_decorator_resolve_fail_by_exit_value_exception(): context.set_pycompss_context(context.MASTER) fail_by_exit_value = [1, 2] # any object kwargs = { "decorator_name": DECORATOR_NAME, "fail_by_exit_value": fail_by_exit_value } raised = False try: resolve_fail_by_exit_value(kwargs) except Exception: # noqa raised = True _ = PyCOMPSsDecorator(**kwargs) context.set_pycompss_context(context.OUT_OF_SCOPE) assert ( raised), "Expected exception with wrong fail_by_exit_value not raised."
def test_decorator_instantiation(): context.set_pycompss_context(context.MASTER) my_deco = PyCOMPSsDecorator(decorator_name="@decorator") assert my_deco.decorator_name == "@decorator", \ "The decorator name must be @decorator."