Browse Source

Add tests for a mime renderer extension

Steven Silvester 7 years ago
parent
commit
24e85d48f8

+ 2 - 0
jupyterlab/package.app.json

@@ -136,6 +136,8 @@
       "@jupyterlab/theme-light-extension",
       "@jupyterlab/tooltip-extension"
     ],
+    "mimeExtensions": [
+    ],
     "singletonPackages": [
       "@jupyterlab/application",
       "@jupyterlab/apputils",

+ 31 - 0
jupyterlab/tests/mock-mimeextension/index.js

@@ -0,0 +1,31 @@
+// Copyright (c) Jupyter Development Team.
+// Distributed under the terms of the Modified BSD License.
+
+var Widget = require('@phosphor/widgets').Widget;
+
+var renderer = {
+  mimeTypes = ['text/plain'],
+
+  canRender: function (options) {
+    return this.mimeTypes.indexOf(options.mimeType) !== -1;
+  },
+
+  render: function (options) {
+    return new Widget();
+  },
+
+  wouldSanitize: function (options) {
+    return false;
+  }
+};
+
+
+module.exports = {
+  mimeType: 'text/plain',
+  renderer: renderer,
+  widgetFactoryOptions: {
+    name: 'Test',
+    fileExtensions: ['.txt'],
+    readOnly: true
+  }
+}

+ 10 - 0
jupyterlab/tests/mock-mimeextension/package.json

@@ -0,0 +1,10 @@
+{
+  "name": "@jupyterlab/mime-extension-test",
+  "version": "0.1.0",
+  "private": true,
+  "jupyterlab": { "mimeExtension": true },
+  "dependencies": {
+    "@phosphor/widgets": "^1.3.0"
+  },
+  "devDependencies": {}
+}

+ 21 - 4
jupyterlab/tests/test_jupyterlab.py

@@ -77,6 +77,7 @@ class TestExtension(TestCase):
         self.source_dir = pjoin(here, 'mockextension')
         self.incompat_dir = pjoin(here, 'mockextension-incompat')
         self.mock_package = pjoin(here, 'mockpackage')
+        self.mime_renderer_dir = pjoin(here, 'mock-mimeextension')
 
         self.patches = []
         p = patch.dict('os.environ', {
@@ -126,10 +127,16 @@ class TestExtension(TestCase):
         assert glob.glob(path)
         assert '@jupyterlab/python-tests' in _get_extensions(self.app_dir)
 
+    def test_install_mime_renderer(self):
+        install_extension(self.mime_renderer_dir)
+        assert '@jupyterlab/mime-extension-test' in _get_extensions(self.app_dir)
+
+        uninstall_extension('@jupyterlab/mime-extension-test')
+        assert '@jupyterlab/mime-extension-test' not in _get_extensions(self.app_dir)
+
     def test_install_incompatible(self):
-        with pytest.raises(ValueError) as excinfo:
+        with pytest.raises(ValueError):
             install_extension(self.incompat_dir)
-        assert 'Conflicting Dependencies' in str(excinfo.value)
 
     def test_install_failed(self):
         path = self.mock_package
@@ -168,6 +175,17 @@ class TestExtension(TestCase):
         assert '@jupyterlab/python-tests' in linked
         assert '@jupyterlab/python-tests' in _get_extensions(self.app_dir)
 
+    def test_link_mime_renderer(self):
+        link_package(self.mime_renderer_dir)
+        linked = _get_linked_packages().keys()
+        assert '@jupyterlab/mime-extension-test' in linked
+        assert '@jupyterlab/mime-extension-test' in _get_extensions(self.app_dir)
+
+        unlink_package('@jupyterlab/mime-extension-test')
+        linked = _get_linked_packages().keys()
+        assert '@jupyterlab/mime-extension-test' not in linked
+        assert '@jupyterlab/mime-extension-test' not in _get_extensions(self.app_dir)
+
     def test_link_package(self):
         path = self.mock_package
         link_package(path)
@@ -181,9 +199,8 @@ class TestExtension(TestCase):
         assert not data['name'] in linked
 
     def test_link_incompatible(self):
-        with pytest.raises(ValueError) as excinfo:
+        with pytest.raises(ValueError):
             install_extension(self.incompat_dir)
-        assert 'Conflicting Dependencies' in str(excinfo.value)
 
     def test_unlink_package(self):
         target = self.source_dir

+ 1 - 0
lerna.json

@@ -2,6 +2,7 @@
   "lerna": "2.0.0-beta.38",
   "packages": [
     "jupyterlab",
+    "jupyterlab/tests/mock-mimeextension",
     "examples/*",
     "packages/*",
     "packages/services/examples/node",