test_misc_util.py 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. from os.path import join, sep, dirname
  2. from numpy.distutils.misc_util import (
  3. appendpath, minrelpath, gpaths, get_shared_lib_extension, get_info
  4. )
  5. from numpy.testing import (
  6. assert_, assert_equal
  7. )
  8. ajoin = lambda *paths: join(*((sep,)+paths))
  9. class TestAppendpath:
  10. def test_1(self):
  11. assert_equal(appendpath('prefix', 'name'), join('prefix', 'name'))
  12. assert_equal(appendpath('/prefix', 'name'), ajoin('prefix', 'name'))
  13. assert_equal(appendpath('/prefix', '/name'), ajoin('prefix', 'name'))
  14. assert_equal(appendpath('prefix', '/name'), join('prefix', 'name'))
  15. def test_2(self):
  16. assert_equal(appendpath('prefix/sub', 'name'),
  17. join('prefix', 'sub', 'name'))
  18. assert_equal(appendpath('prefix/sub', 'sup/name'),
  19. join('prefix', 'sub', 'sup', 'name'))
  20. assert_equal(appendpath('/prefix/sub', '/prefix/name'),
  21. ajoin('prefix', 'sub', 'name'))
  22. def test_3(self):
  23. assert_equal(appendpath('/prefix/sub', '/prefix/sup/name'),
  24. ajoin('prefix', 'sub', 'sup', 'name'))
  25. assert_equal(appendpath('/prefix/sub/sub2', '/prefix/sup/sup2/name'),
  26. ajoin('prefix', 'sub', 'sub2', 'sup', 'sup2', 'name'))
  27. assert_equal(appendpath('/prefix/sub/sub2', '/prefix/sub/sup/name'),
  28. ajoin('prefix', 'sub', 'sub2', 'sup', 'name'))
  29. class TestMinrelpath:
  30. def test_1(self):
  31. n = lambda path: path.replace('/', sep)
  32. assert_equal(minrelpath(n('aa/bb')), n('aa/bb'))
  33. assert_equal(minrelpath('..'), '..')
  34. assert_equal(minrelpath(n('aa/..')), '')
  35. assert_equal(minrelpath(n('aa/../bb')), 'bb')
  36. assert_equal(minrelpath(n('aa/bb/..')), 'aa')
  37. assert_equal(minrelpath(n('aa/bb/../..')), '')
  38. assert_equal(minrelpath(n('aa/bb/../cc/../dd')), n('aa/dd'))
  39. assert_equal(minrelpath(n('.././..')), n('../..'))
  40. assert_equal(minrelpath(n('aa/bb/.././../dd')), n('dd'))
  41. class TestGpaths:
  42. def test_gpaths(self):
  43. local_path = minrelpath(join(dirname(__file__), '..'))
  44. ls = gpaths('command/*.py', local_path)
  45. assert_(join(local_path, 'command', 'build_src.py') in ls, repr(ls))
  46. f = gpaths('system_info.py', local_path)
  47. assert_(join(local_path, 'system_info.py') == f[0], repr(f))
  48. class TestSharedExtension:
  49. def test_get_shared_lib_extension(self):
  50. import sys
  51. ext = get_shared_lib_extension(is_python_ext=False)
  52. if sys.platform.startswith('linux'):
  53. assert_equal(ext, '.so')
  54. elif sys.platform.startswith('gnukfreebsd'):
  55. assert_equal(ext, '.so')
  56. elif sys.platform.startswith('darwin'):
  57. assert_equal(ext, '.dylib')
  58. elif sys.platform.startswith('win'):
  59. assert_equal(ext, '.dll')
  60. # just check for no crash
  61. assert_(get_shared_lib_extension(is_python_ext=True))
  62. def test_installed_npymath_ini():
  63. # Regression test for gh-7707. If npymath.ini wasn't installed, then this
  64. # will give an error.
  65. info = get_info('npymath')
  66. assert isinstance(info, dict)
  67. assert "define_macros" in info