示例#1
0
    def test_update_all(self):
        updated = []
        def _mock_update(self, name, *args, **kwargs):
            updated.append(name[0] + name[1:].split('@')[0])
            return True

        original_app_info = commands._AppHandler._get_app_info
        def _mock_app_info(self):
            info = original_app_info(self)
            info['local_extensions'] = []
            return info


        assert install_extension(self.mock_extension) is True
        assert install_extension(self.mock_mimeextension) is True

        p1 = patch.object(
            commands._AppHandler,
            '_update_extension',
            _mock_update)

        # local packages are not updated, so mock them as non-local:
        p2 = patch.object(
            commands._AppHandler,
            '_get_app_info',
            _mock_app_info
        )

        with p1, p2:
            assert update_extension(None, all_=True) is True
        assert sorted(updated) == [self.pkg_names['extension'], self.pkg_names['mimeextension']]
 def test_install_extension(self):
     install_extension(pjoin(here, 'mockextension'))
     path = pjoin(_get_cache_dir(), '*.tgz')
     assert glob.glob(path)
     data = _get_config()
     exts = data['installed_extensions']
     assert '@jupyterlab/python-tests' in exts
示例#3
0
    def test_update_multiple(self):
        installed = []
        def _mock_install(self, name, *args, **kwargs):
            installed.append(name[0] + name[1:].split('@')[0])
            return dict(name=name, is_dir=False, path='foo/bar/' + name)

        def _mock_latest(self, name):
            return '10000.0.0'

        p1 = patch.object(
            commands._AppHandler,
            '_install_extension',
            _mock_install)
        p2 = patch.object(
            commands._AppHandler,
            '_latest_compatible_package_version',
            _mock_latest)

        install_extension(self.mock_extension)
        install_extension(self.mock_mimeextension)

        with p1, p2:
            assert update_extension(self.pkg_names['extension']) is True
            assert update_extension(self.pkg_names['mimeextension']) is True
        assert installed == [self.pkg_names['extension'], self.pkg_names['mimeextension']]
 def test_install_failed(self):
     path = self.mock_package
     with pytest.raises(ValueError):
         install_extension(path)
     with open(pjoin(path, 'package.json')) as fid:
         data = json.load(fid)
     assert not data['name'] in _get_extensions(self.app_dir)
 def test_build(self):
     install_extension(pjoin(here, 'mockextension'))
     build()
     entry = pjoin(_get_build_dir(), 'index.out.js')
     with open(entry) as fid:
         data = fid.read()
     assert '@jupyterlab/python-tests' in data
示例#6
0
    def test_app_dir_shadowing(self):
        app_dir = self.tempdir()
        sys_dir = self.app_dir
        if os.path.exists(sys_dir):
            os.removedirs(sys_dir)

        assert install_extension(self.mock_extension) is True
        sys_path = pjoin(sys_dir, 'extensions', '*.tgz')
        assert glob.glob(sys_path)
        app_path = pjoin(app_dir, 'extensions', '*.tgz')
        assert not glob.glob(app_path)
        extensions = get_app_info(app_dir)['extensions']
        ext_name = self.pkg_names['extension']
        assert ext_name in extensions
        assert check_extension(ext_name, app_dir)

        assert install_extension(self.mock_extension, app_dir) is True
        assert glob.glob(app_path)
        extensions = get_app_info(app_dir)['extensions']
        assert ext_name in extensions
        assert check_extension(ext_name, app_dir)

        assert uninstall_extension(self.pkg_names['extension'], app_dir) is True
        assert not glob.glob(app_path)
        assert glob.glob(sys_path)
        extensions = get_app_info(app_dir)['extensions']
        assert ext_name in extensions
        assert check_extension(ext_name, app_dir)

        assert uninstall_extension(self.pkg_names['extension'], app_dir) is True
        assert not glob.glob(app_path)
        assert not glob.glob(sys_path)
        extensions = get_app_info(app_dir)['extensions']
        assert ext_name not in extensions
        assert not check_extension(ext_name, app_dir)
    def test_app_dir_shadowing(self):
        app_dir = self.tempdir()
        sys_dir = self.app_dir
        if os.path.exists(sys_dir):
            os.removedirs(sys_dir)

        install_extension(self.source_dir)
        sys_path = pjoin(sys_dir, 'extensions', '*python-tests*.tgz')
        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 _get_extensions(app_dir)

        install_extension(self.source_dir, app_dir)
        assert glob.glob(app_path)
        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 _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 _get_extensions(app_dir)
 def test_enable_extension(self):
     app_dir = self.tempdir()
     install_extension(self.source_dir, app_dir)
     disable_extension('@jupyterlab/python-tests', app_dir)
     enable_extension('@jupyterlab/python-tests', app_dir)
     disabled = _get_disabled(app_dir)
     assert '@jupyterlab/python-tests' not in disabled
示例#9
0
    def test_app_dir(self):
        app_dir = self.tempdir()

        install_extension(self.mock_extension, app_dir)
        path = pjoin(app_dir, 'extensions', '*.tgz')
        assert glob.glob(path)
        extensions = get_app_info(app_dir)['extensions']
        ext_name = self.pkg_names['extension']
        assert ext_name in extensions
        assert check_extension(ext_name, app_dir)

        uninstall_extension(self.pkg_names['extension'], app_dir)
        path = pjoin(app_dir, 'extensions', '*.tgz')
        assert not glob.glob(path)
        extensions = get_app_info(app_dir)['extensions']
        assert ext_name not in extensions
        assert not check_extension(ext_name, app_dir)

        link_package(self.mock_package, app_dir)
        linked = get_app_info(app_dir)['linked_packages']
        pkg_name = self.pkg_names['package']
        assert pkg_name in linked
        assert check_extension(pkg_name, app_dir)

        unlink_package(self.mock_package, app_dir)
        linked = get_app_info(app_dir)['linked_packages']
        assert pkg_name not in linked
        assert not check_extension(pkg_name, app_dir)
 def test_install_failed(self):
     path = os.path.realpath(pjoin(here, '..'))
     with pytest.raises(ValueError):
         install_extension(path)
     with open(pjoin(path, 'package.json')) as fid:
         data = json.load(fid)
     assert not data['name'] in list_extensions()
示例#11
0
 def test_install_extension(self):
     install_extension(self.mock_extension)
     path = pjoin(self.app_dir, 'extensions', '*.tgz')
     assert glob.glob(path)
     extensions = get_app_info(self.app_dir)['extensions']
     name = self.pkg_names['extension']
     assert name in extensions
     assert check_extension(name)
示例#12
0
 def test_should_build(self):
     assert not should_build()[0]
     install_extension(self.source_dir)
     assert should_build()[0]
     build()
     assert not should_build()[0]
     uninstall_extension('@jupyterlab/python-tests')
     assert should_build()[0]
示例#13
0
    def test_install_mime_renderer(self):
        install_extension(self.mock_mimeextension)
        name = self.pkg_names['mimeextension']
        assert name in get_app_info(self.app_dir)['extensions']
        assert check_extension(name)

        assert uninstall_extension(name) is True
        assert name not in get_app_info(self.app_dir)['extensions']
        assert not check_extension(name)
示例#14
0
 def test_install_twice(self):
     assert install_extension(self.mock_extension) is True
     path = pjoin(commands.get_app_dir(), 'extensions', '*.tgz')
     assert install_extension(self.mock_extension) is True
     assert glob.glob(path)
     extensions = get_app_info(self.app_dir)['extensions']
     name = self.pkg_names['extension']
     assert name in extensions
     assert check_extension(name)
示例#15
0
    def test_app_dir_use_sys_prefix(self):
        app_dir = self.tempdir()
        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 _get_extensions(app_dir)
示例#16
0
 def test_install_failed(self):
     path = self.mock_package
     with pytest.raises(ValueError):
         install_extension(path)
     with open(pjoin(path, 'package.json')) as fid:
         data = json.load(fid)
     extensions = get_app_info(self.app_dir)['extensions']
     name = data['name']
     assert name not in extensions
     assert not check_extension(name)
示例#17
0
 def test_uninstall_all_extensions(self):
     install_extension(self.mock_extension)
     install_extension(self.mock_mimeextension)
     ext_name = self.pkg_names['extension']
     mime_ext_name = self.pkg_names['mimeextension']
     assert check_extension(ext_name) is True
     assert check_extension(mime_ext_name) is True
     assert uninstall_extension(all_=True) is True
     extensions = get_app_info(self.app_dir)['extensions']
     assert ext_name not in extensions
     assert mime_ext_name not in extensions
示例#18
0
    def test_app_dir_use_sys_prefix(self):
        app_dir = self.tempdir()
        if os.path.exists(self.app_dir):
            os.removedirs(self.app_dir)

        install_extension(self.mock_extension)
        path = pjoin(app_dir, 'extensions', '*.tgz')
        assert not glob.glob(path)
        extensions = get_app_info(app_dir)['extensions']
        ext_name = self.pkg_names['extension']
        assert ext_name in extensions
        assert check_extension(ext_name, app_dir)
示例#19
0
    def test_validation(self):
        path = self.mock_extension
        os.remove(pjoin(path, 'index.js'))
        with pytest.raises(ValueError):
            install_extension(path)
        assert not check_extension(self.pkg_names["extension"])

        path = self.mock_mimeextension
        os.remove(pjoin(path, 'index.js'))
        with pytest.raises(ValueError):
            install_extension(path)
        assert not check_extension(self.pkg_names["mimeextension"])
示例#20
0
 def test_enable_extension(self):
     app_dir = self.tempdir()
     install_extension(self.mock_extension, app_dir)
     disable_extension(self.pkg_names['extension'], app_dir)
     enable_extension(self.pkg_names['extension'], app_dir)
     info = get_app_info(app_dir)
     name = self.pkg_names['extension']
     assert name not in info['disabled']
     assert check_extension(name, app_dir)
     disable_extension('@jupyterlab/notebook-extension', app_dir)
     assert name not in info['disabled']
     assert check_extension(name, app_dir)
     assert '@jupyterlab/notebook-extension' not in info['disabled']
     assert not check_extension('@jupyterlab/notebook-extension', app_dir)
示例#21
0
    def test_build(self):
        install_extension(self.mock_extension)
        build()
        # check staging directory.
        entry = pjoin(self.app_dir, 'staging', 'build', 'index.out.js')
        with open(entry) as fid:
            data = fid.read()
        assert self.pkg_names['extension'] in data

        # check static directory.
        entry = pjoin(self.app_dir, 'static', 'index.out.js')
        with open(entry) as fid:
            data = fid.read()
        assert self.pkg_names['extension'] in data
示例#22
0
    def test_build(self):
        install_extension(self.source_dir)
        build()
        # check staging directory.
        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(self.app_dir, 'static', 'index.out.js')
        with open(entry) as fid:
            data = fid.read()
        assert '@jupyterlab/python-tests' in data
示例#23
0
    def test_uninstall_core_extension(self):
        uninstall_extension('@jupyterlab/console-extension')
        app_dir = self.app_dir
        _ensure_package(app_dir)
        with open(pjoin(app_dir, 'staging', 'package.json')) as fid:
            data = json.load(fid)
        extensions = data['jupyterlab']['extensions']
        assert '@jupyterlab/console-extension' not in extensions

        install_extension('@jupyterlab/console-extension')
        _ensure_package(app_dir)
        with open(pjoin(app_dir, 'staging', 'package.json')) as fid:
            data = json.load(fid)
        extensions = data['jupyterlab']['extensions']
        assert '@jupyterlab/console-extension' in extensions
示例#24
0
    def test_build_custom(self):
        install_extension(self.source_dir)
        build(name='foo', version='1.0')

        # check static directory.
        entry = pjoin(self.app_dir, 'static', 'index.out.js')
        with open(entry) as fid:
            data = fid.read()
        assert '@jupyterlab/python-tests' in data

        pkg = pjoin(self.app_dir, 'static', 'package.json')
        with open(pkg) as fid:
            data = json.load(fid)
        assert data['jupyterlab']['name'] == 'foo'
        assert data['jupyterlab']['version'] == '1.0'
示例#25
0
    def test_build_custom(self):
        install_extension(self.mock_extension)
        build(name='foo', version='1.0', public_url='bar')

        # check static directory.
        entry = pjoin(self.app_dir, 'static', 'index.out.js')
        with open(entry) as fid:
            data = fid.read()
        assert self.pkg_names['extension'] in data

        pkg = pjoin(self.app_dir, 'static', 'package.json')
        with open(pkg) as fid:
            data = json.load(fid)
        assert data['jupyterlab']['name'] == 'foo'
        assert data['jupyterlab']['version'] == '1.0'
        assert data['jupyterlab']['publicUrl'] == 'bar'
示例#26
0
 def test_uninstall_extension(self):
     assert install_extension(self.mock_extension) is True
     name = self.pkg_names['extension']
     assert check_extension(name)
     assert uninstall_extension(self.pkg_names['extension']) is True
     path = pjoin(self.app_dir, 'extensions', '*.tgz')
     assert not glob.glob(path)
     extensions = get_app_info(self.app_dir)['extensions']
     assert name not in extensions
     assert not check_extension(name)
示例#27
0
    def test_build_check(self):
        # Do the initial build.
        assert build_check()
        assert install_extension(self.mock_extension) is True
        assert link_package(self.mock_package) is True
        build()
        assert not build_check()

        # Check installed extensions.
        assert install_extension(self.mock_mimeextension) is True
        assert build_check()
        assert uninstall_extension(self.pkg_names['mimeextension']) is True
        assert not build_check()

        # Check local extensions.
        pkg_path = pjoin(self.mock_extension, 'package.json')
        with open(pkg_path) as fid:
            data = json.load(fid)
        with open(pkg_path, 'rb') as fid:
            orig = fid.read()
        data['foo'] = 'bar'
        with open(pkg_path, 'w') as fid:
            json.dump(data, fid)
        assert build_check()
        assert build_check()

        with open(pkg_path, 'wb') as fid:
            fid.write(orig)

        assert not build_check()

        # Check linked packages.
        pkg_path = pjoin(self.mock_package, 'index.js')
        with open(pkg_path, 'rb') as fid:
            orig = fid.read()
        with open(pkg_path, 'wb') as fid:
            fid.write(orig + b'\nconsole.log("hello");')
        assert build_check()
        assert build_check()

        with open(pkg_path, 'wb') as fid:
            fid.write(orig)
        assert not build_check()
示例#28
0
    def test_app_dir(self):
        app_dir = self.tempdir()

        install_extension(self.source_dir, app_dir)
        path = pjoin(app_dir, 'extensions', '*python-tests*.tgz')
        assert glob.glob(path)
        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 _get_extensions(app_dir)

        link_package(self.source_dir, app_dir)
        linked = _get_linked_packages(app_dir).keys()
        assert '@jupyterlab/python-tests' in linked

        unlink_package(self.source_dir, app_dir)
        linked = _get_linked_packages(app_dir).keys()
        assert '@jupyterlab/python-tests' not in linked
示例#29
0
    def test_uninstall_core_extension(self):
        assert uninstall_extension('@jupyterlab/console-extension') is True
        app_dir = self.app_dir
        build(app_dir)
        with open(pjoin(app_dir, 'staging', 'package.json')) as fid:
            data = json.load(fid)
        extensions = data['jupyterlab']['extensions']
        assert '@jupyterlab/console-extension' not in extensions
        assert not check_extension('@jupyterlab/console-extension')

        assert install_extension('@jupyterlab/console-extension') is True
        build(app_dir)
        with open(pjoin(app_dir, 'staging', 'package.json')) as fid:
            data = json.load(fid)
        extensions = data['jupyterlab']['extensions']
        assert '@jupyterlab/console-extension' in extensions
        assert check_extension('@jupyterlab/console-extension')
示例#30
0
 def test_uninstall_extension(self):
     install_extension(self.mock_extension)
     uninstall_extension('@jupyterlab/python-tests')
     path = pjoin(self.app_dir, 'extensions', '*python_tests*.tgz')
     assert not glob.glob(path)
     assert '@jupyterlab/python-tests' not in _get_extensions(self.app_dir)
示例#31
0
 def test_link_incompatible(self):
     with pytest.raises(ValueError) as excinfo:
         install_extension(self.mock_incompat)
     assert 'Conflicting Dependencies' in str(excinfo.value)
示例#32
0
 def test_list_extensions(self):
     install_extension(self.source_dir)
     list_extensions()
示例#33
0
    def test_install_mime_renderer(self):
        install_extension(self.mock_mimeextension)
        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)
示例#34
0
 def test_list_extensions(self):
     assert install_extension(self.mock_extension) is True
     list_extensions()
示例#35
0
 def test_install_incompatible(self):
     with pytest.raises(ValueError) as excinfo:
         install_extension(self.mock_incompat)
     assert "Conflicting Dependencies" in str(excinfo.value)
     assert not check_extension(self.pkg_names["incompat"])
示例#36
0
 def test_list_extensions(self):
     install_extension(self.mock_extension)
     list_extensions()
示例#37
0
    def test_install_compatible(self):
        core_data = _get_default_core_data()
        current_app_dep = core_data['dependencies']['@jupyterlab/application']
        def _gen_dep(ver):
            return { "dependencies": {
                '@jupyterlab/application': ver
            }}
        def _mock_metadata(registry, name, logger):
            assert name == 'mockextension'
            return {
                "name": name,
                "versions": {
                    "0.9.0": _gen_dep(current_app_dep),
                    "1.0.0": _gen_dep(current_app_dep),
                    "1.1.0": _gen_dep(current_app_dep),
                    "2.0.0": _gen_dep('^2000.0.0'),
                    "2.0.0-b0": _gen_dep(current_app_dep),
                    "2.1.0-b0": _gen_dep('^2000.0.0'),
                    "2.1.0": _gen_dep('^2000.0.0'),
                }
            }

        def _mock_extract(self, source, tempdir, *args, **kwargs):
            data = dict(
                name=source, version='2.1.0',
                jupyterlab=dict(extension=True),
                jupyterlab_extracted_files=['index.js'],
            )
            data.update(_gen_dep('^2000.0.0'))
            info = dict(
                source=source, is_dir=False, data=data,
                name=source, version=data['version'],
                filename='mockextension.tgz',
                path=pjoin(tempdir, 'mockextension.tgz'),
            )
            return info

        class Success(Exception):
            pass

        def _mock_install(self, name, *args, **kwargs):
            assert name in ('mockextension', '[email protected]')
            if name == '[email protected]':
                raise Success()
            return orig_install(self, name, *args, **kwargs)

        p1 = patch.object(
            commands,
            '_fetch_package_metadata',
            _mock_metadata)
        p2 = patch.object(
            commands._AppHandler,
            '_extract_package',
            _mock_extract)
        p3 = patch.object(
            commands._AppHandler,
            '_install_extension',
            _mock_install)
        with p1, p2:
            orig_install = commands._AppHandler._install_extension
            with p3, pytest.raises(Success):
                assert install_extension('mockextension') is True
示例#38
0
 def test_install_twice(self):
     install_extension(self.mock_extension)
     path = pjoin(commands.get_app_dir(), 'extensions', '*python-tests*.tgz')
     install_extension(self.mock_extension)
     assert glob.glob(path)
     assert '@jupyterlab/python-tests' in _get_extensions(self.app_dir)