From 8653e16591f67cf26890596634cd4399d0700e47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20St=C3=B6ckel?= Date: Sun, 2 Jun 2019 14:29:31 -0400 Subject: [PATCH] Add coveralls CI --- .gitignore | 6 +++-- .travis.yml | 5 +++- README.md | 2 +- nengo_bio/builder/connection.py | 9 ++------ .../builder/tests/test_builder_connection.py | 23 +++++++++++++++++++ nengo_bio/connection.py | 1 - 6 files changed, 34 insertions(+), 12 deletions(-) diff --git a/.gitignore b/.gitignore index b7d238b..a9043a4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,8 @@ -build -dist +build/ +dist/ +htmlcov/ examples/*.cfg *.egg-info/* __pycache__ .ipynb_checkpoints +.coverage* diff --git a/.travis.yml b/.travis.yml index eb39530..d4631ac 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,5 +8,8 @@ env: - NENGO_VERSION=master install: - if [ "$NENGO_VERSION" = "master" ]; then git clone https://github.com/nengo/nengo; cd nengo; pip install .; cd -; else pip install nengo==$NENGO_VERSION; fi + - pip install coveralls pytest-cov - pip install . -script: OMP_NUM_THREADS=1 pytest nengo_bio/ +script: OMP_NUM_THREADS=1 pytest --cov neng_bio nengo_bio/ +after_success: + - coveralls diff --git a/README.md b/README.md index 2b33de8..302951d 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -![NengoBio Logo](doc/logo.png) [![PyPI version](https://badge.fury.io/py/nengo-bio.svg)](https://badge.fury.io/py/nengo-bio) +![NengoBio Logo](doc/logo.png) [![PyPI version](https://badge.fury.io/py/nengo-bio.svg)](https://badge.fury.io/py/nengo-bio) [![Build Status](https://travis-ci.org/astoeckel/nengo-bio.svg?branch=master)](https://travis-ci.org/astoeckel/nengo-bio) [![Coverage Status](https://coveralls.io/repos/github/astoeckel/nengo-bio/badge.svg?branch=master)](https://coveralls.io/github/astoeckel/nengo-bio?branch=master) # NengoBio ‒ Biologically (more) plausible Nengo models diff --git a/nengo_bio/builder/connection.py b/nengo_bio/builder/connection.py index fdcb27f..29a4377 100644 --- a/nengo_bio/builder/connection.py +++ b/nengo_bio/builder/connection.py @@ -188,8 +188,8 @@ def get_connectivity(conn, synapse_types, rng=np.random): # We're done if both has_mps_E and has_mps_I are true. Otherwise, select # more neurons up to mps. if not (has_mps_E and has_mps_I): - # If no maximum number of synapses is set, set it to the maximum number - # of synapses that are still available + # If no maximum number of synapses is set, set it to the maximum + # number of synapses that are still available if not has_mps: mps_rem = n_exc + n_inh else: @@ -223,8 +223,6 @@ def remove_bias_current(model, ens): # Delete the copy operator and instead add a reset operator del model.operators[i] model.add_op((nengo.builder.operator.Reset(sig_post_in))) - return True - return False @nengo.builder.Builder.register(SolverWrapper) @@ -256,9 +254,6 @@ def build_solver(model, solver, _, rng, *args, **kwargs): # Transform the target values if hasattr(nengo.connection, 'Dense'): # Nengo 2.8 compat - if not isinstance(conn.transform, nengo.connection.Dense): - raise nengo.exceptions.BuildError( - "Non-compositional solvers only work with Dense transforms") transform = conn.transform.sample(rng=rng) else: transform = conn.transform diff --git a/nengo_bio/builder/tests/test_builder_connection.py b/nengo_bio/builder/tests/test_builder_connection.py index 01a8c3b..d19d8e9 100644 --- a/nengo_bio/builder/tests/test_builder_connection.py +++ b/nengo_bio/builder/tests/test_builder_connection.py @@ -270,3 +270,26 @@ def test_get_connectivity(nengo_ensembles_and_model): assert np.sum(connectivity[0, :101, i]) == 4 assert np.sum(connectivity[1, 101:, i]) == 10 + # ens_a is excitatory, ens_b is inhibitory + with model.toplevel: + conn = Connection((ens_a, ens_b), ens_c, + max_n_post_synapses_exc=4) + synapse_types = get_multi_ensemble_synapse_types(model, conn.pre_obj) + connectivity = get_connectivity(conn, synapse_types) + + for i in range(ens_c.n_neurons): + assert np.sum(connectivity[0, :, i]) == 4 + assert np.sum(connectivity[1, :, i]) == 102 + assert np.sum(connectivity[0, :101, i]) == 4 + assert np.sum(connectivity[1, 101:, i]) == 102 + +def test_connection_invalid_max_synapses(): + with pytest.raises(nengo.exceptions.BuildError) as _: + with nengo.Network() as net: + ens_a = Ensemble(n_neurons=101, dimensions=1) + ens_b = Ensemble(n_neurons=102, dimensions=1) + Connection(ens_a, ens_b, + max_n_post_synapses=10, max_n_post_synapses_exc=10, + max_n_post_synapses_inh=10) + with nengo.Simulator(net) as sim: + pass diff --git a/nengo_bio/connection.py b/nengo_bio/connection.py index 473029c..f1439ba 100644 --- a/nengo_bio/connection.py +++ b/nengo_bio/connection.py @@ -313,7 +313,6 @@ def mkcon(synapse_type, synapse): solver=SolverWrapper( self.solver, i, self, ns, synapse_type), kind=str(synapse_type)) - return conn self.connections.append(( mkcon(Excitatory, synapse_exc), mkcon(Inhibitory, synapse_inh)))