From 6c6c3e0dac6367619dde5e4c0bb571cacdf249f6 Mon Sep 17 00:00:00 2001 From: Leonid Kostrykin Date: Wed, 18 Sep 2024 10:56:45 +0200 Subject: [PATCH] Fix linting issues --- .github/workflows/linters.yml | 1 + tests/regression/batch-validate.py | 9 ++++++--- tests/regression/validate.py | 26 +++++++++++++++----------- tests/test_atoms.py | 2 ++ 4 files changed, 24 insertions(+), 14 deletions(-) diff --git a/.github/workflows/linters.yml b/.github/workflows/linters.yml index 20513054..e217fdb3 100644 --- a/.github/workflows/linters.yml +++ b/.github/workflows/linters.yml @@ -28,5 +28,6 @@ jobs: - name: Run linters run: | flake8 superdsm + flake8 tests isort superdsm --check-only --diff isort tests --check-only --diff \ No newline at end of file diff --git a/tests/regression/batch-validate.py b/tests/regression/batch-validate.py index c64629b4..fb3ae1b2 100644 --- a/tests/regression/batch-validate.py +++ b/tests/regression/batch-validate.py @@ -3,11 +3,11 @@ import pathlib import socket - parser = argparse.ArgumentParser(prog='Regression testing (batch)') parser.add_argument('actual_csv', help='Root directory where the actual CSV will be stored.') -parser.add_argument('--taskdirs', help='Directory for which the /seg subdirectory will be validated.', nargs='+', default=list()) +parser.add_argument('--taskdirs', help='Directory for which the /seg subdirectory will be validated.', nargs='+', + default=list()) parser.add_argument('--update-expected', help='Update the expected CSV.', action='store_true') args = parser.parse_args() @@ -22,4 +22,7 @@ actual_csv = pathlib.Path(args.actual_csv) / taskdir actual_csv.mkdir(parents=True, exist_ok=True) - os.system(f'python tests/regression/validate.py "examples/{taskdir}/seg" "{str(actual_csv)}" "tests/regression/expected/{hostname}/{taskdir}" {options}') + os.system( + f'python tests/regression/validate.py ' + f'"examples/{taskdir}/seg" "{str(actual_csv)}" "tests/regression/expected/{hostname}/{taskdir}" {options}' + ) diff --git a/tests/regression/validate.py b/tests/regression/validate.py index 92a7406c..cb1f7fe5 100644 --- a/tests/regression/validate.py +++ b/tests/regression/validate.py @@ -1,12 +1,12 @@ -import sys import argparse +import csv import glob import pathlib -import skimage.io -import csv -import scipy.ndimage as ndi import shutil +import sys +import scipy.ndimage as ndi +import skimage.io parser = argparse.ArgumentParser(prog='Regression testing') @@ -30,14 +30,14 @@ img = skimage.io.imread(str(actual_seg_filepath)) actual_csv_rows = list() - for l in frozenset(img.flatten()) - {0}: + for l in frozenset(img.flatten()) - {0}: # noqa: E741 cc = (img == l) cc_center_rc = ndi.center_of_mass(cc) actual_csv_rows.append((str(cc.sum()), str(round(cc_center_rc[1], 1)), str(round(cc_center_rc[0], 1)))) - actual_csv_rows.sort(key = lambda row: row[1:3]) + actual_csv_rows.sort(key=lambda row: row[1:3]) with actual_csv_filepath.open('w') as fp: - writer = csv.writer(fp, delimiter = ',', quoting = csv.QUOTE_ALL) + writer = csv.writer(fp, delimiter=',', quoting=csv.QUOTE_ALL) writer.writerows([['Object size', 'Center X', 'Center Y']] + actual_csv_rows) actual_csv_rows_by_filename[actual_seg_filepath.name] = frozenset(actual_csv_rows) @@ -67,9 +67,10 @@ expected_csv_rows = list() with expected_csv_filepath.open('r') as fp: - reader = csv.reader(fp, delimiter = ',', quoting = csv.QUOTE_ALL) + reader = csv.reader(fp, delimiter=',', quoting=csv.QUOTE_ALL) for ridx, row in enumerate(reader): - if ridx == 0: continue ## skip header + if ridx == 0: + continue # skip header expected_csv_rows.append(tuple(row)) expected_csv_rows = frozenset(expected_csv_rows) @@ -77,14 +78,17 @@ spurious_rows = actual_csv_rows - expected_csv_rows if len(spurious_rows) > 0 or len(missing_rows) > 0: - errors.append(f'{actual_seg_filename}: {len(spurious_rows)} spurious object(s) and {len(missing_rows)} missing object(s) cannot be matched') + errors.append( + f'{actual_seg_filename}: {len(spurious_rows)} spurious object(s) ' + f'and {len(missing_rows)} missing object(s) cannot be matched' + ) for remaining_filename in actual_csv_rows_by_filename.keys(): errors.append(f'Spurious label map: "{remaining_filename}"') -if 'img' not in locals(): ## an additional error check to prevent passing tests due to wrongs paths +if 'img' not in locals(): # an additional error check to prevent passing tests due to wrongs paths errors.append('No label maps found') if len(errors) == 0: diff --git a/tests/test_atoms.py b/tests/test_atoms.py index fb400a7a..4591fbe6 100644 --- a/tests/test_atoms.py +++ b/tests/test_atoms.py @@ -1,5 +1,7 @@ import unittest + import numpy as np + import superdsm.atoms