From 82a625641b69711a52b449f5267625ad6ae966ac Mon Sep 17 00:00:00 2001 From: Roman Yurchak Date: Mon, 3 Sep 2018 15:56:37 +0200 Subject: [PATCH] Better tests when loading multiple packages --- src/pyodide.js | 11 +++++++++-- test/test_package_loading.py | 8 ++++++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/pyodide.js b/src/pyodide.js index a6c290e22..5edb05589 100644 --- a/src/pyodide.js +++ b/src/pyodide.js @@ -49,8 +49,6 @@ var languagePluginLoader = new Promise((resolve, reject) => { package_uri = 'default channel'; } - console.log(`Loading ${package} from ${package_uri}`); - if (package in loadedPackages) { if (package_uri != loadedPackages[package]) { throw new Error( @@ -58,7 +56,16 @@ var languagePluginLoader = new Promise((resolve, reject) => { `${package} from ${package_uri} while it is already ` + `loaded from ${loadedPackages[package]}!`); } + } else if (package in toLoad) { + if (package_uri != toLoad[package]) { + throw new Error( + `URI mismatch, attempting to load package ` + + `${package} from ${package_uri} while it is already ` + + `being loaded from ${toLoad[package]}!`); + } } else { + console.log(`Loading ${package} from ${package_uri}`); + toLoad[package] = package_uri; if (packages.hasOwnProperty(package)) { packages[package].forEach((subpackage) => { diff --git a/test/test_package_loading.py b/test/test_package_loading.py index 6a695f9d0..05cd73c1e 100644 --- a/test/test_package_loading.py +++ b/test/test_package_loading.py @@ -37,8 +37,12 @@ def test_invalid_package_name(selenium): selenium.load_package('tcp://some_url') -def test_load_packages_multiple(selenium): - selenium.load_package(['pyparsing', 'pytz']) +def test_load_packages_multiple(selenium_standalone): + selenium = selenium_standalone + selenium.load_package(['pyparsing', 'matplotlib']) + selenium.run('import pyparsing') + selenium.run('import matplotlib') + assert selenium.logs.count('Loading pyparsing') == 1 @pytest.mark.xfail(reason='Not implemented')