1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
|
import mpi4py
import unittest
import warnings
import pathlib
import os
class TestRC(unittest.TestCase):
@staticmethod
def newrc():
rc = type(mpi4py.rc)()
rc(initialize = rc.initialize)
rc(threads = rc.threads)
rc(thread_level = rc.thread_level)
rc(finalize = rc.finalize)
rc(fast_reduce = rc.fast_reduce)
rc(recv_mprobe = rc.recv_mprobe)
rc(irecv_bufsz = rc.irecv_bufsz)
rc(errors = rc.errors)
return rc
def testCallKwArgs(self):
rc = self.newrc()
kwargs = rc.__dict__.copy()
rc(**kwargs)
def testInitKwArgs(self):
rc = self.newrc()
kwargs = rc.__dict__.copy()
rc = type(mpi4py.rc)(**kwargs)
def testBadAttribute(self):
error = lambda: mpi4py.rc(ABCXYZ=123456)
self.assertRaises(TypeError, error)
error = lambda: setattr(mpi4py.rc, 'ABCXYZ', 123456)
self.assertRaises(TypeError, error)
error = lambda: getattr(mpi4py.rc, 'ABCXYZ')
self.assertRaises(AttributeError, error)
def testRepr(self):
repr(mpi4py.rc)
class TestConfig(unittest.TestCase):
def testGetInclude(self):
path = mpi4py.get_include()
self.assertIsInstance(path, str)
self.assertTrue(os.path.isdir(path))
header = os.path.join(path, 'mpi4py', 'mpi4py.h')
self.assertTrue(os.path.isfile(header))
def testGetConfig(self):
conf = mpi4py.get_config()
self.assertIsInstance(conf, dict)
mpicc = conf.get('mpicc')
if mpicc is not None:
self.assertTrue(os.path.exists(mpicc))
class TestProfile(unittest.TestCase):
def testProfile(self):
import struct
import sysconfig
bits = struct.calcsize('P') * 8
triplet = sysconfig.get_config_var('MULTIARCH') or ''
libpath = [
f"{prefix}{suffix}"
for prefix in ("/lib", "/usr/lib")
for suffix in (bits, f"/{triplet}", "")
]
fspath = (
os.fsencode,
os.fsdecode,
pathlib.Path
)
libraries = (
'c', 'libc.so.6',
'm', 'libm.so.6',
'dl', 'libdl.so.2',
)
def mpi4py_profile(*args, **kwargs):
try:
mpi4py.profile(*args, **kwargs)
except ValueError:
pass
if os.name != 'posix':
with warnings.catch_warnings():
warnings.simplefilter('error')
with self.assertRaises(UserWarning):
mpi4py.profile(struct.__file__)
return
with warnings.catch_warnings():
warnings.simplefilter('ignore')
for libname in libraries:
mpi4py_profile(libname, path=libpath)
for fs in fspath:
mpi4py_profile(libname, path=map(fs, libpath))
for path in libpath:
mpi4py_profile(libname, path=path)
for fsp in fspath:
mpi4py_profile(libname, path=fsp(path))
warnings.simplefilter('error')
with self.assertRaises(UserWarning):
mpi4py.profile('hosts', path=["/etc"])
with self.assertRaises(ValueError):
mpi4py.profile('@querty')
with self.assertRaises(ValueError):
mpi4py.profile('@querty', path="/usr/lib")
with self.assertRaises(ValueError):
mpi4py.profile('@querty', path=["/usr/lib"])
with self.assertRaises(ValueError):
mpi4py.profile('@querty')
if __name__ == '__main__':
unittest.main()
|