From 6f16803c42d7f63365d073fb3a89a023c96a9cb7 Mon Sep 17 00:00:00 2001 From: jchen6727 Date: Sat, 11 May 2024 01:16:35 -0500 Subject: [PATCH] fixed bug in conn, updated test/examples/* to use dynamic pathing (#817) * fixed bug in conn, updated test/examples/* to use dynamic pathing * update CHANGES.md --- CHANGES.md | 2 ++ netpyne/network/conn.py | 2 +- tests/examples/test_HHTut.py | 5 +++-- tests/examples/test_HybridTut.py | 6 ++++-- tests/examples/test_LFPrecording.py | 6 +++--- tests/examples/test_M1.py | 6 +++--- tests/examples/test_NeuroMLImport.py | 6 +++--- tests/examples/test_PTcell.py | 6 +++--- tests/examples/test_batchCell.py | 6 +++--- tests/examples/test_evolCell.py | 6 +++--- tests/examples/test_rxd_buffering.py | 5 +++-- tests/examples/test_rxd_net.py | 6 +++--- tests/examples/test_saving.py | 6 +++--- tests/examples/utils.py | 4 +++- 14 files changed, 40 insertions(+), 32 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 6881d80f9..7c4219c2f 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -6,6 +6,8 @@ - cfg.connRandomSecFromList and cfg.distributeSynsUniformly can now be overriden in individual conn rule +- Updated tests.examples.utils to allow for dynamic pathing + **Bug fixes** - Better handling of exceptions in `importCellParams()` (incl. issue 782) diff --git a/netpyne/network/conn.py b/netpyne/network/conn.py index 6e006765e..079631e07 100644 --- a/netpyne/network/conn.py +++ b/netpyne/network/conn.py @@ -511,7 +511,7 @@ def probConn(self, preCellsTags, postCellsTags, connParam): if sim.cfg.verbose: print('Generating set of probabilistic connections (rule: %s) ...' % (connParam['label'])) if sim.rank == 0 and not sim.cfg.verbose: pbar = tqdm(total=len(postCellsTags.items()), ascii=True, - desc=' ' + connParam['label'], position=0, leave=True, + desc=' ' + str(connParam['label']), position=0, leave=True, bar_format= '{l_bar}{bar}| Creating synaptic connections for {n_fmt}/{total_fmt} postsynaptic cells on node %i (probabilistic connectivity)' % sim.rank) allRands = self.generateRandsPrePost(preCellsTags, postCellsTags) diff --git a/tests/examples/test_HHTut.py b/tests/examples/test_HHTut.py index c2abbe325..253ba73dc 100644 --- a/tests/examples/test_HHTut.py +++ b/tests/examples/test_HHTut.py @@ -4,9 +4,10 @@ if '-nogui' not in sys.argv: sys.argv.append('-nogui') -from .utils import pkg_setup +from .utils import pkg_setup, NETPYNE_DIR -@pytest.mark.package_data(['examples/HHTut/', None]) +package_dir = NETPYNE_DIR + '/examples/HHTut/' +@pytest.mark.package_data([package_dir, None]) class TestHHTut(): def test_run(self, pkg_setup): import src.init diff --git a/tests/examples/test_HybridTut.py b/tests/examples/test_HybridTut.py index 9fc96136e..1490cea87 100644 --- a/tests/examples/test_HybridTut.py +++ b/tests/examples/test_HybridTut.py @@ -5,9 +5,11 @@ if '-nogui' not in sys.argv: sys.argv.append('-nogui') -from .utils import pkg_setup +from .utils import pkg_setup, NETPYNE_DIR -@pytest.mark.package_data(['examples/HybridTut/', 'mod']) +package_dir = NETPYNE_DIR + '/examples/HybridTut/' + +@pytest.mark.package_data([package_dir, 'mod']) class TestHybridTut: def test_run(self, pkg_setup): import src.init diff --git a/tests/examples/test_LFPrecording.py b/tests/examples/test_LFPrecording.py index 3ec68b134..42e235d0f 100644 --- a/tests/examples/test_LFPrecording.py +++ b/tests/examples/test_LFPrecording.py @@ -5,10 +5,10 @@ if '-nogui' not in sys.argv: sys.argv.append('-nogui') -from .utils import pkg_setup +from .utils import pkg_setup, NETPYNE_DIR - -@pytest.mark.package_data(['examples/LFPrecording/', 'mod']) +package_dir = NETPYNE_DIR + '/examples/LFPrecording/' +@pytest.mark.package_data([package_dir, 'mod']) class TestLFPrecording: def test_cell_lfp(self, pkg_setup): import src.cell.init diff --git a/tests/examples/test_M1.py b/tests/examples/test_M1.py index 6af398481..981df1f3a 100644 --- a/tests/examples/test_M1.py +++ b/tests/examples/test_M1.py @@ -5,10 +5,10 @@ if '-nogui' not in sys.argv: sys.argv.append('-nogui') -from .utils import pkg_setup +from .utils import pkg_setup, NETPYNE_DIR - -@pytest.mark.package_data(['examples/M1/', 'mod']) +package_dir = NETPYNE_DIR + '/examples/M1/' +@pytest.mark.package_data([package_dir, 'mod']) class TestM1: def test_run(self, pkg_setup): import src.init diff --git a/tests/examples/test_NeuroMLImport.py b/tests/examples/test_NeuroMLImport.py index fe540b4c6..361fb864f 100644 --- a/tests/examples/test_NeuroMLImport.py +++ b/tests/examples/test_NeuroMLImport.py @@ -5,10 +5,10 @@ if '-nogui' not in sys.argv: sys.argv.append('-nogui') -from .utils import pkg_setup +from .utils import pkg_setup, NETPYNE_DIR - -@pytest.mark.package_data(['examples/NeuroMLImport/', '.']) +package_dir = NETPYNE_DIR + '/examples/NeuroMLImport/' +@pytest.mark.package_data([package_dir, '.']) class TestPTcell: def test_init(self, pkg_setup): import SimpleNet_import diff --git a/tests/examples/test_PTcell.py b/tests/examples/test_PTcell.py index a7599f9e0..0e3b5a793 100644 --- a/tests/examples/test_PTcell.py +++ b/tests/examples/test_PTcell.py @@ -5,10 +5,10 @@ if '-nogui' not in sys.argv: sys.argv.append('-nogui') -from .utils import pkg_setup +from .utils import pkg_setup, NETPYNE_DIR - -@pytest.mark.package_data(['examples/PTcell/', 'mod']) +package_dir = NETPYNE_DIR + '/examples/PTcell/' +@pytest.mark.package_data([package_dir, 'mod']) class TestPTcell: def test_init(self, pkg_setup): import src.init diff --git a/tests/examples/test_batchCell.py b/tests/examples/test_batchCell.py index 9ce282143..ac2898e21 100644 --- a/tests/examples/test_batchCell.py +++ b/tests/examples/test_batchCell.py @@ -8,10 +8,10 @@ if "-nogui" not in sys.argv: sys.argv.append("-nogui") -from .utils import pkg_setup +from .utils import pkg_setup, NETPYNE_DIR - -@pytest.mark.package_data(["examples/batchCell/", "mod"]) +package_dir = NETPYNE_DIR + "/examples/batchCell/" +@pytest.mark.package_data([package_dir, "mod"]) class TestBatchCell: def batch_run(self, pkg_setup): """run a reduced version of the batchCell example""" diff --git a/tests/examples/test_evolCell.py b/tests/examples/test_evolCell.py index cf82f05b6..8c171bf35 100644 --- a/tests/examples/test_evolCell.py +++ b/tests/examples/test_evolCell.py @@ -9,10 +9,10 @@ if "-nogui" not in sys.argv: sys.argv.append("-nogui") -from .utils import pkg_setup +from .utils import pkg_setup, NETPYNE_DIR - -@pytest.mark.package_data(["examples/evolCell/", "mod"]) +package_dir = NETPYNE_DIR + "/examples/evolCell/" +@pytest.mark.package_data([package_dir, "mod"]) class TestEvolCell: def evol_run(self, pkg_setup): """run a reduced version of the evolCell example""" diff --git a/tests/examples/test_rxd_buffering.py b/tests/examples/test_rxd_buffering.py index ce6bb14d7..dab5ab15d 100644 --- a/tests/examples/test_rxd_buffering.py +++ b/tests/examples/test_rxd_buffering.py @@ -3,9 +3,10 @@ if '-nogui' not in sys.argv: sys.argv.append('-nogui') -from .utils import pkg_setup +from .utils import pkg_setup, NETPYNE_DIR -@pytest.mark.package_data(['examples/rxd_buffering/', None]) +package_dir = NETPYNE_DIR + '/examples/rxd_buffering/' +@pytest.mark.package_data([package_dir, None]) class Test_rxd_buffering(): def test_buffering(self, pkg_setup): import src.init diff --git a/tests/examples/test_rxd_net.py b/tests/examples/test_rxd_net.py index 4da23a73a..0e7a9b23b 100644 --- a/tests/examples/test_rxd_net.py +++ b/tests/examples/test_rxd_net.py @@ -5,10 +5,10 @@ if '-nogui' not in sys.argv: sys.argv.append('-nogui') -from .utils import pkg_setup +from .utils import pkg_setup, NETPYNE_DIR - -@pytest.mark.package_data(['examples/rxd_net/', 'mod']) +package_dir = NETPYNE_DIR + '/examples/rxd_net/' +@pytest.mark.package_data([package_dir, 'mod']) class TestRxdNet: def test_init(self, pkg_setup): import src.init diff --git a/tests/examples/test_saving.py b/tests/examples/test_saving.py index 451d29b71..0e3b838aa 100644 --- a/tests/examples/test_saving.py +++ b/tests/examples/test_saving.py @@ -5,10 +5,10 @@ sys.argv.append('-nogui') -from .utils import pkg_setup +from .utils import pkg_setup, NETPYNE_DIR - -@pytest.mark.package_data(['examples/saving', None]) +package_dir = NETPYNE_DIR + '/examples/saving/' +@pytest.mark.package_data([package_dir, None]) class Test_saving(): def test_init(self, pkg_setup): import src.init diff --git a/tests/examples/utils.py b/tests/examples/utils.py index 81d3ab0d3..4180a4d99 100644 --- a/tests/examples/utils.py +++ b/tests/examples/utils.py @@ -1,7 +1,10 @@ import os import pytest import sys +import inspect +import netpyne +NETPYNE_DIR = '/' + os.path.join(*inspect.getfile(netpyne).split('/')[:-2]) def compile_neuron_mod_dir(pkg_dir): try: print('Compiling {}'.format(pkg_dir)) @@ -14,7 +17,6 @@ def compile_neuron_mod_dir(pkg_dir): print(err) return - @pytest.fixture def pkg_setup(request): mark = request.node.get_closest_marker("package_data")