From 27b71bf3dea58830e8fc538dd4c65a155198e4ae Mon Sep 17 00:00:00 2001 From: Marc Wouts Date: Sun, 27 Sep 2020 19:34:44 +0200 Subject: [PATCH] Test that the contents manager can load the global configuration file when no local configuration file is found --- jupytext/contentsmanager.py | 13 +++++++------ tests/test_cm_config.py | 23 +++++++++++++++++++++++ 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/jupytext/contentsmanager.py b/jupytext/contentsmanager.py index 165cc5a42..d3d111817 100644 --- a/jupytext/contentsmanager.py +++ b/jupytext/contentsmanager.py @@ -437,20 +437,21 @@ def get_config_file(self, directory): return path if not directory: - return find_global_jupytext_configuration_file() + return None parent_dir = self.get_parent_dir(directory) return self.get_config_file(parent_dir) - def load_config_file(self, config_file): + def load_config_file(self, config_file, is_os_path=False): """Load the configuration file""" if config_file is None: return None self.log.info("Loading Jupytext configuration file at %s", config_file) - if config_file.endswith(".py"): - config_dict = load_jupytext_configuration_file( - self._get_os_path(config_file) - ) + if config_file.endswith(".py") and not is_os_path: + config_file = self._get_os_path(config_file) + is_os_path = True + if is_os_path: + config_dict = load_jupytext_configuration_file(config_file) else: model = self.super.get(config_file, content=True, type="file") config_dict = load_jupytext_configuration_file( diff --git a/tests/test_cm_config.py b/tests/test_cm_config.py index 06a0c2007..2716b511c 100644 --- a/tests/test_cm_config.py +++ b/tests/test_cm_config.py @@ -100,3 +100,26 @@ def test_incorrect_config_message(tmpdir, cfg_file, cfg_text): with pytest.raises(HTTPError, match=expected_message): cm.save(dict(type="notebook", content=SAMPLE_NOTEBOOK), "notebook.ipynb") + + +def test_global_config_file(tmpdir): + cm_dir = tmpdir.join("cm_dir").mkdir() + cm = jupytext.TextFileContentsManager() + cm.root_dir = str(cm_dir) + + tmpdir.join("jupytext.toml").write('default_jupytext_formats = "ipynb,Rmd"') + + def fake_global_config_directory(): + return [str(tmpdir)] + + with mock.patch( + "jupytext.config.global_jupytext_configuration_directories", + fake_global_config_directory, + ): + nb = new_notebook(cells=[new_code_cell("1+1")]) + model = dict(content=nb, type="notebook") + cm.save(model, "notebook.ipynb") + assert set(model["path"] for model in cm.get("/", content=True)["content"]) == { + "notebook.ipynb", + "notebook.Rmd", + }