Beispiel #1
0
    def test_yarn_config(self):
        with patch("subprocess.check_output") as check_output:
            yarn_registry = "https://private.yarn/manager"
            check_output.return_value = b"\n".join([
                b'{"type":"info","data":"yarn config"}',
                b'{"type":"inspect","data":{"registry":"' +
                bytes(yarn_registry, "utf-8") + b'"}}',
                b'{"type":"info","data":"npm config"}',
                b'{"type":"inspect","data":{"registry":"' +
                bytes(yarn_registry, "utf-8") + b'"}}',
            ])
            logger = logging.getLogger("jupyterlab")
            config = commands._yarn_config(logger)

            self.assertDictEqual(
                config,
                {
                    "yarn config": {
                        "registry": yarn_registry
                    },
                    "npm config": {
                        "registry": yarn_registry
                    },
                },
            )
Beispiel #2
0
    def test_yarn_config_failure(self):
        with patch("subprocess.check_output") as check_output:
            check_output.side_effect = subprocess.CalledProcessError(
                1, ['yarn', 'config', 'list'], stderr=b"yarn config failed.")

            logger = logging.getLogger('jupyterlab')
            config = commands._yarn_config(logger)

            self.assertDictEqual(config, {"yarn config": {}, "npm config": {}})
Beispiel #3
0
    def test_node_not_available(self):
        # patch should be applied on `jupyterlab.commands` and not on `jupyterlab_server.process`
        # See https://docs.python.org/3/library/unittest.mock.html#where-to-patch
        with patch("jupyterlab.commands.which") as which:
            which.side_effect = ValueError("Command not found")

            logger = logging.getLogger("jupyterlab")
            config = commands._yarn_config(logger)

            which.assert_called_once_with("node")
            self.assertDictEqual(config, {"yarn config": {}, "npm config": {}})