From 7a09cb930244ea333f9e6ce2edb3a06516737892 Mon Sep 17 00:00:00 2001 From: Frederic Collonval Date: Wed, 20 May 2020 08:58:46 +0200 Subject: [PATCH] Fix unit tests --- jupyter_conda/envmanager.py | 1 - jupyter_conda/tests/test_api.py | 6 ++-- labextension/src/__tests__/services.spec.ts | 31 +++++++++++++++++++-- labextension/src/tokens.ts | 2 +- 4 files changed, 32 insertions(+), 8 deletions(-) diff --git a/jupyter_conda/envmanager.py b/jupyter_conda/envmanager.py index 1d163919..2e14337d 100644 --- a/jupyter_conda/envmanager.py +++ b/jupyter_conda/envmanager.py @@ -256,7 +256,6 @@ async def export_env( ) else: command.append("--from-history") - ans = await self._execute(*command) rcode, output = ans if rcode > 0: diff --git a/jupyter_conda/tests/test_api.py b/jupyter_conda/tests/test_api.py index e65916dc..194c5c32 100644 --- a/jupyter_conda/tests/test_api.py +++ b/jupyter_conda/tests/test_api.py @@ -579,12 +579,10 @@ def test_env_export_history(self): ) def test_env_export_not_supporting_history(self): - manager = TestEnvironmentHandler.notebook.web_app.settings["env_manager"] - manager._conda_version = (4, 6, 0) - try: n = generate_name() self.wait_for_task(self.mk_env, n) + EnvManager._conda_version = (4, 6, 0) r = self.conda_api.get( ["environments", n], params={"download": 1, "history": 1} ) @@ -597,7 +595,7 @@ def test_env_export_not_supporting_history(self): self.assertRegex(content, r"- python=\d\.\d+\.\d+=\w+") self.assertRegex(content, r"prefix:") finally: - manager._conda_version = None + EnvManager._conda_version = None class TestCondaVersion(JupyterCondaAPITest): diff --git a/labextension/src/__tests__/services.spec.ts b/labextension/src/__tests__/services.spec.ts index 85ff2227..21f14d59 100644 --- a/labextension/src/__tests__/services.spec.ts +++ b/labextension/src/__tests__/services.spec.ts @@ -249,7 +249,7 @@ describe("jupyterlab_conda/services", () => { // TODO describe("dispose()", () => {}); describe("export()", () => { - it("should request to export", async () => { + it("should request to export in full format", async () => { const name = "dummy"; (ServerConnection.makeRequest as jest.Mock).mockResolvedValue( new Response("", { status: 200 }) @@ -258,7 +258,33 @@ describe("jupyterlab_conda/services", () => { const envManager = new CondaEnvironments(); await envManager.export(name); - const queryArgs = URLExt.objectToQueryString({ download: 1 }); + const queryArgs = URLExt.objectToQueryString({ + download: 1, + history: 0 + }); + expect(ServerConnection.makeRequest).toBeCalledWith( + URLExt.join(settings.baseUrl, "conda", "environments", name) + + queryArgs, + { + method: "GET" + }, + settings + ); + }); + + it("should request to export in history format", async () => { + const name = "dummy"; + (ServerConnection.makeRequest as jest.Mock).mockResolvedValue( + new Response("", { status: 200 }) + ); + + const envManager = new CondaEnvironments(); + await envManager.export(name, true); + + const queryArgs = URLExt.objectToQueryString({ + download: 1, + history: 1 + }); expect(ServerConnection.makeRequest).toBeCalledWith( URLExt.join(settings.baseUrl, "conda", "environments", name) + queryArgs, @@ -364,6 +390,7 @@ describe("jupyterlab_conda/services", () => { get: jest.fn().mockImplementation((key: string) => { // @ts-ignore return { + fromHistory: { composite: false }, types: { composite: {} }, whitelist: { composite: true } }[key]; diff --git a/labextension/src/tokens.ts b/labextension/src/tokens.ts index f23f1ea6..e824ed9c 100644 --- a/labextension/src/tokens.ts +++ b/labextension/src/tokens.ts @@ -54,7 +54,7 @@ export interface IEnvironmentManager extends IDisposable { * @param name Name of the environment to be exported * @param fromHistory Whether to export only from the history */ - export(name: string, fromHistory: boolean): Promise; + export(name: string, fromHistory?: boolean): Promise; /** * Create an environment from a packages list file *