<commit_before>from __future__ import division, print_function, absolute_import

import sys
import math
import numpy as np
from numpy import sqrt, cos, sin, arctan, exp, log, pi, Inf
from numpy.testing import (assert_, TestCase, run_module_suite, dec,
        assert_allclose, assert_array_less, assert_almost_equal)
from scipy.integrate import quad, dblquad, tplquad, nquad
from scipy._lib.six import xrange

try:
    import ctypes
    import ctypes.util
    _ctypes_missing = False
except ImportError:
    _ctypes_missing = True

try:
    import scipy.integrate._test_multivariate as clib_test
    _ctypes_multivariate_fail = False
except:
    _ctypes_multivariate_fail = True


def assert_quad(value_and_err, tabled_value, errTol=1.5e-8):
    value, err = value_and_err
    assert_allclose(value, tabled_value, atol=err, rtol=0)
    if errTol is not None:
        assert_array_less(err, errTol)


class TestCtypesQuad(TestCase):
    @dec.skipif(_ctypes_missing, msg="Ctypes library could not be found")
    def setUp(self):
        if sys.platform == 'win32':
            if sys.version_info < (3, 5):
                file = ctypes.util.find_msvcrt()
            else:
                file = 'api-ms-win-crt-math-l1-1-0.dll'
        elif sys.platform == 'darwin':
            file = 'libm.dylib'
        else:
            file = 'libm.so'
        self.lib = ctypes.CDLL(file)
        restype = ctypes.c_double
        argtypes = (ctypes.c_double,)
        for name in ['sin', 'cos', 'tan']:
            func = getattr(self.lib, name)
            func.restype = restype
            func.argtypes = argtypes

    @dec.skipif(_ctypes_missing, msg="Ctypes library could not be found")
    def test_typical(self):
        assert_quad(quad(self.lib.sin, 0, 5), quad(math.sin, 0, 5)[0])
        assert_quad(quad(self.lib.cos, 0, 5), quad(math.cos, 0, 5)[0])
        assert_quad(quad(self.lib.tan, 0, 1), quad(math.tan, 0, 1)[0])

    <EMAIL>if(_ctypes_missing, msg="Ctypes library could not be found")
    # This doesn't seem to always work.  Need a better way to figure out
    # whether the fast path is called.
    @dec.knownfailureif(True, msg="Unreliable test, see ticket 1684.")
    def test_improvement(self):<commit_msg>TST: fix issue with a ctypes test for integrate on Fedora.  Closes gh-5370<commit_after>from __future__ import division, print_function, absolute_import

import sys
import math
import numpy as np
from numpy import sqrt, cos, sin, arctan, exp, log, pi, Inf
from numpy.testing import (assert_, TestCase, run_module_suite, dec,
        assert_allclose, assert_array_less, assert_almost_equal)
from scipy.integrate import quad, dblquad, tplquad, nquad
from scipy._lib.six import xrange

try:
    import ctypes
    import ctypes.util
    _ctypes_missing = False
except ImportError:
    _ctypes_missing = True

try:
    import scipy.integrate._test_multivariate as clib_test
    _ctypes_multivariate_fail = False
except:
    _ctypes_multivariate_fail = True


def assert_quad(value_and_err, tabled_value, errTol=1.5e-8):
    value, err = value_and_err
    assert_allclose(value, tabled_value, atol=err, rtol=0)
    if errTol is not None:
        assert_array_less(err, errTol)


class TestCtypesQuad(TestCase):
    @dec.skipif(_ctypes_missing, msg="Ctypes library could not be found")
    def setUp(self):
        if sys.platform == 'win32':
            if sys.version_info < (3, 5):
                file = ctypes.util.find_msvcrt()
            else:
                file = 'api-ms-win-crt-math-l1-1-0.dll'
        elif sys.platform == 'darwin':
            file = 'libm.dylib'
        else:
            file = 'libm.so'

        try:
            self.lib = ctypes.CDLL(file)
        except OSError:
            # This test doesn't work on some Linux platforms (Fedora for
            # example) that put an ld script in libm.so - see gh-5370
            self.skipTest("Ctypes can't import libm.so")

        restype = ctypes.c_double
        argtypes = (ctypes.c_double,)
        for name in ['sin', 'cos', 'tan']:
            func = getattr(self.lib, name)
            func.restype = restype
            func.argtypes = argtypes

    @dec.skipif(_ctypes_missing, msg="Ctypes library could not be found")
    def test_typical(self):
        assert_quad(quad(self.lib.sin, 0, 5), quad(math.sin, 0, 5)[0])
        assert_quad(quad(self.lib.cos, 0, 5), quad(math.cos, 0, 5)[0])
        assert_quad(quad(self.lib.tan, 0, 1), quad(math.tan, 0, 1)[0])

    <EMAIL>(_ctypes_missing, msg="Ctypes library could not be found")
    # This doesn't seem to always work.  Need a better way to figure out
    # whether the fast path is called.
    @dec.knownfailureif(True, msg="Unreliable test, see ticket 1684.")
    def test_improvement(self):
{'fraction_non_alphanumeric': 0.10273684210526315, 'fraction_numerical': 0.01431578947368421, 'mean_word_length': 2.8720456397718013, 'pattern_counts': {'":': 0, '<': 7, '<?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': '1772487', 'n_tokens_mistral': 1660, 'n_tokens_neox': 1588, 'n_words': 430}