From 3951021659bb9e5cd945b082abaffc64c533dc48 Mon Sep 17 00:00:00 2001 From: Anil Tuncel Date: Wed, 14 Feb 2024 22:51:33 +0100 Subject: [PATCH 1/2] reloading neuron mechanisms in _load_hoc_and_mod_files --- bluecellulab/importer.py | 1 + tests/test_import_directory.py | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 tests/test_import_directory.py diff --git a/bluecellulab/importer.py b/bluecellulab/importer.py index 2f76a61c..ba24d5ff 100644 --- a/bluecellulab/importer.py +++ b/bluecellulab/importer.py @@ -75,6 +75,7 @@ def print_header(neuron: ModuleType, mod_lib_path: str) -> None: @run_once def _load_hoc_and_mod_files() -> None: """Import hoc and mod files.""" + neuron.load_mechanisms(".") logger.info("Loading the mod files.") mod_lib_paths = import_mod_lib(neuron) logger.info("Loading the hoc files.") diff --git a/tests/test_import_directory.py b/tests/test_import_directory.py new file mode 100644 index 00000000..c1fa96c8 --- /dev/null +++ b/tests/test_import_directory.py @@ -0,0 +1,21 @@ +"""This test file is to ensure mechanisms are loaded where Cell is created.""" +import os +from pathlib import Path + + +os.chdir("tests") + + +# intentionally imported in the directory without compiled mechanisms +from bluecellulab import Cell # noqa: E402 + + +examples_dir = Path(__file__).resolve().parent / "examples" + + +def test_import_vs_first_call_neuron_mechanisms_dir(): + """Test if the neuron import directory is set at import or at the first call.""" + os.chdir("..") # mechanisms at .. should be loaded + hoc_path = examples_dir / "bpo_cell" / "0_cADpyr_L5TPC_a6e707a_1_sNone.hoc" + morph_path = examples_dir / "bpo_cell" / "C060114A5.asc" + _ = Cell(hoc_path, morph_path, template_format="bluepyopt") From ae1fc1544efcba140f7b510af609156a72a74501 Mon Sep 17 00:00:00 2001 From: Anil Tuncel Date: Thu, 15 Feb 2024 16:41:53 +0100 Subject: [PATCH 2/2] move imports inside test_import_vs_first_call_neuron_mechanisms_dir --- tests/test_import_directory.py | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/tests/test_import_directory.py b/tests/test_import_directory.py index c1fa96c8..ad034a7b 100644 --- a/tests/test_import_directory.py +++ b/tests/test_import_directory.py @@ -3,18 +3,15 @@ from pathlib import Path -os.chdir("tests") - - -# intentionally imported in the directory without compiled mechanisms -from bluecellulab import Cell # noqa: E402 - +def test_import_vs_first_call_neuron_mechanisms_dir(): + """Test if the neuron import directory is set at import or at the first call.""" + os.chdir("tests") # there are no mechanisms here -examples_dir = Path(__file__).resolve().parent / "examples" + # intentionally imported in the directory without compiled mechanisms + from bluecellulab import Cell # noqa: E402 + examples_dir = Path(__file__).resolve().parent / "examples" -def test_import_vs_first_call_neuron_mechanisms_dir(): - """Test if the neuron import directory is set at import or at the first call.""" os.chdir("..") # mechanisms at .. should be loaded hoc_path = examples_dir / "bpo_cell" / "0_cADpyr_L5TPC_a6e707a_1_sNone.hoc" morph_path = examples_dir / "bpo_cell" / "C060114A5.asc"