You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

test-configure-python.js 2.5KB

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