Exemplo n.º 1
0
def test_kernel_name_format(monkeypatch, tmp_path, name_format, expected):
    kernelspec = {
        "display_name": "Python 3 (XPython)",
        "argv":
        ["@XPYTHON_KERNELSPEC_PATH@xpython", "-f", "{connection_file}"],
        "language": "python",
        "metadata": {
            "debugger": True
        }
    }
    mock_info = {'conda_prefix': '/'}
    env_name = "dummy_env"

    def envs(*args):
        return {env_name: str(tmp_path)}

    kernel_file = tmp_path / 'share' / 'jupyter' / 'kernels' / 'xpython' / 'kernel.json'
    kernel_file.parent.mkdir(parents=True, exist_ok=True)
    if sys.version_info >= (3, 0):
        kernel_file.write_text(json.dumps(kernelspec))
    else:
        kernel_file.write_bytes(json.dumps(kernelspec))

    monkeypatch.setattr(CondaKernelSpecManager, "_conda_info", mock_info)
    monkeypatch.setattr(CondaKernelSpecManager, "_all_envs", envs)

    manager = CondaKernelSpecManager(name_format=name_format)
    specs = manager._all_specs()

    assert len(specs) == 1
    for spec in specs.values():
        assert spec["display_name"] == expected.format(env_name=env_name)
Exemplo n.º 2
0
def test_kernel_metadata(monkeypatch, tmp_path, kernelspec):

    mock_info = {'conda_prefix': '/'}

    def envs(*args):
        return {'env_name': str(tmp_path)}

    kernel_file = tmp_path / 'share' / 'jupyter' / 'kernels' / 'my_kernel' / 'kernel.json'
    kernel_file.parent.mkdir(parents=True, exist_ok=True)
    if sys.version_info >= (3, 0):
        kernel_file.write_text(json.dumps(kernelspec))
    else:
        kernel_file.write_bytes(json.dumps(kernelspec))

    monkeypatch.setattr(CondaKernelSpecManager, "_conda_info", mock_info)
    monkeypatch.setattr(CondaKernelSpecManager, "_all_envs", envs)

    manager = CondaKernelSpecManager()
    specs = manager._all_specs()

    assert len(specs) == 1
    for spec in specs.values():
        metadata = spec['metadata']
        for key, value in kernelspec['metadata'].items():
            assert key in metadata
            assert metadata[key] == value
Exemplo n.º 3
0
def test_runner():
    if os.environ.get('CONDA_BUILD'):
        # The current version of conda build manually adds the activation
        # directories to the PATH---and then calls the standard conda
        # activation script, which does it again. This frustrates conda's
        # ability to deactivate this environment. Most package builds are
        # not affected by this, but we are, because our tests need to do
        # environment activation and deactivation. To fix this, we remove
        # the duplicate PATH entries conda-build added.
        print('BEFORE: {}'.format(os.environ['PATH']))
        path_list = os.environ['PATH'].split(os.pathsep)
        path_dups = set()
        path_list = [
            p for p in path_list if not p.startswith(sys.prefix)
            or p not in path_dups and not path_dups.add(p)
        ]
        os.environ['PATH'] = os.pathsep.join(path_list)
        print('AFTER: {}'.format(os.environ['PATH']))
    spec_manager = CondaKernelSpecManager()
    for key, value in spec_manager._all_specs().items():
        if key.endswith('-py') or key.endswith('-r'):
            yield check_exec_in_env, key, value['argv']