import platform
import sys
if platform.machine() == 'ppc64le' and hasattr(sys, 'gettotalrefcount'):
    print("WARNING :: skipping test on ppc64le. This is due to some Py_DEBUG issue.")
    sys.exit(0)
import os
import numpy

import numpy.core.multiarray
import numpy.core.multiarray_tests
import numpy.core.numeric
import numpy.core.operand_flag_tests
import numpy.core.struct_ufunc_test
import numpy.core.test_rational
import numpy.core.umath
import numpy.core.umath_tests
import numpy.fft.fftpack_lite
import numpy.linalg.lapack_lite
import numpy.random.mtrand

from numpy.fft import using_mklfft

try:
    print('MKL: %r' % numpy.__mkl_version__)
    have_mkl = True
except AttributeError:
    print('NO MKL')
    have_mkl = False

print('USING MKLFFT: %s' % using_mklfft)

# for compiled code tests
if sys.platform == 'darwin':
    os.environ['LDFLAGS'] = ' '.join((os.getenv('LDFLAGS', ''), " -undefined dynamic_lookup"))
elif sys.platform.startswith('linux'):
    os.environ['LDFLAGS'] = ' '.join((os.getenv('LDFLAGS', ''), '-shared'))
    os.environ['FFLAGS'] = ' '.join((os.getenv('FFLAGS', ''), '-Wl,-shared'))

# We have a test-case failure on 32-bit platforms:
# https://github.com/numpy/numpy/issues/9665
# -fsanitize=signed-integer-overflow gave nothing,
# -fno-strict-aliasing didn't help either.
# TODO :: Investigate this properly.
if sys.maxsize > 2**32:
    result = numpy.test()
    if sys.version_info[0:2] >= (3, 7) and not result.wasSuccessful():
        # I can't find a way to skip individual tests, but we should error if tests other than this one fails
        if len(result.failures) == 1 and 'test_utils.test_clear_and_catch_warnings' in str(result.failures[0][0]):
            print("WARNING :: Ignoring numpy test failure on Python >= 3.7")
            sys.exit(0)
        else:
            sys.exit(not result.wasSuccessful())
    sys.exit(not result.wasSuccessful())
else:
    print("WARNING :: skipping tests on 32-bit")
