Browse Source

Update tests

Steven Silvester 8 years ago
parent
commit
13a212cbdd
2 changed files with 28 additions and 24 deletions
  1. 2 1
      jupyterlab/commands.py
  2. 26 23
      jupyterlab/tests/test_jupyterlab.py

+ 2 - 1
jupyterlab/commands.py

@@ -29,7 +29,6 @@ else:
 
 
 here = osp.dirname(osp.abspath(__file__))
-sys_path = pjoin(ENV_JUPYTER_PATH[0], 'lab', 'extensions')
 
 
 def get_app_dir(app_dir=None):
@@ -319,6 +318,7 @@ def list_extensions(app_dir=None):
     linked = []
 
     # We want to organize by dir.
+    sys_path = pjoin(get_app_dir(), 'extensions')
     for (key, value) in extensions.items():
         if key in linked:
             linked.append(key)
@@ -516,6 +516,7 @@ def _get_extensions(app_dir):
     extensions = dict()
 
     # Get system level packages
+    sys_path = pjoin(get_app_dir(), 'extensions')
     for target in glob.glob(pjoin(sys_path, '*.tgz')):
         data = _read_package(target)
         extensions[data['name']] = dict(path=os.path.realpath(target),

+ 26 - 23
jupyterlab/tests/test_jupyterlab.py

@@ -27,8 +27,8 @@ from jupyterlab.extension import (
 )
 from jupyterlab.commands import (
     install_extension, uninstall_extension, list_extensions,
-    build, link_package, unlink_package, get_app_dir, should_build,
-    disable_extension, enable_extension,
+    build, link_package, unlink_package, should_build,
+    disable_extension, enable_extension, _get_extensions,
     _get_linked_packages, _ensure_package, _get_disabled
 )
 
@@ -104,15 +104,18 @@ class TestExtension(TestCase):
         self.assertEqual(commands.ENV_JUPYTER_PATH, [self.data_dir])
         self.assertEqual(commands.get_app_dir(), os.path.realpath(pjoin(self.data_dir, 'lab')))
 
+        self.app_dir = commands.get_app_dir()
+        print('****', self.app_dir)
+
     def tearDown(self):
         for modulename in self._mock_extensions:
             sys.modules.pop(modulename)
 
     def test_install_extension(self):
         install_extension(self.source_dir)
-        path = pjoin(get_app_dir(), 'extensions', '*python-tests*.tgz')
+        path = pjoin(self.app_dir, 'extensions', '*python-tests*.tgz')
         assert glob.glob(path)
-        assert '@jupyterlab/python-tests' in list_extensions()
+        assert '@jupyterlab/python-tests' in _get_extensions(self.app_dir)
 
     def test_install_failed(self):
         path = os.path.realpath(pjoin(here, '..'))
@@ -120,18 +123,18 @@ class TestExtension(TestCase):
             install_extension(path)
         with open(pjoin(path, 'package.json')) as fid:
             data = json.load(fid)
-        assert not data['name'] in list_extensions()
+        assert not data['name'] in _get_extensions(self.app_dir)
 
     def test_uninstall_extension(self):
         install_extension(self.source_dir)
         uninstall_extension('@jupyterlab/python-tests')
-        path = pjoin(get_app_dir(), 'extensions', '*python_tests*.tgz')
+        path = pjoin(self.app_dir, 'extensions', '*python_tests*.tgz')
         assert not glob.glob(path)
-        assert '@jupyterlab/python-tests' not in list_extensions()
+        assert '@jupyterlab/python-tests' not in _get_extensions(self.app_dir)
 
     def test_uninstall_core_extension(self):
         uninstall_extension('@jupyterlab/console-extension')
-        app_dir = get_app_dir()
+        app_dir = self.app_dir
         _ensure_package(app_dir)
         with open(pjoin(app_dir, 'staging', 'package.json')) as fid:
             data = json.load(fid)
@@ -142,7 +145,7 @@ class TestExtension(TestCase):
         link_package(self.source_dir)
         linked = _get_linked_packages().keys()
         assert '@jupyterlab/python-tests' in linked
-        assert '@jupyterlab/python-tests' in list_extensions()
+        assert '@jupyterlab/python-tests' in _get_extensions(self.app_dir)
 
     def test_link_package(self):
         path = os.path.realpath(pjoin(here, '..'))
@@ -151,7 +154,7 @@ class TestExtension(TestCase):
         with open(pjoin(path, 'package.json')) as fid:
             data = json.load(fid)
         assert data['name'] in linked
-        assert not data['name'] in list_extensions()
+        assert not data['name'] in _get_extensions(self.app_dir)
         unlink_package(path)
         linked = _get_linked_packages().keys()
         assert not data['name'] in linked
@@ -162,7 +165,7 @@ class TestExtension(TestCase):
         unlink_package(target)
         linked = _get_linked_packages().keys()
         assert '@jupyterlab/python-tests' not in linked
-        assert '@jupyterlab/python-tests' not in list_extensions()
+        assert '@jupyterlab/python-tests' not in _get_extensions(self.app_dir)
 
     def test_list_extensions(self):
         install_extension(self.source_dir)
@@ -174,12 +177,12 @@ class TestExtension(TestCase):
         install_extension(self.source_dir, app_dir)
         path = pjoin(app_dir, 'extensions', '*python-tests*.tgz')
         assert glob.glob(path)
-        assert '@jupyterlab/python-tests' in list_extensions(app_dir)
+        assert '@jupyterlab/python-tests' in _get_extensions(app_dir)
 
         uninstall_extension('@jupyterlab/python-tests', app_dir)
         path = pjoin(app_dir, 'extensions', '*python-tests*.tgz')
         assert not glob.glob(path)
-        assert '@jupyterlab/python-tests' not in list_extensions(app_dir)
+        assert '@jupyterlab/python-tests' not in _get_extensions(app_dir)
 
         link_package(self.source_dir, app_dir)
         linked = _get_linked_packages(app_dir).keys()
@@ -191,17 +194,17 @@ class TestExtension(TestCase):
 
     def test_app_dir_use_sys_prefix(self):
         app_dir = self.tempdir()
-        if os.path.exists(get_app_dir()):
-            os.removedirs(get_app_dir())
+        if os.path.exists(self.app_dir):
+            os.removedirs(self.app_dir)
 
         install_extension(self.source_dir)
         path = pjoin(app_dir, 'extensions', '*python-tests*.tgz')
         assert not glob.glob(path)
-        assert '@jupyterlab/python-tests' in list_extensions(app_dir)
+        assert '@jupyterlab/python-tests' in _get_extensions(app_dir)
 
     def test_app_dir_shadowing(self):
         app_dir = self.tempdir()
-        sys_dir = get_app_dir()
+        sys_dir = self.app_dir
         if os.path.exists(sys_dir):
             os.removedirs(sys_dir)
 
@@ -210,33 +213,33 @@ class TestExtension(TestCase):
         assert glob.glob(sys_path)
         app_path = pjoin(app_dir, 'extensions', '*python-tests*.tgz')
         assert not glob.glob(app_path)
-        assert '@jupyterlab/python-tests' in list_extensions(app_dir)
+        assert '@jupyterlab/python-tests' in _get_extensions(app_dir)
 
         install_extension(self.source_dir, app_dir)
         assert glob.glob(app_path)
-        assert '@jupyterlab/python-tests' in list_extensions(app_dir)
+        assert '@jupyterlab/python-tests' in _get_extensions(app_dir)
 
         uninstall_extension('@jupyterlab/python-tests', app_dir)
         assert not glob.glob(app_path)
         assert glob.glob(sys_path)
-        assert '@jupyterlab/python-tests' in list_extensions(app_dir)
+        assert '@jupyterlab/python-tests' in _get_extensions(app_dir)
 
         uninstall_extension('@jupyterlab/python-tests', app_dir)
         assert not glob.glob(app_path)
         assert not glob.glob(sys_path)
-        assert '@jupyterlab/python-tests' not in list_extensions(app_dir)
+        assert '@jupyterlab/python-tests' not in _get_extensions(app_dir)
 
     def test_build(self):
         install_extension(self.source_dir)
         build()
         # check staging directory.
-        entry = pjoin(get_app_dir(), 'staging', 'build', 'index.out.js')
+        entry = pjoin(self.app_dir, 'staging', 'build', 'index.out.js')
         with open(entry) as fid:
             data = fid.read()
         assert '@jupyterlab/python-tests' in data
 
         # check static directory.
-        entry = pjoin(get_app_dir(), 'static', 'index.out.js')
+        entry = pjoin(self.app_dir, 'static', 'index.out.js')
         with open(entry) as fid:
             data = fid.read()
         assert '@jupyterlab/python-tests' in data