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

[CLN] - Clean up documentation within test code #241

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion neurodsp/tests/aperiodic/test_autocorr.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Tests for autocorrelation measures."""
"""Tests for neurodsp.aperiodic.autocorr."""

from neurodsp.aperiodic.autocorr import *

Expand Down
5 changes: 3 additions & 2 deletions neurodsp/tests/aperiodic/test_dfa.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
"""Tests for fractal analysis using fluctuation measures."""
"""Tests neurodsp.aperiodic.dfa."""

from pytest import raises

import numpy as np

from neurodsp.sim import sim_powerlaw

from neurodsp.tests.settings import FS, FS_HIGH

from neurodsp.aperiodic.dfa import (compute_fluctuations, compute_rescaled_range,
Expand All @@ -18,7 +19,7 @@ def test_compute_fluctuations(tsig):
t_scales, flucs, exp = compute_fluctuations(tsig, 500)
assert len(t_scales) == len(flucs)

# Check error for if the settings create window lengths that are too short
# Check error if the settings create window lengths that are too short
with raises(ValueError):
t_scales, flucs, exp = compute_fluctuations(tsig, 100)

Expand Down
7 changes: 3 additions & 4 deletions neurodsp/tests/aperiodic/test_irasa.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
"""Tests for IRASA functions."""
"""Tests for neurodsp.aperiodic.irasa."""

import numpy as np

from neurodsp.tests.settings import FS, N_SECONDS_LONG, EXP1

from neurodsp.sim import sim_combined
from neurodsp.spectral import compute_spectrum, trim_spectrum

from neurodsp.tests.settings import FS, N_SECONDS_LONG, EXP1

from neurodsp.aperiodic.irasa import *

###################################################################################################
Expand All @@ -17,7 +17,6 @@ def test_compute_irasa(tsig_comb):
# Estimate periodic and aperiodic components with IRASA
f_range = [1, 30]
freqs, psd_ap, psd_pe = compute_irasa(tsig_comb, FS, f_range, noverlap=int(2*FS))

assert len(freqs) == len(psd_ap) == len(psd_pe)

# Compute r-squared for the full model, comparing to a standard power spectrum
Expand Down
2 changes: 1 addition & 1 deletion neurodsp/tests/burst/test_dualthresh.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Tests for burst detection functions."""
"""Tests for neurodsp.burst.dualthresh."""

from neurodsp.tests.settings import FS

Expand Down
5 changes: 3 additions & 2 deletions neurodsp/tests/burst/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
"""Tests for burst detection functions."""
"""Tests for neurodsp.burst.utils."""

from neurodsp.burst.utils import *
import pytest

from neurodsp.burst.utils import *

###################################################################################################
###################################################################################################

Expand Down
2 changes: 1 addition & 1 deletion neurodsp/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Configuration file for pytest for NDSP."""
"""Pytest configuration file for testing neurodsp."""

import os
import shutil
Expand Down
9 changes: 4 additions & 5 deletions neurodsp/tests/filt/test_checks.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Tests for filter check functions."""
"""Tests for neurodsp.filt.checks."""

from pytest import raises

Expand All @@ -12,12 +12,11 @@

def test_check_filter_definition():

# Check that error catching works for bad pass_type definition
# Check error for bad pass_type definition
with raises(ValueError):
check_filter_definition('not_a_filter', (12, 12))

# Check that filter definitions that are legal evaluate as expected
# Float or partially filled tuple for f_range should work passable
f_lo, f_hi = check_filter_definition('bandpass', f_range=(8, 12))
assert f_lo == 8; assert f_hi == 12
f_lo, f_hi = check_filter_definition('bandstop', f_range=(58, 62))
Expand All @@ -31,7 +30,7 @@ def test_check_filter_definition():
f_lo, f_hi = check_filter_definition('highpass', f_range=(58, 100))
assert f_lo == 58 ; assert f_hi == None

# Check that a bandpass & bandstop definitions fail without proper definitions
# Check that bandpass & bandstop definitions fail without proper definitions
with raises(ValueError):
f_lo, f_hi = check_filter_definition('bandpass', f_range=8)
with raises(ValueError):
Expand All @@ -46,7 +45,7 @@ def test_check_filter_definition():
def test_check_filter_properties():

filter_coefs = design_fir_filter(FS, 'bandpass', (8, 12))

passes = check_filter_properties(filter_coefs, 1, FS, 'bandpass', (8, 12))
assert passes is True

Expand Down
2 changes: 1 addition & 1 deletion neurodsp/tests/filt/test_filter.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Test filtering functions."""
"""Tests for neurodsp.filt.filter."""

from pytest import raises, warns

Expand Down
26 changes: 14 additions & 12 deletions neurodsp/tests/filt/test_fir.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Tests for FIR filters."""
"""Tests for neurodsp.filt.fir."""

from pytest import raises

import numpy as np

from neurodsp.tests.settings import FS, EPS_FILT
Expand All @@ -15,20 +16,19 @@ def test_filter_signal_fir(tsig, tsig_sine):
out = filter_signal_fir(tsig, FS, 'bandpass', (8, 12))
assert out.shape == tsig.shape

# Apply lowpass to low-frequency sine. There should be little attenuation.
# Apply lowpass to low-frequency sine, which should should give little attenuation
sig_filt_lp = filter_signal_fir(tsig_sine, FS, pass_type='lowpass', f_range=(None, 10))

# Compare the two signals only at those times where the filtered signal is not nan.
# Compare the two signals at timepoints where the filtered signal is not nan
not_nan = ~np.isnan(sig_filt_lp)
assert np.allclose(tsig_sine[not_nan], sig_filt_lp[not_nan], atol=EPS_FILT)

# Now apply a high pass filter. The signal should be significantly attenuated.
# Apply a highpass filter, which should significantly attenuate the signal
sig_filt_hp = filter_signal_fir(tsig_sine, FS, pass_type='highpass', f_range=(30, None))

# Get rid of nans.
# Compare the two signals at timepoints where the filtered signal is not nan
not_nan = ~np.isnan(sig_filt_hp)
sig_filt_hp = sig_filt_hp[not_nan]

expected_answer = np.zeros_like(sig_filt_hp)
assert np.allclose(sig_filt_hp, expected_answer, atol=EPS_FILT)

Expand Down Expand Up @@ -58,23 +58,25 @@ def test_compute_filter_length():
f_lo, f_hi = 4, 8

# Check filt_len, if defined using n_seconds
n_seconds = 1.75 # Number chosen to create odd expected filt_len (not needing rounding up)
# n_seconds here is chosen to create expected odd filt_len, without needing rounding up
n_seconds = 1.75
expected_filt_len = n_seconds * fs
filt_len = compute_filter_length(fs, 'bandpass', f_lo, f_hi, n_cycles=None, n_seconds=n_seconds)
filt_len = compute_filter_length(fs, 'bandpass', f_lo, f_hi,
n_cycles=None, n_seconds=n_seconds)
assert filt_len == expected_filt_len

# Check filt_len, if defined using n_cycles
n_cycles = 5
expected_filt_len = int(np.ceil(fs * n_cycles / f_lo))
filt_len = compute_filter_length(fs, 'bandpass', f_lo, f_hi, n_cycles=n_cycles, n_seconds=None)
filt_len = compute_filter_length(fs, 'bandpass', f_lo, f_hi,
n_cycles=n_cycles, n_seconds=None)
assert filt_len == expected_filt_len

# Check filt_len, if expected to be rounded up to be odd
n_cycles = 4
expected_filt_len = int(np.ceil(fs * n_cycles / f_lo)) + 1
filt_len = compute_filter_length(fs, 'bandpass', f_lo, f_hi, n_cycles=n_cycles, n_seconds=None)
filt_len = compute_filter_length(fs, 'bandpass', f_lo, f_hi,
n_cycles=n_cycles, n_seconds=None)
assert filt_len == expected_filt_len

with raises(ValueError):
filt_len = compute_filter_length(fs, 'bandpass', f_lo, f_hi)

2 changes: 1 addition & 1 deletion neurodsp/tests/filt/test_iir.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Tests for IIR filters."""
"""Tests for neurodsp.filt.iir."""

import numpy as np

Expand Down
8 changes: 5 additions & 3 deletions neurodsp/tests/filt/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
"""Tests for filter utilities."""
"""Tests for neurodsp.filt.utils."""

from pytest import raises

from neurodsp.tests.settings import FS

from neurodsp.filt.utils import *
from neurodsp.filt.fir import design_fir_filter, compute_filter_length

from neurodsp.filt.utils import *

###################################################################################################
###################################################################################################

Expand Down Expand Up @@ -42,7 +44,7 @@ def test_compute_nyquist():

def test_remove_filter_edges():

# Get the length for a possible filter & calculate # of values should be dropped for it
# Get the length for a possible filter & calculate # of values that should be dropped for it
sig_len = 1000
sig = np.ones(sig_len)
filt_len = compute_filter_length(FS, 'bandpass', f_lo=4, f_hi=8, n_cycles=3, n_seconds=None)
Expand Down
2 changes: 1 addition & 1 deletion neurodsp/tests/plts/test_filt.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Test filtering plots."""
"""Tests for neurodsp.plts.filt."""

from neurodsp.filt.filter import filter_signal
from neurodsp.filt.fir import design_fir_filter
Expand Down
2 changes: 1 addition & 1 deletion neurodsp/tests/plts/test_rhythm.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Test rhythm plots."""
"""Tests for neurodsp.plts.rhythm."""

import numpy as np

Expand Down
3 changes: 2 additions & 1 deletion neurodsp/tests/plts/test_spectral.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
"""Test spectral plots."""
"""Tests for neurodsp.plts.spectral."""

import numpy as np

from neurodsp.spectral.variance import compute_spectral_hist
from neurodsp.spectral.power import compute_spectrum

from neurodsp.tests.settings import TEST_PLOTS_PATH
from neurodsp.tests.tutils import plot_test

Expand Down
6 changes: 3 additions & 3 deletions neurodsp/tests/plts/test_style.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Test plot style related functionality."""
"""Tests for neurodsp.plts.style."""

import matplotlib.pyplot as plt

Expand Down Expand Up @@ -40,7 +40,7 @@ def test_apply_line_style():

assert ax.get_lines()[0].get_lw() == lw

# Check applying style across multiple lines
# Check applying style to multiple lines
_, ax = plt.subplots()
ax.plot([1, 2], [[3, 4], [5, 6]])

Expand Down Expand Up @@ -71,7 +71,7 @@ def test_plot_style():
def my_custom_styler(ax, **kwargs):
ax.set_title('DATA!')

# Apply plot style using all defaults
# Apply plot style using defaults
plot_style(ax)

# Apply plot style passing in a styler
Expand Down
6 changes: 3 additions & 3 deletions neurodsp/tests/plts/test_time_series.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Test time series plots."""
"""Tests for neurodsp.plts.time_series."""

from pytest import raises

Expand All @@ -15,10 +15,10 @@ def test_plot_time_series(tsig):

times = np.arange(0, len(tsig), 1)

# Run single time series plot
# Check single time series plot
plot_time_series(times, tsig)

# Run multi time series plot, with colors & labels
# Check multi time series plot, with colors & labels
plot_time_series(times, [tsig, tsig[::-1]], labels=['signal', 'signal reversed'],
colors=['k', 'r'], save_fig=True, file_name='test_plot_time_series.png',
file_path=TEST_PLOTS_PATH)
Expand Down
4 changes: 2 additions & 2 deletions neurodsp/tests/plts/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Test plot utilities."""
"""Tests for neurodsp.plts.utils."""

import os
import tempfile
Expand All @@ -10,7 +10,7 @@

def test_check_ax():

# Check running will None Input
# Check running with None Input
ax = check_ax(None)

# Check running with pre-created axis
Expand Down
4 changes: 2 additions & 2 deletions neurodsp/tests/rhythm/test_lc.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Test lagged coherence code."""
"""Tests for neurodsp.rhythm.lc (lagged coherence)."""

from pytest import warns

Expand All @@ -22,7 +22,7 @@ def test_compute_lagged_coherence(tsig):
# Check using a list of n_cycles definitions
lc = compute_lagged_coherence(tsig, FS, FREQS_ARR, n_cycles=[3, 4, 5])

# Test the warning if can't estimate some values
# Test the warning if some values can't be estimated
with warns(UserWarning):
compute_lagged_coherence(tsig, 100, np.array([1, 2]), n_cycles=10)

Expand Down
2 changes: 1 addition & 1 deletion neurodsp/tests/rhythm/test_swm.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Test the sliding window matching function."""
"""Tests for neurodsp.rhythm.swm (sliding window matching)."""

from neurodsp.tests.settings import FS

Expand Down
6 changes: 3 additions & 3 deletions neurodsp/tests/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
###################################################################################################
###################################################################################################

# Define general settings for simulations & tests
# Define general settings for test simulations
FS = 100
FS_HIGH = 1000
N_SECONDS = 1.0
N_SECONDS_LONG = 10.0

# Define parameter options for simulations
# Define parameter options for test simulations
FREQ1 = 10
FREQ2 = 25
FREQ_SINE = 1
Expand All @@ -28,6 +28,6 @@
EPS = 10**(-10)
EPS_FILT = 10**(-3)

# Path Settings
# Set paths for test files
BASE_TEST_FILE_PATH = pkg.resource_filename(__name__, 'test_files')
TEST_PLOTS_PATH = os.path.join(BASE_TEST_FILE_PATH, 'plots')
3 changes: 1 addition & 2 deletions neurodsp/tests/sim/test_aperiodic.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Test aperiodic simulation functions."""
"""Tests for neurodsp.sim.aperiodic."""

import numpy as np
from scipy.optimize import curve_fit
Expand Down Expand Up @@ -60,7 +60,6 @@ def _estimate_single_knee(xs, offset, knee, chi2):

assert -round(chi2_hat) == EXP2


def test_sim_random_walk():

sig = sim_random_walk(N_SECONDS, FS)
Expand Down
2 changes: 1 addition & 1 deletion neurodsp/tests/sim/test_combined.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Test combined simulation functions."""
"""Tests for neurodsp.sim.combined."""

from pytest import raises

Expand Down
2 changes: 1 addition & 1 deletion neurodsp/tests/sim/test_cycles.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Test cycle simulation functions."""
"""Tests for neurodsp.sim.cycle."""

from pytest import raises

Expand Down
2 changes: 1 addition & 1 deletion neurodsp/tests/sim/test_info.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Tests for simulation info functions."""
"""Tests for neurodsp.sim.info."""

from pytest import raises

Expand Down
2 changes: 1 addition & 1 deletion neurodsp/tests/sim/test_periodic.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Test periodic simulation functions."""
"""Tests for neurodsp.sim.periodic."""

from neurodsp.tests.tutils import check_sim_output
from neurodsp.tests.settings import FS, N_SECONDS, FREQ1
Expand Down
2 changes: 1 addition & 1 deletion neurodsp/tests/sim/test_transients.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Test transient simulation functions."""
"""Tests for neurodsp.sim.transients."""

import numpy as np

Expand Down
2 changes: 1 addition & 1 deletion neurodsp/tests/spectral/test_checks.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Test spectral checker functions."""
"""Tests neurodsp.spectral.checks."""

import numpy as np

Expand Down
Loading