Skip to content

Commit 773ccf9

Browse files
authored
Merge pull request #1562 from SpiNNakerManchester/tspy
Typing of Integration test
2 parents 5ba974e + 4fcfc54 commit 773ccf9

175 files changed

Lines changed: 1553 additions & 1165 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/python_actions.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,6 @@ jobs:
3232
coverage-package: spynnaker
3333
flake8-packages: spynnaker unittests spynnaker_integration_tests proxy_integration_tests
3434
pylint-packages: spynnaker
35-
mypy-packages: spynnaker_integration_tests proxy_integration_tests
36-
mypy-full-packages: spynnaker unittests
35+
mypy-packages: proxy_integration_tests
36+
mypy-full-packages: spynnaker unittests spynnaker_integration_tests
3737
cfg-file: spynnaker

mypy.bash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,4 @@ spalloc="../spalloc/spalloc_client"
2727
fec="../SpiNNFrontEndCommon/spinn_front_end_common"
2828
test_base="../TestBase/spinnaker_testbase"
2929

30-
mypy --python-version 3.8 $utils $machine $man $pacman $spalloc $fec $test_base spynnaker unittests
30+
mypy --python-version 3.8 $utils $machine $man $pacman $spalloc $fec $test_base spynnaker unittests spynnaker_integration_tests

mypyd.bash

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,5 @@ spalloc="../spalloc/spalloc_client"
2727
fec="../SpiNNFrontEndCommon/spinn_front_end_common"
2828
test_base="../TestBase/spinnaker_testbase"
2929

30-
mypy --python-version 3.8 --disallow-untyped-defs $utils $machine $man $pacman $spalloc $fec $test_base spynnaker unittests
30+
mypy --python-version 3.8 --disallow-untyped-defs $utils $machine $man $pacman $spalloc $fec $test_base spynnaker unittests spynnaker_integration_tests
31+

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@ requires = ["setuptools"]
1717
build-backend = "setuptools.build_meta"
1818

1919
[[tool.mypy.overrides]]
20-
module = ["matplotlib", "matplotlib.*", "pyNN.*", "quantities", "neo", "scipy", "scipy.*", "lazyarray"]
20+
module = ["matplotlib", "matplotlib.*", "pyNN.*", "quantities", "neo", "neo.*", "scipy", "scipy.*", "lazyarray"]
2121
ignore_missing_imports = true

spynnaker_integration_tests/conftest.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,16 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
from typing import Iterator
16+
1517
import pytest
18+
from _pytest.fixtures import SubRequest
1619
from spynnaker.pyNN.data.spynnaker_data_view import SpynnakerDataView
1720
import pyNN.spiNNaker as sim
1821

1922

2023
@pytest.fixture(autouse=True)
21-
def check_end_is_called(request):
24+
def check_end_is_called(request: SubRequest) -> Iterator[None]:
2225
""" Fixture for all tests, to make sure end is used!
2326
"""
2427
yield

spynnaker_integration_tests/scripts/checker.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,13 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
from neo import AnalogSignal, SpikeTrain
16+
from spynnaker.pyNN.models.populations import Population
1517

16-
def check_neuron_data(spikes, v, exc, expected_spikes, simtime, label, index):
18+
19+
def check_neuron_data(
20+
spikes: SpikeTrain, v: AnalogSignal, exc: AnalogSignal,
21+
expected_spikes: int, simtime: int, label: str, index: int) -> None:
1722

1823
if len(spikes) != expected_spikes:
1924
raise AssertionError(
@@ -56,7 +61,7 @@ def check_neuron_data(spikes, v, exc, expected_spikes, simtime, label, index):
5661
index, t, t_delta, label, v[t], target_v - 1))
5762

5863

59-
def check_data(pop, expected_spikes, simtime):
64+
def check_data(pop: Population, expected_spikes: int, simtime: int) -> None:
6065
neo = pop.get_data("all")
6166
spikes = neo.segments[0].spiketrains
6267
v = neo.segments[0].filter(name="v")[0]

spynnaker_integration_tests/scripts/pattern_spiker.py

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,15 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14+
15+
from types import ModuleType
16+
from typing import List, Optional
1417
import numpy
1518
import math
16-
from spynnaker.pyNN.models.populations import PopulationView
19+
from neo import AnalogSignal
20+
from neo.core.spiketrainlist import SpikeTrainList
21+
22+
from spynnaker.pyNN.models.populations import (Population, PopulationView)
1723

1824

1925
class PatternSpiker(object):
@@ -29,9 +35,12 @@ class PatternSpiker(object):
2935
-50.73040771484375, -50.450927734375, -50.185089111328125]
3036
V_COUNT = len(V_PATTERN)
3137

32-
def create_population(self, sim, n_neurons, label,
33-
spike_rate=None, spike_rec_indexes=None,
34-
v_rate=None, v_rec_indexes=None):
38+
def create_population(
39+
self, sim: ModuleType, n_neurons: int, label: str,
40+
spike_rate: Optional[int] = None,
41+
spike_rec_indexes: Optional[List[int]] = None,
42+
v_rate: Optional[int] = None,
43+
v_rec_indexes: Optional[List[int]] = None) -> Population:
3544

3645
v_start = self.V_PATTERN * int(math.ceil(n_neurons/self.V_COUNT))
3746
v_start = v_start[:n_neurons]
@@ -51,11 +60,13 @@ def create_population(self, sim, n_neurons, label,
5160
view.record(['v'], sampling_interval=v_rate)
5261
return pop
5362

54-
def check_v(self, v, label, v_rate, v_rec_indexes, is_view, missing):
63+
def check_v(self, v: AnalogSignal, label: str, v_rate: Optional[int],
64+
v_rec_indexes: Optional[List[int]], is_view: bool,
65+
missing: bool) -> None:
5566
if v_rate is None:
5667
v_rate = 1
5768
if v_rec_indexes is None:
58-
v_rec_indexes = range(len(v[0]))
69+
v_rec_indexes = list(range(len(v[0])))
5970
else:
6071
actual_indexes = list(v.annotations["channel_names"])
6172

@@ -85,7 +96,9 @@ def check_v(self, v, label, v_rate, v_rec_indexes, is_view, missing):
8596
self.V_PATTERN[(t + neuron) % self.V_COUNT]))
8697

8798
def check_spikes(
88-
self, spikes, simtime, label, spike_rate, spike_rec_indexes):
99+
self, spikes: SpikeTrainList, simtime: int, label: str,
100+
spike_rate: Optional[int],
101+
spike_rec_indexes: Optional[List[int]]) -> None:
89102
for neuron in range(len(spikes)):
90103
if spike_rec_indexes and neuron not in spike_rec_indexes:
91104
continue
@@ -111,8 +124,13 @@ def check_spikes(
111124
"Found {} but expected {}".format(
112125
neuron, label, spikes[neuron], adjusted_spikes, ))
113126

114-
def check(self, pop, simtime, spike_rate=None, spike_rec_indexes=None,
115-
v_rate=None, v_rec_indexes=None, is_view=False, missing=False):
127+
def check(
128+
self, pop: Population, simtime: int,
129+
spike_rate: Optional[int] = None,
130+
spike_rec_indexes: Optional[List[int]] = None,
131+
v_rate: Optional[int] = None,
132+
v_rec_indexes: Optional[List[int]] = None, is_view: bool = False,
133+
missing: bool = False) -> None:
116134
if is_view:
117135
neo = pop.get_data("spikes")
118136
spikes = neo.segments[0].spiketrains

spynnaker_integration_tests/scripts/synfire_npop_run.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,13 @@
1818
Synfirechain-like example
1919
"""
2020
import numpy
21+
from numpy.typing import NDArray
2122
import pyNN.spiNNaker as p
2223
from spinnaker_testbase.root_test_case import RootTestCase
2324

2425

25-
def do_synfire_npop(nNeurons, n_pops, neurons_per_core, runtime=25000):
26+
def do_synfire_npop(nNeurons: int, n_pops: int, neurons_per_core: int,
27+
runtime: int = 25000) -> NDArray[numpy.floating]:
2628
"""
2729
Runs the script Does the run based on the parameters
2830

0 commit comments

Comments
 (0)