<commit_before>"""
=========================================
The :mod:`mpi_array.types_test` Module
=========================================

Module defining :mod:`mpi_array.types` unit-tests.
Execute as::

   python -m mpi_array.types_test


Classes
=======

.. autosummary::
   :toctree: generated/
   :template: autosummary/inherits_TestCase_class.rst

   TypesTest - Tests for :func:`mpi_array.types.to_datatype`.


"""
from __future__ import absolute_import

import numpy as _np  # noqa: E402,F401
import mpi4py.MPI as _mpi

from .license import license as _license, copyright as _copyright, version as _version
from . import types as _types
from . import logging as _logging
from . import unittest as _unittest

__author__ = "<NAME>"
__license__ = _license()
__copyright__ = _copyright()
__version__ = _version


class TypesTest(_unittest.TestCase):

    """
    :obj:`unittest.TestCase` for :obj:`mpi_array.types.to_datatype`.
    """

    def setUp(self):
        """
        Set up, assign :obj:`logging.Logger` object.
        """
        self.logger = _logging.get_rank_logger(self.id())

    def test_basic(self):
        """
        Test for :obj:`mpi_array.types.to_datatype` converting basic :obj:`numpy.dtype`
        to MPI data types.
        """

        type_pairs = [
            [_mpi.BOOL, "bool"],
            [_mpi.UNSIGNED_CHAR, "uint8"],
            [_mpi.SIGNED_CHAR, "int8"],
            [_mpi.UNSIGNED_SHORT, "uint16"],
            [_mpi.SIGNED_SHORT, "int16"],
            [_mpi.UNSIGNED_INT, "uint32"],
            [_mpi.SIGNED_INT, "int32"],
            [_mpi.UNSIGNED_LONG_LONG, "uint64"],
            [_mpi.AINT, "int64"],
            [_mpi.FLOAT, "float32"],
            [_mpi.DOUBLE, "float64"],
        ]
        for (mpi_dt, np_dt) in type_pairs:
            mpi_dt_from_np_dt = _types.to_datatype(np_dt)
            self.assertEqual(
                mpi_dt,
                mpi_dt_from_np_dt,
                "str(%s) != str(%s)" % (mpi_dt.Get_name(), mpi_dt_from_np_dt.Get_name())
            )

    def test_contiguous(self):
        """
        Test for :obj:`mpi_array.types.to_datatype` converting contiguous :obj:`numpy.dtype`
        to MPI data types.
        """
        mpi_dt_from_np_dt = _types.to_datatype("float16")
        self.assertEqual(2, mpi_dt_from_np_dt.Get_extent()[1])
        mpi_dt_from_np_dt = _types.to_datatype(("float16", (4,)))
        self.assertEqual(8, mpi_dt_from_np_dt.Get_extent()[1])
        mpi_dt_from_np_dt = _types.to_datatype(("int32", (4,)))
        self.assertEqual(16, mpi_dt_from_np_dt.Get_extent()[1])<commit_msg>Fix for failing unit tests in mpi_array.types_test.<commit_after>"""
=========================================
The :mod:`mpi_array.types_test` Module
=========================================

Module defining :mod:`mpi_array.types` unit-tests.
Execute as::

   python -m mpi_array.types_test


Classes
=======

.. autosummary::
   :toctree: generated/
   :template: autosummary/inherits_TestCase_class.rst

   TypesTest - Tests for :func:`mpi_array.types.to_datatype`.


"""
from __future__ import absolute_import

import numpy as _np  # noqa: E402,F401
import mpi4py.MPI as _mpi

from .license import license as _license, copyright as _copyright, version as _version
from . import types as _types
from . import logging as _logging
from . import unittest as _unittest

__author__ = "<NAME>"
__license__ = _license()
__copyright__ = _copyright()
__version__ = _version


class TypesTest(_unittest.TestCase):

    """
    :obj:`unittest.TestCase` for :obj:`mpi_array.types.to_datatype`.
    """

    def setUp(self):
        """
        Set up, assign :obj:`logging.Logger` object.
        """
        self.logger = _logging.get_rank_logger(self.id())

    def test_basic(self):
        """
        Test for :obj:`mpi_array.types.to_datatype` converting basic :obj:`numpy.dtype`
        to MPI data types.
        """

        type_tuples = [
            ["bool", _mpi.BOOL, ],
            ["uint8", _mpi.UNSIGNED_CHAR, ],
            ["int8", _mpi.SIGNED_CHAR, ],
            ["uint16", _mpi.UNSIGNED_SHORT, ],
            ["int16", _mpi.SIGNED_SHORT, ],
            ["uint32", _mpi.UNSIGNED_INT, ],
            ["int32", _mpi.SIGNED_INT, _mpi.INT],
            ["uint64", _mpi.UNSIGNED_LONG_LONG, _mpi.UNSIGNED_LONG],
            ["int64", _mpi.AINT, _mpi.LONG, _mpi.LONG_INT, _mpi.SIGNED_LONG_LONG, _mpi.SIGNED_LONG],
            ["float32", _mpi.FLOAT, ],
            ["float64", _mpi.DOUBLE, ],
        ]
        for tup in type_tuples:
            np_dt = tup[0]
            mpi_dt_from_np_dt = _types.to_datatype(np_dt)
            matches =\
                _np.any(
                    tuple(
                        mpi_dt_from_np_dt == mpi_dt for mpi_dt in tup[1:]
                    )
                )
            self.assertTrue(
                matches,
                "%s converted to %s is not equal to any of %s"
                %
                (
                    np_dt,
                    mpi_dt_from_np_dt.Get_name(),
                    tuple(mpi_dt.Get_name() for mpi_dt in tup[1:])
                )
            )

    def test_contiguous(self):
        """
        Test for :obj:`mpi_array.types.to_datatype` converting contiguous :obj:`numpy.dtype`
        to MPI data types.
        """
        mpi_dt_from_np_dt = _types.to_datatype("float16")
        self.assertEqual(2, mpi_dt_from_np_dt.Get_extent()[1])
        mpi_dt_from_np_dt = _types.to_datatype(("float16", (4,)))
        self.assertEqual(8, mpi_dt_from_np_dt.Get_extent()[1])
        mpi_dt_from_np_dt = _types.to_datatype(("int32", (4,)))
        self.assertEqual(16, mpi_dt_from_np_dt.Get_extent()[1])
{'fraction_non_alphanumeric': 0.15093015093015094, 'fraction_numerical': 0.014566514566514567, 'mean_word_length': 2.433132530120482, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '7185380', 'n_tokens_mistral': 2018, 'n_tokens_neox': 1860, 'n_words': 356}