-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Expand file tree
/
Copy pathtest-configure-python.js
More file actions
78 lines (65 loc) · 2.31 KB
/
test-configure-python.js
File metadata and controls
78 lines (65 loc) · 2.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
'use strict'
const { describe, it } = require('mocha')
const assert = require('assert')
const path = require('path')
const { devDir } = require('./common')
const gyp = require('../lib/node-gyp')
const requireInject = require('require-inject')
const configure = requireInject('../lib/configure', {
'graceful-fs': {
openSync: () => 0,
closeSync: () => {},
existsSync: () => {},
promises: {
stat: async () => ({}),
mkdir: async () => {},
writeFile: async () => {}
}
}
})
const EXPECTED_PYPATH = path.join(__dirname, '..', 'gyp', 'pylib')
const SEPARATOR = process.platform === 'win32' ? ';' : ':'
const SPAWN_RESULT = cb => ({ on: function () { cb() } })
describe('configure-python', function () {
it('configure PYTHONPATH with no existing env', function (done) {
delete process.env.PYTHONPATH
const prog = gyp()
prog.parseArgv([])
prog.spawn = function () {
assert.strictEqual(process.env.PYTHONPATH, EXPECTED_PYPATH)
return SPAWN_RESULT(done)
}
prog.devDir = devDir
configure(prog, [], assert.fail)
})
it('configure PYTHONPATH with existing env of one dir', function (done) {
const existingPath = path.join('a', 'b')
process.env.PYTHONPATH = existingPath
const prog = gyp()
prog.parseArgv([])
prog.spawn = function () {
assert.strictEqual(process.env.PYTHONPATH, [EXPECTED_PYPATH, existingPath].join(SEPARATOR))
const dirs = process.env.PYTHONPATH.split(SEPARATOR)
assert.deepStrictEqual(dirs, [EXPECTED_PYPATH, existingPath])
return SPAWN_RESULT(done)
}
prog.devDir = devDir
configure(prog, [], assert.fail)
})
it('configure PYTHONPATH with existing env of multiple dirs', function (done) {
const pythonDir1 = path.join('a', 'b')
const pythonDir2 = path.join('b', 'c')
const existingPath = [pythonDir1, pythonDir2].join(SEPARATOR)
process.env.PYTHONPATH = existingPath
const prog = gyp()
prog.parseArgv([])
prog.spawn = function () {
assert.strictEqual(process.env.PYTHONPATH, [EXPECTED_PYPATH, existingPath].join(SEPARATOR))
const dirs = process.env.PYTHONPATH.split(SEPARATOR)
assert.deepStrictEqual(dirs, [EXPECTED_PYPATH, pythonDir1, pythonDir2])
return SPAWN_RESULT(done)
}
prog.devDir = devDir
configure(prog, [], assert.fail)
})
})