test-configure-python.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. }
  15. })
  16. const EXPECTED_PYPATH = path.join(__dirname, '..', 'gyp', 'pylib')
  17. const SEPARATOR = process.platform === 'win32' ? ';' : ':'
  18. const SPAWN_RESULT = { on: function () { } }
  19. require('npmlog').level = 'warn'
  20. test('configure PYTHONPATH with no existing env', function (t) {
  21. t.plan(1)
  22. delete process.env.PYTHONPATH
  23. var prog = gyp()
  24. prog.parseArgv([])
  25. prog.spawn = function () {
  26. t.equal(process.env.PYTHONPATH, EXPECTED_PYPATH)
  27. return SPAWN_RESULT
  28. }
  29. prog.devDir = devDir
  30. configure(prog, [], t.fail)
  31. })
  32. test('configure PYTHONPATH with existing env of one dir', function (t) {
  33. t.plan(2)
  34. var existingPath = path.join('a', 'b')
  35. process.env.PYTHONPATH = existingPath
  36. var prog = gyp()
  37. prog.parseArgv([])
  38. prog.spawn = function () {
  39. t.equal(process.env.PYTHONPATH, [EXPECTED_PYPATH, existingPath].join(SEPARATOR))
  40. var dirs = process.env.PYTHONPATH.split(SEPARATOR)
  41. t.deepEqual(dirs, [EXPECTED_PYPATH, existingPath])
  42. return SPAWN_RESULT
  43. }
  44. prog.devDir = devDir
  45. configure(prog, [], t.fail)
  46. })
  47. test('configure PYTHONPATH with existing env of multiple dirs', function (t) {
  48. t.plan(2)
  49. var pythonDir1 = path.join('a', 'b')
  50. var pythonDir2 = path.join('b', 'c')
  51. var existingPath = [pythonDir1, pythonDir2].join(SEPARATOR)
  52. process.env.PYTHONPATH = existingPath
  53. var prog = gyp()
  54. prog.parseArgv([])
  55. prog.spawn = function () {
  56. t.equal(process.env.PYTHONPATH, [EXPECTED_PYPATH, existingPath].join(SEPARATOR))
  57. var dirs = process.env.PYTHONPATH.split(SEPARATOR)
  58. t.deepEqual(dirs, [EXPECTED_PYPATH, pythonDir1, pythonDir2])
  59. return SPAWN_RESULT
  60. }
  61. prog.devDir = devDir
  62. configure(prog, [], t.fail)
  63. })