|
1 | 1 | const path = require("path"); |
2 | | -const { detectVirtualEnv, sanitizeConfig } = require("../lib/utils"); |
| 2 | +const mockSpawn = require("mock-spawn"); |
| 3 | +const assert = require("assert"); |
| 4 | +const child_process = require('child_process'); |
| 5 | +const { detectVirtualEnv, sanitizeConfig, detectPipEnv, replacePipEnvPathVar } = require("../lib/utils"); |
3 | 6 |
|
4 | 7 | const venvFixturesDir = path.join(__dirname, "fixtures", "venv"); |
5 | 8 |
|
@@ -51,6 +54,61 @@ describe("detectVirtualEnv", () => { |
51 | 54 | }); |
52 | 55 | }); |
53 | 56 |
|
| 57 | +describe("detect PipEnv", () => { |
| 58 | + const spawn = mockSpawn() |
| 59 | + child_process.spawn = spawn |
| 60 | + spawn.sequence.add(function (cb) { |
| 61 | + this.emit('error', new Error('spawn ENOENT')); |
| 62 | + setTimeout(function() { return cb(8); }, 10); |
| 63 | + }); |
| 64 | + it("with no pipenv", () => { |
| 65 | + waitsForPromise(() => { |
| 66 | + return detectPipEnv("/home/mock_pipenv").then(venv => { |
| 67 | + expect(venv).toBeNull(); |
| 68 | + assert.equal('pipenv', spawn.calls[0].command); |
| 69 | + assert.deepEqual(['--venv'], spawn.calls[0].args); |
| 70 | + }); |
| 71 | + }); |
| 72 | + }); |
| 73 | + |
| 74 | + it("with Unix pipenv", () => { |
| 75 | + spawn.sequence.add(spawn.simple(1, '/home/tvallois/.local/share/virtualenvs/unix-XZE001N_')); |
| 76 | + waitsForPromise(() => { |
| 77 | + return detectPipEnv("/home/mock_pipenv").then(venv => { |
| 78 | + expect(venv).toBe('/home/tvallois/.local/share/virtualenvs/unix-XZE001N_'); |
| 79 | + assert.equal('pipenv', spawn.calls[1].command); |
| 80 | + assert.deepEqual(['--venv'], spawn.calls[1].args); |
| 81 | + }); |
| 82 | + }); |
| 83 | + }); |
| 84 | + |
| 85 | + it("with Windows pipenv", () => { |
| 86 | + spawn.sequence.add(spawn.simple(1, 'C:\\Program Files\\tvallois\\virtualenvs\\windows-XZE001N_')); |
| 87 | + waitsForPromise(() => { |
| 88 | + return detectPipEnv("C:\\Program Files\\mock_pipenv").then(venv => { |
| 89 | + expect(venv).toBe('C:\\Program Files\\tvallois\\virtualenvs\\windows-XZE001N_'); |
| 90 | + assert.equal('pipenv', spawn.calls[2].command); |
| 91 | + assert.deepEqual(['--venv'], spawn.calls[2].args); |
| 92 | + }); |
| 93 | + }); |
| 94 | + }); |
| 95 | +}); |
| 96 | + |
| 97 | +describe("replacePipEnvPathVar", () => { |
| 98 | + it("replace $PIPENV_PATH", () => { |
| 99 | + expect(replacePipEnvPathVar("$PIPENV_PATH/bin/python", |
| 100 | + "/home/tvallois/.local/share/virtualenvs/unix-XZE001N_")) |
| 101 | + .toEqual("/home/tvallois/.local/share/virtualenvs/unix-XZE001N_/bin/python"); |
| 102 | + }); |
| 103 | + |
| 104 | + it("no $PIPENV_PATH", () => { |
| 105 | + expect(replacePipEnvPathVar("python", |
| 106 | + "/home/tvallois/.local/share/virtualenvs/unix-XZE001N_")) |
| 107 | + .toEqual("python"); |
| 108 | + }); |
| 109 | + |
| 110 | +}); |
| 111 | + |
54 | 112 | describe("sanitizeConfig", () => { |
55 | 113 | it("converts 'null' to null", () => { |
56 | 114 | const config = { |
|
0 commit comments