test_npy_pkg_config.py 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. import os
  2. from numpy.distutils.npy_pkg_config import read_config, parse_flags
  3. from numpy.testing import temppath, assert_
  4. simple = """\
  5. [meta]
  6. Name = foo
  7. Description = foo lib
  8. Version = 0.1
  9. [default]
  10. cflags = -I/usr/include
  11. libs = -L/usr/lib
  12. """
  13. simple_d = {'cflags': '-I/usr/include', 'libflags': '-L/usr/lib',
  14. 'version': '0.1', 'name': 'foo'}
  15. simple_variable = """\
  16. [meta]
  17. Name = foo
  18. Description = foo lib
  19. Version = 0.1
  20. [variables]
  21. prefix = /foo/bar
  22. libdir = ${prefix}/lib
  23. includedir = ${prefix}/include
  24. [default]
  25. cflags = -I${includedir}
  26. libs = -L${libdir}
  27. """
  28. simple_variable_d = {'cflags': '-I/foo/bar/include', 'libflags': '-L/foo/bar/lib',
  29. 'version': '0.1', 'name': 'foo'}
  30. class TestLibraryInfo:
  31. def test_simple(self):
  32. with temppath('foo.ini') as path:
  33. with open(path, 'w') as f:
  34. f.write(simple)
  35. pkg = os.path.splitext(path)[0]
  36. out = read_config(pkg)
  37. assert_(out.cflags() == simple_d['cflags'])
  38. assert_(out.libs() == simple_d['libflags'])
  39. assert_(out.name == simple_d['name'])
  40. assert_(out.version == simple_d['version'])
  41. def test_simple_variable(self):
  42. with temppath('foo.ini') as path:
  43. with open(path, 'w') as f:
  44. f.write(simple_variable)
  45. pkg = os.path.splitext(path)[0]
  46. out = read_config(pkg)
  47. assert_(out.cflags() == simple_variable_d['cflags'])
  48. assert_(out.libs() == simple_variable_d['libflags'])
  49. assert_(out.name == simple_variable_d['name'])
  50. assert_(out.version == simple_variable_d['version'])
  51. out.vars['prefix'] = '/Users/david'
  52. assert_(out.cflags() == '-I/Users/david/include')
  53. class TestParseFlags:
  54. def test_simple_cflags(self):
  55. d = parse_flags("-I/usr/include")
  56. assert_(d['include_dirs'] == ['/usr/include'])
  57. d = parse_flags("-I/usr/include -DFOO")
  58. assert_(d['include_dirs'] == ['/usr/include'])
  59. assert_(d['macros'] == ['FOO'])
  60. d = parse_flags("-I /usr/include -DFOO")
  61. assert_(d['include_dirs'] == ['/usr/include'])
  62. assert_(d['macros'] == ['FOO'])
  63. def test_simple_lflags(self):
  64. d = parse_flags("-L/usr/lib -lfoo -L/usr/lib -lbar")
  65. assert_(d['library_dirs'] == ['/usr/lib', '/usr/lib'])
  66. assert_(d['libraries'] == ['foo', 'bar'])
  67. d = parse_flags("-L /usr/lib -lfoo -L/usr/lib -lbar")
  68. assert_(d['library_dirs'] == ['/usr/lib', '/usr/lib'])
  69. assert_(d['libraries'] == ['foo', 'bar'])