test_misc_util.py 3.2 KB

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