diff options
author | Nate Sesti <sestinj@gmail.com> | 2023-07-03 19:34:33 -0700 |
---|---|---|
committer | Nate Sesti <sestinj@gmail.com> | 2023-07-03 19:34:33 -0700 |
commit | 97f477e4dd64165738a6beab74edf09ef355a55a (patch) | |
tree | 352ebe3e0bd37a53f54732184b507334f531430c /extension/src/activation/test | |
parent | a37550d5acc0c79efd18c80d9be3dcb3999dd4e9 (diff) | |
download | sncontinue-97f477e4dd64165738a6beab74edf09ef355a55a.tar.gz sncontinue-97f477e4dd64165738a6beab74edf09ef355a55a.tar.bz2 sncontinue-97f477e4dd64165738a6beab74edf09ef355a55a.zip |
fix python version on windows, other bugs, jest
Diffstat (limited to 'extension/src/activation/test')
-rw-r--r-- | extension/src/activation/test/environmentSetup.test.ts | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/extension/src/activation/test/environmentSetup.test.ts b/extension/src/activation/test/environmentSetup.test.ts new file mode 100644 index 00000000..ca487416 --- /dev/null +++ b/extension/src/activation/test/environmentSetup.test.ts @@ -0,0 +1,70 @@ +const child_process = require("child_process"); +import { platform } from "os"; +import { getPythonPipCommands } from "../environmentSetup"; + +jest.mock("os"); +jest.mock("child_process"); + +function mockPythonVersionMappings(mappings: { [pythonCmd: string]: string }) { + (child_process.exec as jest.Mock).mockImplementation( + (command: string, options: any) => { + const pythonCmd = command.split(" ")[0]; + if (pythonCmd in mappings) { + return Promise.resolve([mappings[pythonCmd], ""]); + } else { + return Promise.resolve(["", stubStderr]); + } + } + ); +} + +const stubStderr = + "This is a stub stderr, but will be checked only for existence."; +describe("getPythonPipCommands", () => { + describe("on Windows", () => { + it("should return the correct Python and Pip commands", async () => { + (platform as jest.Mock).mockReturnValue("win32"); + mockPythonVersionMappings({ + python: "Python 3.8.0", + }); + + const [pythonCmd, pipCmd] = await getPythonPipCommands(); + + expect(pythonCmd).toBe("python"); + expect(pipCmd).toBe("pip"); + + jest.restoreAllMocks(); + }); + describe("on MacOS", () => { + (platform as jest.Mock).mockReturnValue("darwin"); + it("should check through all python versions after finding 3.7", async () => { + mockPythonVersionMappings({ + python: "", + python3: "Python 3.7.0", + "python3.11": "Python 3.11.0", + }); + + const [pythonCmd, pipCmd] = await getPythonPipCommands(); + + expect(pythonCmd).toBe("python3.11"); + expect(pipCmd).toBe("pip3.11"); + + jest.restoreAllMocks(); + }); + + it("should use python3 if that maps to valid version", async () => { + mockPythonVersionMappings({ + python: "", + python3: "Python 3.8.0", + }); + + const [pythonCmd, pipCmd] = await getPythonPipCommands(); + + expect(pythonCmd).toBe("python3"); + expect(pipCmd).toBe("pip3"); + + jest.restoreAllMocks(); + }); + }); + }); +}); |