Skip to content

Commit

Permalink
Add some basic linting to tests (#260)
Browse files Browse the repository at this point in the history
  • Loading branch information
joni-herttuainen authored Feb 23, 2024
1 parent 4a64964 commit 16986bf
Show file tree
Hide file tree
Showing 14 changed files with 23 additions and 32 deletions.
10 changes: 10 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,13 @@ extension-pkg-whitelist = [
ignored-modules = [
'numpy',
]

[tool.pylint.tests]
disable = [
'all',
]
enable = [
'unused-import',
'unused-variable',
'unused-argument',
]
3 changes: 0 additions & 3 deletions tests/test__plotting.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import sys
from unittest.mock import Mock, patch

import numpy as np
import pandas as pd
import pytest

import bluepysnap._plotting as test_module
from bluepysnap.exceptions import BluepySnapError
from bluepysnap.simulation import Simulation
from bluepysnap.spike_report import FilteredSpikeReport, SpikeReport

from utils import TEST_DATA_DIR

Expand Down
2 changes: 1 addition & 1 deletion tests/test_circuit_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import pytest

import bluepysnap.circuit_validation as test_module
from bluepysnap.exceptions import BluepySnapError, BluepySnapValidationError
from bluepysnap.exceptions import BluepySnapValidationError

from utils import TEST_DATA_DIR, copy_test_data, edit_config

Expand Down
3 changes: 0 additions & 3 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import warnings
from unittest.mock import Mock, patch

import click
import pytest
from click.testing import CliRunner

from bluepysnap.cli import cli
from bluepysnap.exceptions import BluepySnapDeprecationWarning

from utils import TEST_DATA_DIR

Expand Down
2 changes: 0 additions & 2 deletions tests/test_edges.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import pickle
from unittest.mock import PropertyMock, patch

import numpy as np
import numpy.testing as npt
import pandas as pd
import pandas.testing as pdt
import pytest
from numpy import dtype

import bluepysnap.edges as test_module
from bluepysnap.bbp import Synapse
Expand Down
8 changes: 3 additions & 5 deletions tests/test_neuron_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
from bluepysnap.exceptions import BluepySnapError
from bluepysnap.sonata_constants import Node

from utils import TEST_DATA_DIR, copy_config, copy_test_data, create_node_population, edit_config
from utils import TEST_DATA_DIR, copy_test_data, create_node_population, edit_config


def test_invalid_model_type():
"""test that model type, other than 'biophysical' throws an error"""
with copy_test_data() as (circuit_copy_path, config_copy_path):
with copy_test_data() as (_, config_copy_path):
config = CircuitConfig.from_config(config_copy_path).to_dict()
nodes_file = config["networks"]["nodes"][0]["nodes_file"]
with h5py.File(nodes_file, "r+") as h5f:
Expand All @@ -35,7 +35,6 @@ def test_invalid_model_type():

def test_get_invalid_node_id():
nodes = create_node_population(str(TEST_DATA_DIR / "nodes.h5"), "default")
config = CircuitConfig.from_config(TEST_DATA_DIR / "circuit_config.json").to_dict()
test_obj = test_module.NeuronModelsHelper(nodes._properties, nodes)

with pytest.raises(BluepySnapError) as e:
Expand All @@ -45,7 +44,6 @@ def test_get_invalid_node_id():

def test_get_filepath_biophysical():
nodes = create_node_population(str(TEST_DATA_DIR / "nodes.h5"), "default")
config = CircuitConfig.from_config(TEST_DATA_DIR / "circuit_config.json").to_dict()
test_obj = test_module.NeuronModelsHelper(nodes._properties, nodes)

node_id = 0
Expand Down Expand Up @@ -91,7 +89,7 @@ def test_absolute_biophysical_dir():


def test_no_biophysical_dir():
with copy_test_data() as (data_dir, circuit_config):
with copy_test_data() as (_, circuit_config):
with edit_config(circuit_config) as config:
del config["components"]["biophysical_neuron_models_dir"]

Expand Down
1 change: 0 additions & 1 deletion tests/test_node_population.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import sys
from unittest import mock

import libsonata
import numpy as np
import numpy.testing as npt
import pandas as pd
Expand Down
1 change: 0 additions & 1 deletion tests/test_node_sets.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import json
import re
from unittest.mock import patch

import libsonata
import pytest
Expand Down
2 changes: 0 additions & 2 deletions tests/test_nodes.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import pickle
from unittest.mock import PropertyMock, patch

import numpy as np
import numpy.testing as npt
import pandas as pd
import pandas.testing as pdt
import pytest
from numpy import dtype

import bluepysnap.nodes as test_module
from bluepysnap.circuit import Circuit
Expand Down
14 changes: 6 additions & 8 deletions tests/test_schemas.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import re
from collections.abc import Iterable
from pathlib import Path

import h5py
import numpy as np
Expand Down Expand Up @@ -248,7 +246,7 @@ def test_validate_edges_ok():
),
)
def test_validate_nodes_biophysical_missing_required(missing):
with copy_test_data() as (circuit_copy_path, config_copy_path):
with copy_test_data() as (circuit_copy_path, _):
nodes_file = circuit_copy_path / "nodes_single_pop.h5"
with h5py.File(nodes_file, "r+") as h5f:
del h5f[missing]
Expand Down Expand Up @@ -299,7 +297,7 @@ def test_validate_nodes_biophysical_missing_required(missing):
),
)
def test_validate_edges_chemical_missing_required(missing):
with copy_test_data() as (circuit_copy_path, config_copy_path):
with copy_test_data() as (circuit_copy_path, _):
edges_file = circuit_copy_path / "edges_single_pop.h5"
with h5py.File(edges_file, "r+") as h5f:
del h5f[missing]
Expand Down Expand Up @@ -394,7 +392,7 @@ def test_virtual_node_population_error():

def test_validate_edges_missing_attributes_field():
# has no attributes at all
with copy_test_data() as (circuit_copy_path, config_copy_path):
with copy_test_data() as (circuit_copy_path, _):
edges_file = circuit_copy_path / "edges_single_pop.h5"
with h5py.File(edges_file, "r+") as h5f:
del h5f["edges/default/source_node_id"].attrs["node_population"]
Expand All @@ -405,7 +403,7 @@ def test_validate_edges_missing_attributes_field():

def test_validate_edges_missing_attribute():
# has attributes but not the required ones
with copy_test_data() as (circuit_copy_path, config_copy_path):
with copy_test_data() as (circuit_copy_path, _):
edges_file = circuit_copy_path / "edges_single_pop.h5"
with h5py.File(edges_file, "r+") as h5f:
del h5f["edges/default/source_node_id"].attrs["node_population"]
Expand All @@ -425,7 +423,7 @@ def test_validate_edges_missing_attribute():
),
)
def test_wrong_datatype(field):
with copy_test_data() as (circuit_copy_path, config_copy_path):
with copy_test_data() as (circuit_copy_path, _):
edges_file = circuit_copy_path / "edges_single_pop.h5"
with h5py.File(edges_file, "r+") as h5f:
del h5f[field]
Expand All @@ -444,7 +442,7 @@ def test__get_reference_resolver():


def test_nodes_schema_types():
property_types, dynamics_params = test_module.nodes_schema_types("biophysical")
property_types, _ = test_module.nodes_schema_types("biophysical")
assert "x" in property_types
assert property_types["x"] == np.float32

Expand Down
1 change: 0 additions & 1 deletion tests/test_simulation_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,6 @@ def test_validate_reports(tmp_path):
fail_1_file = tmp_path / "non_existent.h5"
fail_2_file = tmp_path / "fail_2.h5"

report = {"cells": "fake_node_set"}
config = {
"_node_sets_instance": node_sets,
"_output_dir": tmp_path,
Expand Down
4 changes: 2 additions & 2 deletions tests/test_spike_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,14 +269,14 @@ def test_get2(self):
@patch(
test_module.__name__ + ".PopulationSpikeReport.resolve_nodes", return_value=np.asarray([4])
)
def test_get_not_in_report(self, mock):
def test_get_not_in_report(self, _):
pdt.assert_series_equal(self.test_obj.get(4), _create_series([], []))

@patch(
test_module.__name__ + ".PopulationSpikeReport.resolve_nodes",
return_value=np.asarray([0, 4]),
)
def test_get_not_in_report(self, mock):
def test_get_not_in_report(self, _):
pdt.assert_series_equal(self.test_obj.get([0, 4]), _create_series([0, 0], [0.2, 1.3]))

def test_node_ids(self):
Expand Down
2 changes: 0 additions & 2 deletions tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
from distutils.dir_util import copy_tree
from pathlib import Path

import libsonata
import numpy.testing as npt
import pytest

from bluepysnap.circuit import Circuit
from bluepysnap.nodes import NodePopulation, Nodes
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ commands =
isort --check {[base]name} tests setup.py doc/source/conf.py
pycodestyle {[base]name}
pydocstyle {[base]name}
pylint -j4 {[base]name}
pylint -j4 {[base]name} tests

[testenv:format]
deps =
Expand Down

0 comments on commit 16986bf

Please sign in to comment.