test-configure-python.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. 'use strict'
  2. const test = require('tap').test
  3. const path = require('path')
  4. const devDir = require('./common').devDir()
  5. const gyp = require('../lib/node-gyp')
  6. const requireInject = require('require-inject')
  7. const configure = requireInject('../lib/configure', {
  8. 'graceful-fs': {
  9. openSync: function () { return 0 },
  10. closeSync: function () { },
  11. writeFile: function (file, data, cb) { cb() },
  12. stat: function (file, cb) { cb(null, {}) },
  13. mkdir: function (dir, options, cb) { cb() },
  14. promises: {
  15. writeFile: function (file, data) { return Promise.resolve(null) }
  16. }
  17. }
  18. })
  19. const EXPECTED_PYPATH = path.join(__dirname, '..', 'gyp', 'pylib')
  20. const SEPARATOR = process.platform === 'win32' ? ';' : ':'
  21. const SPAWN_RESULT = { on: function () { } }
  22. require('npmlog').level = 'warn'
  23. test('configure PYTHONPATH with no existing env', function (t) {
  24. t.plan(1)
  25. delete process.env.PYTHONPATH
  26. var prog = gyp()
  27. prog.parseArgv([])
  28. prog.spawn = function () {
  29. t.equal(process.env.PYTHONPATH, EXPECTED_PYPATH)
  30. return SPAWN_RESULT
  31. }
  32. prog.devDir = devDir
  33. configure(prog, [], t.fail)
  34. })
  35. test('configure PYTHONPATH with existing env of one dir', function (t) {
  36. t.plan(2)
  37. var existingPath = path.join('a', 'b')
  38. process.env.PYTHONPATH = existingPath
  39. var prog = gyp()
  40. prog.parseArgv([])
  41. prog.spawn = function () {
  42. t.equal(process.env.PYTHONPATH, [EXPECTED_PYPATH, existingPath].join(SEPARATOR))
  43. var dirs = process.env.PYTHONPATH.split(SEPARATOR)
  44. t.deepEqual(dirs, [EXPECTED_PYPATH, existingPath])
  45. return SPAWN_RESULT
  46. }
  47. prog.devDir = devDir
  48. configure(prog, [], t.fail)
  49. })
  50. test('configure PYTHONPATH with existing env of multiple dirs', function (t) {
  51. t.plan(2)
  52. var pythonDir1 = path.join('a', 'b')
  53. var pythonDir2 = path.join('b', 'c')
  54. var existingPath = [pythonDir1, pythonDir2].join(SEPARATOR)
  55. process.env.PYTHONPATH = existingPath
  56. var prog = gyp()
  57. prog.parseArgv([])
  58. prog.spawn = function () {
  59. t.equal(process.env.PYTHONPATH, [EXPECTED_PYPATH, existingPath].join(SEPARATOR))
  60. var dirs = process.env.PYTHONPATH.split(SEPARATOR)
  61. t.deepEqual(dirs, [EXPECTED_PYPATH, pythonDir1, pythonDir2])
  62. return SPAWN_RESULT
  63. }
  64. prog.devDir = devDir
  65. configure(prog, [], t.fail)
  66. })