-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use push on PYTHONPATH and add tests
Using push instead of the original unshift makes the logic a little cleaner to read here. PR-URL: #990 Reviewed-By: Ben Noordhuis <[email protected]>
- Loading branch information
1 parent
b182a19
commit ddac348
Showing
2 changed files
with
77 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
'use strict' | ||
|
||
var test = require('tape') | ||
var path = require('path') | ||
var gyp = require('../lib/node-gyp') | ||
var requireInject = require('require-inject') | ||
var configure = requireInject('../lib/configure', { | ||
'graceful-fs': { | ||
'writeFile': function (file, data, cb) { cb() }, | ||
'stat': function (file, cb) { cb(null, {}) } | ||
} | ||
}) | ||
|
||
var EXPECTED_PYPATH = path.join(__dirname, '..', 'gyp', 'pylib') | ||
var SEPARATOR = process.platform == 'win32' ? ';' : ':' | ||
var SPAWN_RESULT = { on: function () { } } | ||
|
||
test('configure PYTHONPATH with no existing env', function (t) { | ||
t.plan(1) | ||
|
||
delete process.env.PYTHONPATH | ||
|
||
var prog = gyp() | ||
prog.parseArgv([]) | ||
prog.spawn = function () { | ||
t.equal(process.env.PYTHONPATH, EXPECTED_PYPATH) | ||
return SPAWN_RESULT | ||
} | ||
configure(prog, []) | ||
}) | ||
|
||
test('configure PYTHONPATH with existing env of one dir', function (t) { | ||
t.plan(2) | ||
|
||
var existingPath = path.join('a', 'b') | ||
process.env.PYTHONPATH = existingPath | ||
|
||
var prog = gyp() | ||
prog.parseArgv([]) | ||
prog.spawn = function () { | ||
|
||
t.equal(process.env.PYTHONPATH, [EXPECTED_PYPATH, existingPath].join(SEPARATOR)) | ||
|
||
var dirs = process.env.PYTHONPATH.split(SEPARATOR) | ||
t.deepEqual(dirs, [EXPECTED_PYPATH, existingPath]) | ||
|
||
return SPAWN_RESULT | ||
} | ||
configure(prog, []) | ||
}) | ||
|
||
test('configure PYTHONPATH with existing env of multiple dirs', function (t) { | ||
t.plan(2) | ||
|
||
var pythonDir1 = path.join('a', 'b') | ||
var pythonDir2 = path.join('b', 'c') | ||
var existingPath = [pythonDir1, pythonDir2].join(SEPARATOR) | ||
process.env.PYTHONPATH = existingPath | ||
|
||
var prog = gyp() | ||
prog.parseArgv([]) | ||
prog.spawn = function () { | ||
|
||
t.equal(process.env.PYTHONPATH, [EXPECTED_PYPATH, existingPath].join(SEPARATOR)) | ||
|
||
var dirs = process.env.PYTHONPATH.split(SEPARATOR) | ||
t.deepEqual(dirs, [EXPECTED_PYPATH, pythonDir1, pythonDir2]) | ||
|
||
return SPAWN_RESULT | ||
} | ||
configure(prog, []) | ||
}) |