Skip to content

Commit

Permalink
Fix linting issues
Browse files Browse the repository at this point in the history
  • Loading branch information
kostrykin committed Sep 18, 2024
1 parent 4a1ca08 commit 6c6c3e0
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 14 deletions.
1 change: 1 addition & 0 deletions .github/workflows/linters.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@ jobs:
- name: Run linters
run: |
flake8 superdsm
flake8 tests
isort superdsm --check-only --diff
isort tests --check-only --diff
9 changes: 6 additions & 3 deletions tests/regression/batch-validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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}'
)
26 changes: 15 additions & 11 deletions tests/regression/validate.py
Original file line number Diff line number Diff line change
@@ -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')

Expand All @@ -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)
Expand Down Expand Up @@ -67,24 +67,28 @@

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)
missing_rows = expected_csv_rows - actual_csv_rows
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:
Expand Down
2 changes: 2 additions & 0 deletions tests/test_atoms.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import unittest

import numpy as np

import superdsm.atoms


Expand Down

0 comments on commit 6c6c3e0

Please sign in to comment.