Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EBR-43: resolve sonar warnings #70

Merged
merged 3 commits into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions dev/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
FROM continuumio/miniconda3
FROM continuumio/miniconda3:master

ARG TVB_USER=tvb_user
ARG USER_HOME=/home/$TVB_USER
ARG JUPYTER_CONFIG=$USER_HOME/.jupyter

RUN useradd -ms /bin/bash $TVB_USER
RUN useradd -ms /bin/bash "$TVB_USER"
WORKDIR $USER_HOME

USER root
Expand Down
2 changes: 1 addition & 1 deletion dev/notebook_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def execute_notebook(in_path, notebook):
if not os.getenv('CLB_AUTH'):
os.environ['CLB_AUTH'] = 'abc'

notebooks = [file for file in os.listdir(in_path) if file[-6:] == ".ipynb"]
notebooks = [file for file in os.listdir(in_path) if file.endswith(".ipynb")]

# start as many threads as logical cpus
with ThreadPool(cpu_count()) as pool:
Expand Down
2 changes: 1 addition & 1 deletion tvbwidgets/tests/test_drive_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def mockk(token):
assert len(widget.files_list.options) == 1

with pytest.raises(AttributeError):
assert widget.get_selected_file_content()
widget.get_selected_file_content()


def test_storage_widget(mocker):
Expand Down
10 changes: 6 additions & 4 deletions tvbwidgets/tests/ts/test_data_wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# (c) 2022-2023, TVB Widgets Team
#

import math
import numpy as np
import pytest

Expand All @@ -17,7 +18,8 @@
@pytest.fixture
def wrapper_np():
""" Returns an initialized Numpy wrapper with 3 dimensions """
numpy_array = np.random.rand(30000, 4, 50)
rng = np.random.default_rng()

Check notice

Code scanning / SonarCloud

Results that depend on random number generation should be reproducible Low test

Provide a seed for this random generator. See more on SonarCloud
numpy_array = rng.random(size=(30000, 4, 50))
wrapper_np = WrapperNumpy(numpy_array, 0.01, ch_idx=2)
return wrapper_np

Expand All @@ -37,7 +39,7 @@


def test_get_sample_rate_np(wrapper_np):
assert wrapper_np.get_ts_sample_rate() == 0.01
assert math.isclose(wrapper_np.get_ts_sample_rate(), 0.01)


def test_build_raw_np(wrapper_np):
Expand Down Expand Up @@ -92,7 +94,7 @@
assert len(ch_names) == len(ch_order) == len(ch_type) == 76

assert wrapper_tvb.displayed_time_points == 3000
assert wrapper_tvb.get_ts_period() == 0.75
assert math.isclose(wrapper_tvb.get_ts_period(), 0.75)
assert wrapper_tvb.get_ts_sample_rate() == 4000

raw = wrapper_tvb.build_raw()
Expand Down Expand Up @@ -120,7 +122,7 @@

def test_get_ts_period_tvb(wrapper_tvb):
ts_period = wrapper_tvb.get_ts_period()
assert ts_period == 0.75
assert math.isclose(ts_period, 0.75)


def test_get_ts_sample_rate_tvb(wrapper_tvb):
Expand Down
8 changes: 5 additions & 3 deletions tvbwidgets/tests/ts/test_mne_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# (c) 2022-2023, TVB Widgets Team
#

import math
import numpy as np
import pytest
import logging
Expand Down Expand Up @@ -43,7 +44,7 @@
# =========================================== WIDGET CREATION ==========================================================
def test_get_widget(tsw_tvb_data):
tsw_tvb_data.get_widget()
assert type(tsw_tvb_data) == TimeSeriesWidgetMNE
assert isinstance(tsw_tvb_data, TimeSeriesWidgetMNE)


def test_create_ts_widget(tsw):
Expand All @@ -67,7 +68,7 @@

assert tsw.data == wrapper_tvb
assert tsw.sample_freq == 4000
assert tsw.displayed_period == 0.75
assert math.isclose(tsw.displayed_period, 0.75)
assert len(tsw.ch_names) == len(tsw.ch_order) == len(tsw.ch_types) == 76
assert tsw.raw.get_data().shape == (76, 4000)

Expand Down Expand Up @@ -104,7 +105,8 @@

def test_dimensions_selection_update(tsw_tvb_data):
# simulate unchecking of some checkboxes
false_cb_idx = list(np.random.choice(76, size=3, replace=False))
rng = np.random.default_rng()

Check notice

Code scanning / SonarCloud

Results that depend on random number generation should be reproducible Low test

Provide a seed for this random generator. See more on SonarCloud
false_cb_idx = list(rng.choice(76, size=3, replace=False))
false_cb_names = [f'sig {x}' for x in false_cb_idx]
for cb_name in false_cb_names:
tsw_tvb_data.checkboxes[cb_name].value = False
Expand Down
5 changes: 3 additions & 2 deletions tvbwidgets/tests/ts/test_plotly_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# (c) 2022-2023, TVB Widgets Team
#

import math
import pytest

import ipywidgets as widgets
Expand Down Expand Up @@ -44,7 +45,7 @@ def tsw_tvb_data(tsr_4d):
# =========================================== WIDGET CREATION ==========================================================
def test_get_widget(tsw_tvb_data):
tsw_tvb_data.get_widget()
assert type(tsw_tvb_data) == TimeSeriesWidgetPlotly
assert isinstance(tsw_tvb_data, TimeSeriesWidgetPlotly)


def test_create_ts_widget(tsw):
Expand All @@ -64,7 +65,7 @@ def test_populate_from_data_wrapper_tvb(tsw, wrapper_tvb):

assert tsw.data == wrapper_tvb
assert tsw.sample_freq == 4000
assert tsw.displayed_period == 0.75
assert math.isclose(tsw.displayed_period, 0.75)
assert len(tsw.ch_names) == 76
assert tsw.raw.get_data().shape == (76, 4000)

Expand Down
7 changes: 4 additions & 3 deletions tvbwidgets/tests/ts/ts_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,9 @@

def _generate_connectivity(no_of_regions):
labels = np.array(['sig ' + str(i) for i in range(no_of_regions)])
conn = connectivity.Connectivity(centres=np.random.rand(no_of_regions, 3),
rng = np.random.default_rng()

Check notice

Code scanning / SonarCloud

Results that depend on random number generation should be reproducible Low test

Provide a seed for this random generator. See more on SonarCloud
conn = connectivity.Connectivity(centres=rng.random(size=(no_of_regions, 3)),
region_labels=labels,
weights=np.random.rand(no_of_regions, no_of_regions),
tract_lengths=np.random.rand(no_of_regions, no_of_regions))
weights=rng.random(size=(no_of_regions, no_of_regions)),
tract_lengths=rng.random(size=(no_of_regions, no_of_regions)))
return conn
4 changes: 2 additions & 2 deletions tvbwidgets/ui/connectivity_ipy/operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,13 +150,13 @@ def __cut_nodes(self, selected=True):
Create a new connectivity using only the selected nodes
"""
regions = CONTEXT.connectivity.region_labels
selected_regions = [numpy.where(regions == label)[0][0] for label in self.selected_regions]
selected_regions = [numpy.nonzero(regions == label)[0][0] for label in self.selected_regions]
new_conn = self.__cut_connectivity_nodes(selected_regions, selected)
CONTEXT.connectivity = new_conn

def __cut_edges(self, selected=False):
regions = CONTEXT.connectivity.region_labels
selected_regions = numpy.array([numpy.where(regions == label)[0][0] for label in self.selected_regions])
selected_regions = numpy.array([numpy.nonzero(regions == label)[0][0] for label in self.selected_regions])
new_conn = self.__cut_connectivity_edges(selected_regions, selected)
CONTEXT.connectivity = new_conn

Expand Down
Loading