test-configure-python.js 1.9 KB

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