From 5610d508f33de1aefb18ae941f3a47f9949aed3c Mon Sep 17 00:00:00 2001 From: Peter Corke Date: Thu, 26 Nov 2026 12:04:29 +1000 Subject: [PATCH 1/2] test: TestGridify no longer hides the per-cell test, and test_polygons drops a repeated import Two classes named TestGridify in one file meant the first one never ran. It is renamed TestGridifyPerCell; it passes. Codacy pyflakes F811. Co-Authored-By: Claude Sonnet 5.5 --- tests/test_image_constants.py | 2 -- tests/test_image_point_features_extra.py | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/test_image_constants.py b/tests/test_image_constants.py index beecdb39..35bd47d5 100644 --- a/tests/test_image_constants.py +++ b/tests/test_image_constants.py @@ -525,8 +525,6 @@ def test_chequerboard(self): self.assertTrue(im._A.sum(), 64 * 128 / 2) def test_polygons(self): - from spatialmath import Polygon2 - p1 = Polygon2([(10, 10), (12, 10), (12, 12), (10, 12)]) # 2x2 p2 = Polygon2([(30, 30), (40, 30), (40, 40), (30, 40)]) # 10x10 diff --git a/tests/test_image_point_features_extra.py b/tests/test_image_point_features_extra.py index 67797941..7e946c11 100644 --- a/tests/test_image_point_features_extra.py +++ b/tests/test_image_point_features_extra.py @@ -278,7 +278,7 @@ def test_sum_of_different_types_is_an_error(self): sum([a, b]) -class TestGridify: +class TestGridifyPerCell: def test_limits_features_per_cell(self): # ten features in one corner cell of a 2 x 2 grid of a 100 x 100 image image = Image(np.zeros((100, 100), dtype=np.uint8)) From 4299b3bbb403531b1dcbd188f7b39dd4c1a95df3 Mon Sep 17 00:00:00 2001 From: Peter Corke Date: Thu, 26 Nov 2026 12:06:42 +1000 Subject: [PATCH 2/2] chore: tests have explicit imports, no unused imports or variables Codacy pyflakes F401, F405, F841. The star imports in test_graphics.py and test_image_color.py name what they use. Imports that only probe for an optional package use __import__, which pyflakes accepts. 2416 tests pass. Co-Authored-By: Claude Sonnet 5.5 --- tests/base/test_base_color.py | 3 +- tests/base/test_graphics.py | 12 +++- tests/base/test_io.py | 93 ++--------------------------- tests/test_bag_of_words.py | 7 +-- tests/test_bin.py | 6 +- tests/test_cv2_contrib.py | 2 +- tests/test_image_blobs.py | 2 - tests/test_image_color.py | 12 +++- tests/test_image_constants.py | 3 +- tests/test_image_core.py | 10 ++-- tests/test_image_io.py | 11 ++-- tests/test_image_line_features.py | 5 +- tests/test_image_morph.py | 1 - tests/test_image_region_features.py | 2 - tests/test_image_sources.py | 6 +- tests/test_image_spatial.py | 2 +- tests/test_image_whole_features.py | 4 +- tests/test_pointcloud.py | 6 +- tests/test_ros.py | 9 ++- 19 files changed, 56 insertions(+), 140 deletions(-) diff --git a/tests/base/test_base_color.py b/tests/base/test_base_color.py index 99b0da45..a1423eac 100644 --- a/tests/base/test_base_color.py +++ b/tests/base/test_base_color.py @@ -6,7 +6,6 @@ import numpy as np import numpy.testing as nt -import machinevisiontoolbox as mvt from machinevisiontoolbox.base import color @@ -23,7 +22,7 @@ def test_blackbody(self): def test_loadspectrum(self): - data_dir = Path.cwd() / "machinevisiontoolbox" / "data" + Path.cwd() / "machinevisiontoolbox" / "data" nm = 1e-9 λ = np.linspace(400, 700, 30) * nm diff --git a/tests/base/test_graphics.py b/tests/base/test_graphics.py index e6c9d400..9db6a1ad 100644 --- a/tests/base/test_graphics.py +++ b/tests/base/test_graphics.py @@ -1,11 +1,17 @@ import unittest -from unittest.case import skip -import matplotlib.pyplot as plt import numpy as np import numpy.testing as nt -from machinevisiontoolbox.base import * +from machinevisiontoolbox.base import ( + draw_box, + draw_circle, + draw_labelbox, + draw_line, + draw_point, + idisp, + plot_labelbox, +) class TestBlobs(unittest.TestCase): diff --git a/tests/base/test_io.py b/tests/base/test_io.py index 8bfaac64..20a7c624 100644 --- a/tests/base/test_io.py +++ b/tests/base/test_io.py @@ -2,12 +2,9 @@ # test for Image input/output -import contextlib -import io import os import unittest import urllib.error -from collections.abc import Iterable from pathlib import Path import numpy as np @@ -150,8 +147,6 @@ def test_convert_mono_from_color(self): color_im = np.zeros((10, 10, 3), dtype=np.uint8) color_im[:, :, 0] = 100 - from machinevisiontoolbox.base.imageio import convert - mono_im = convert(color_im, mono=True) self.assertEqual(len(mono_im.shape), 2) @@ -163,8 +158,6 @@ def test_convert_rgb_from_bgr(self): bgr_im[:, :, 0] = 100 # Blue channel bgr_im[:, :, 2] = 200 # Red channel - from machinevisiontoolbox.base.imageio import convert - rgb_im = convert(bgr_im, rgb=True) self.assertEqual(rgb_im.shape, bgr_im.shape) @@ -175,8 +168,6 @@ def test_convert_dtype_uint8(self): """Test dtype conversion to uint8""" im = (np.random.rand(10, 10) * 255).astype(np.uint8) - from machinevisiontoolbox.base.imageio import convert - result = convert(im, dtype="uint8") self.assertEqual(result.dtype, np.uint8) @@ -185,8 +176,6 @@ def test_convert_dtype_float32(self): """Test dtype conversion to float32""" im = np.random.randint(0, 256, (10, 10), dtype=np.uint8) - from machinevisiontoolbox.base.imageio import convert - result = convert(im, dtype="float32") self.assertEqual(result.dtype, np.float32) @@ -195,8 +184,6 @@ def test_convert_reduce(self): """Test image reduction (subsampling)""" im = np.ones((20, 30), dtype=np.uint8) - from machinevisiontoolbox.base.imageio import convert - result = convert(im, reduce=2) self.assertEqual(result.shape, (10, 15)) @@ -206,8 +193,6 @@ def test_convert_roi(self): im = np.arange(100, dtype=np.uint8).reshape(10, 10) roi = [2, 8, 1, 5] # umin, umax, vmin, vmax - from machinevisiontoolbox.base.imageio import convert - result = convert(im, roi=roi) # roi should extract [vmin:vmax, umin:umax] @@ -219,8 +204,6 @@ def test_convert_remove_alpha(self): rgba_im[:, :, 0] = 100 rgba_im[:, :, 3] = 255 - from machinevisiontoolbox.base.imageio import convert - result = convert(rgba_im, alpha=False) self.assertEqual(result.shape[2], 3) @@ -231,8 +214,6 @@ def test_convert_keep_alpha(self): rgba_im[:, :, 0] = 100 rgba_im[:, :, 3] = 255 - from machinevisiontoolbox.base.imageio import convert - result = convert(rgba_im, alpha=True) self.assertEqual(result.shape[2], 4) @@ -241,8 +222,6 @@ def test_convert_copy(self): """Test copy flag with dtype conversion""" im = np.ones((10, 10), dtype=np.uint8) - from machinevisiontoolbox.base.imageio import convert - # When there's a transformation (dtype change), copy flag should take effect result = convert(im, dtype="float32", copy=True) @@ -254,8 +233,6 @@ def test_convert_no_copy(self): """Test default behavior without copy""" im = np.ones((10, 10), dtype=np.uint8) - from machinevisiontoolbox.base.imageio import convert - result = convert(im) # When no transformations applied, result shares data with original @@ -433,8 +410,6 @@ def test_convert_mono_from_bgr(self): bgr_im[:, :, 1] = 150 # Green bgr_im[:, :, 2] = 200 # Red - from machinevisiontoolbox.base.imageio import convert - mono = convert(bgr_im, mono=True) self.assertEqual(len(mono.shape), 2) @@ -444,8 +419,6 @@ def test_convert_with_gamma(self): """Test gamma correction in convert""" im = (np.random.rand(10, 10) * 255).astype(np.uint8) - from machinevisiontoolbox.base.imageio import convert - # gamma decode should apply gamma correction result = convert(im, gamma="sRGB") @@ -455,8 +428,6 @@ def test_convert_float_image_dtype(self): """Test float image conversion between dtypes""" im = np.random.rand(10, 10).astype(np.float32) - from machinevisiontoolbox.base.imageio import convert - result = convert(im, dtype="float64") self.assertEqual(result.dtype, np.float64) @@ -465,8 +436,6 @@ def test_convert_uint16_to_uint8(self): """Test uint16 to uint8 conversion""" im = np.random.randint(0, 65535, (10, 10), dtype=np.uint16) - from machinevisiontoolbox.base.imageio import convert - result = convert(im, dtype="uint8") self.assertEqual(result.dtype, np.uint8) @@ -475,8 +444,6 @@ def test_convert_uint8_to_float(self): """Test uint8 to float conversion""" im = np.random.randint(0, 256, (10, 10), dtype=np.uint8) - from machinevisiontoolbox.base.imageio import convert - result = convert(im, dtype="float32") self.assertEqual(result.dtype, np.float32) @@ -491,8 +458,6 @@ def test_convert_3channel_to_mono_rgb(self): rgb_im[:, :, 1] = 150 # Green rgb_im[:, :, 2] = 200 # Blue - from machinevisiontoolbox.base.imageio import convert - mono = convert(rgb_im, mono=True) self.assertEqual(len(mono.shape), 2) @@ -501,8 +466,6 @@ def test_convert_with_multiple_options(self): """Test convert with multiple options combined""" im = np.random.randint(0, 256, (20, 30, 3), dtype=np.uint8) - from machinevisiontoolbox.base.imageio import convert - result = convert(im, mono=True, reduce=2, dtype="float32") self.assertEqual(len(result.shape), 2) @@ -572,8 +535,6 @@ def test_convert_invalid_dtype(self): """Test convert with invalid dtype""" im = np.ones((10, 10), dtype=np.uint8) - from machinevisiontoolbox.base.imageio import convert - with self.assertRaises(ValueError): convert(im, dtype="invalid_type") @@ -581,8 +542,6 @@ def test_convert_invalid_roi_values(self): """Test convert with invalid ROI values""" im = np.arange(100, dtype=np.uint8).reshape(10, 10) - from machinevisiontoolbox.base.imageio import convert - # This should either work or raise an error gracefully # Testing that it doesn't crash unexpectedly try: @@ -663,8 +622,6 @@ def test_convert_rgb_to_bgr(self): rgb_im[:, :, 1] = 150 # Green rgb_im[:, :, 2] = 200 # Blue - from machinevisiontoolbox.base.imageio import convert - bgr_im = convert(rgb_im, rgb=True) self.assertEqual(bgr_im.shape, rgb_im.shape) @@ -673,8 +630,6 @@ def test_convert_preserves_2d_shape(self): """Test that 2D images stay 2D after conversion""" im = np.random.randint(0, 256, (20, 20), dtype=np.uint8) - from machinevisiontoolbox.base.imageio import convert - result = convert(im, reduce=2) self.assertEqual(len(result.shape), 2) @@ -683,8 +638,6 @@ def test_convert_preserves_3d_shape(self): """Test that 3D images stay 3D after conversion""" im = np.random.randint(0, 256, (20, 20, 3), dtype=np.uint8) - from machinevisiontoolbox.base.imageio import convert - result = convert(im, reduce=2) self.assertEqual(len(result.shape), 3) @@ -793,8 +746,6 @@ def test_convert_roi_full_image(self): """Test ROI that covers full image""" im = np.arange(100, dtype=np.uint8).reshape(10, 10) - from machinevisiontoolbox.base.imageio import convert - result = convert(im, roi=[0, 10, 0, 10]) self.assertIsInstance(result, np.ndarray) @@ -803,8 +754,6 @@ def test_convert_roi_small_region(self): """Test ROI with very small region""" im = np.arange(100, dtype=np.uint8).reshape(10, 10) - from machinevisiontoolbox.base.imageio import convert - result = convert(im, roi=[5, 6, 5, 6]) self.assertEqual(result.shape[0], 1) @@ -814,8 +763,6 @@ def test_convert_roi_with_color(self): """Test ROI extraction on color image""" im = np.random.randint(0, 256, (20, 20, 3), dtype=np.uint8) - from machinevisiontoolbox.base.imageio import convert - result = convert(im, roi=[5, 15, 5, 15]) self.assertEqual(len(result.shape), 3) @@ -860,8 +807,6 @@ def test_convert_dtype_int_alias(self): """Test 'int' dtype alias converts to uint8""" im = np.random.rand(10, 10).astype(np.float32) - from machinevisiontoolbox.base.imageio import convert - result = convert(im, dtype="int") self.assertEqual(result.dtype, np.uint8) @@ -870,8 +815,6 @@ def test_convert_dtype_float_alias(self): """Test 'float' dtype alias converts to float32""" im = np.random.randint(0, 256, (10, 10), dtype=np.uint8) - from machinevisiontoolbox.base.imageio import convert - result = convert(im, dtype="float") self.assertEqual(result.dtype, np.float32) @@ -880,8 +823,6 @@ def test_convert_dtype_double_alias(self): """Test 'double' dtype alias converts to float64""" im = np.random.randint(0, 256, (10, 10), dtype=np.uint8) - from machinevisiontoolbox.base.imageio import convert - result = convert(im, dtype="double") self.assertEqual(result.dtype, np.float64) @@ -890,8 +831,6 @@ def test_convert_dtype_half_alias(self): """Test 'half' dtype alias converts to float16""" im = np.random.randint(0, 256, (10, 10), dtype=np.uint8) - from machinevisiontoolbox.base.imageio import convert - result = convert(im, dtype="half") self.assertEqual(result.dtype, np.float16) @@ -1120,8 +1059,6 @@ def test_convert_bgra_remove_alpha(self): bgra_im[:, :, 0] = 100 # Blue bgra_im[:, :, 3] = 255 # Alpha - from machinevisiontoolbox.base.imageio import convert - result = convert(bgra_im, alpha=False) # Should have 3 channels after removing alpha @@ -1133,8 +1070,6 @@ def test_convert_bgra_keep_alpha(self): bgra_im[:, :, 0] = 100 # Blue bgra_im[:, :, 3] = 255 # Alpha - from machinevisiontoolbox.base.imageio import convert - result = convert(bgra_im, alpha=True) # Should keep 4 channels @@ -1160,8 +1095,6 @@ def test_convert_srgb_gamma(self): """Test sRGB gamma decoding""" im = np.random.randint(0, 256, (10, 10), dtype=np.uint8) - from machinevisiontoolbox.base.imageio import convert - result = convert(im, gamma="sRGB") # Result should be different from input due to gamma correction @@ -1174,8 +1107,6 @@ def test_convert_gamma_with_other_options(self): """Test gamma with other transformations""" im = np.random.randint(0, 256, (20, 20), dtype=np.uint8) - from machinevisiontoolbox.base.imageio import convert - result = convert(im, gamma="sRGB", reduce=2) self.assertIsInstance(result, np.ndarray) @@ -1254,11 +1185,11 @@ def test_idisp_reuse_true(self): try: # Display first image with coordformat=None to avoid interactive issues - result1 = idisp(im1, ax=ax, reuse=True, coordformat=None) + idisp(im1, ax=ax, reuse=True, coordformat=None) # Reuse path returns None when successful # Display second image reusing axis - result2 = idisp(im2, ax=ax, reuse=True, coordformat=None) + idisp(im2, ax=ax, reuse=True, coordformat=None) # Both calls should complete without error except (AttributeError, TypeError): # In headless environments, canvas operations may fail @@ -1266,7 +1197,6 @@ def test_idisp_reuse_true(self): def test_idisp_multiple_figures(self): """Test idisp with multiple figures sequentially""" - import matplotlib.pyplot as plt from machinevisiontoolbox.base.imageio import idisp @@ -1309,7 +1239,6 @@ def test_idisp_with_fps_parameter(self): def test_idisp_height_width_parameters(self): """Test idisp with explicit height/width""" - import matplotlib.pyplot as plt from machinevisiontoolbox.base.imageio import idisp @@ -1320,7 +1249,6 @@ def test_idisp_height_width_parameters(self): def test_idisp_with_colormap_ncolors(self): """Test idisp with colormap and number of colors""" - import matplotlib.pyplot as plt from machinevisiontoolbox.base.imageio import idisp @@ -1331,7 +1259,6 @@ def test_idisp_with_colormap_ncolors(self): def test_idisp_bgr_color_order(self): """Test idisp with BGR color order""" - import matplotlib.pyplot as plt from machinevisiontoolbox.base.imageio import idisp @@ -1342,7 +1269,6 @@ def test_idisp_bgr_color_order(self): def test_idisp_darken_true(self): """Test idisp with darken=True (darkens by 0.5)""" - import matplotlib.pyplot as plt from machinevisiontoolbox.base.imageio import idisp @@ -1356,8 +1282,6 @@ def test_idisp_with_savefigname(self): import os import tempfile - import matplotlib.pyplot as plt - from machinevisiontoolbox.base.imageio import idisp im = np.random.randint(0, 256, (30, 30), dtype=np.uint8) @@ -1377,7 +1301,7 @@ def test_idisp_current_axis_gca(self): # Create figure first fig = plt.figure() - ax = fig.add_subplot(111) + fig.add_subplot(111) im = np.random.randint(0, 256, (30, 30), dtype=np.uint8) @@ -1387,7 +1311,6 @@ def test_idisp_current_axis_gca(self): def test_idisp_vrange_with_colormap(self): """Test idisp vrange with colormap normalization""" - import matplotlib.pyplot as plt from machinevisiontoolbox.base.imageio import idisp @@ -1398,7 +1321,6 @@ def test_idisp_vrange_with_colormap(self): def test_idisp_undercolor_overcolor_with_vrange(self): """Test undercolor/overcolor with vrange clipping""" - import matplotlib.pyplot as plt from machinevisiontoolbox.base.imageio import idisp @@ -1415,7 +1337,6 @@ def test_idisp_undercolor_overcolor_with_vrange(self): def test_idisp_uint16_with_vrange(self): """Test uint16 image with custom vrange""" - import matplotlib.pyplot as plt from machinevisiontoolbox.base.imageio import idisp @@ -1426,7 +1347,6 @@ def test_idisp_uint16_with_vrange(self): def test_idisp_float_with_vrange(self): """Test float image with vrange normalization""" - import matplotlib.pyplot as plt from machinevisiontoolbox.base.imageio import idisp @@ -1437,7 +1357,6 @@ def test_idisp_float_with_vrange(self): def test_idisp_3channel_different_sizes(self): """Test idisp with various 3-channel image sizes""" - import matplotlib.pyplot as plt from machinevisiontoolbox.base.imageio import idisp @@ -1449,7 +1368,6 @@ def test_idisp_3channel_different_sizes(self): def test_idisp_axes_grid_combination(self): """Test idisp with axes and grid combination""" - import matplotlib.pyplot as plt from machinevisiontoolbox.base.imageio import idisp @@ -1460,7 +1378,6 @@ def test_idisp_axes_grid_combination(self): def test_idisp_frame_plain_combination(self): """Test idisp with frame and plain options""" - import matplotlib.pyplot as plt from machinevisiontoolbox.base.imageio import idisp @@ -1496,11 +1413,11 @@ def test_idisp_reuse_with_different_image_types(self): try: # First greyscale im_grey = np.random.randint(0, 256, (30, 30), dtype=np.uint8) - result1 = idisp(im_grey, ax=ax, reuse=True, coordformat=None) + idisp(im_grey, ax=ax, reuse=True, coordformat=None) # Then color im_color = np.random.randint(0, 256, (30, 30, 3), dtype=np.uint8) - result2 = idisp(im_color, ax=ax, reuse=True, coordformat=None) + idisp(im_color, ax=ax, reuse=True, coordformat=None) # Reuse path should complete without error except (AttributeError, TypeError): diff --git a/tests/test_bag_of_words.py b/tests/test_bag_of_words.py index 7f94fa7e..fef0392f 100644 --- a/tests/test_bag_of_words.py +++ b/tests/test_bag_of_words.py @@ -7,7 +7,6 @@ import warnings import numpy as np -import numpy.testing as nt from machinevisiontoolbox import BagOfWords, FileCollection @@ -41,12 +40,12 @@ def test_retrieve(self): query = FileCollection("campus/holdout/*.png", mono=True) S = bag.similarity(query) - q = np.argmax(S, axis=1) + np.argmax(S, axis=1) # nt.assert_equal(q, [0, 10, 17, 17, 17]) - q = bag.retrieve(query[0]) + bag.retrieve(query[0]) # self.assertEqual(q[0], 0) - q = bag.retrieve(query[1]) + bag.retrieve(query[1]) # self.assertEqual(q[0], 10) diff --git a/tests/test_bin.py b/tests/test_bin.py index cde1e03f..21bb6485 100644 --- a/tests/test_bin.py +++ b/tests/test_bin.py @@ -13,21 +13,21 @@ import unittest try: - import rosbags # noqa: F401 + __import__("rosbags") _rosbags_available = True except ImportError: _rosbags_available = False try: - import pytesseract # noqa: F401 + __import__("pytesseract") _pytesseract_available = True except ImportError: _pytesseract_available = False try: - import open3d # noqa: F401 + __import__("open3d") _open3d_available = True except ImportError: diff --git a/tests/test_cv2_contrib.py b/tests/test_cv2_contrib.py index 11246c53..1b490a32 100644 --- a/tests/test_cv2_contrib.py +++ b/tests/test_cv2_contrib.py @@ -66,6 +66,6 @@ def test_installing_twice_adds_nothing_more(): def test_the_real_cv2_still_works_after_import(): import cv2 - import machinevisiontoolbox # noqa: F401 + __import__("machinevisiontoolbox") assert hasattr(cv2, "SIFT_create") diff --git a/tests/test_image_blobs.py b/tests/test_image_blobs.py index 4bb2bbf3..458e8ef5 100644 --- a/tests/test_image_blobs.py +++ b/tests/test_image_blobs.py @@ -2,7 +2,6 @@ import json import unittest from pathlib import Path -from unittest.case import skip import matplotlib @@ -10,7 +9,6 @@ import matplotlib.colors as mcolors import matplotlib.pyplot as plt import numpy as np -import numpy.testing as nt from machinevisiontoolbox import Blobs, Image diff --git a/tests/test_image_color.py b/tests/test_image_color.py index 9a2185f6..c3b61931 100644 --- a/tests/test_image_color.py +++ b/tests/test_image_color.py @@ -6,7 +6,17 @@ import numpy.testing as nt from machinevisiontoolbox import Image -from machinevisiontoolbox.base.color import * +from machinevisiontoolbox.base.color import ( + XYZ2RGBxform, + ccxyz, + color2name, + colorspace_convert, + gamma_decode, + gamma_encode, + lambda2xy, + luminos, + name2color, +) class TestImageProcessingColor(unittest.TestCase): diff --git a/tests/test_image_constants.py b/tests/test_image_constants.py index 35bd47d5..1c085768 100644 --- a/tests/test_image_constants.py +++ b/tests/test_image_constants.py @@ -7,7 +7,6 @@ from spatialmath import Polygon2 from machinevisiontoolbox import Image -from machinevisiontoolbox.base.color import * class TestImageConstants(unittest.TestCase): @@ -118,7 +117,7 @@ def test_constant(self): self.assertEqual(im.dtype, np.float32) self.assertTrue(np.all(im._A == 0.74)) - with self.assertRaises(ValueError) as context: + with self.assertRaises(ValueError): im = Image.Constant((40, 41, 42), size=(5, 9), colororder="ABCD") def test_constant_new_style(self): diff --git a/tests/test_image_core.py b/tests/test_image_core.py index b06c555f..c3672c4f 100644 --- a/tests/test_image_core.py +++ b/tests/test_image_core.py @@ -1,6 +1,4 @@ import unittest -from pathlib import Path -from unittest.case import skip import numpy as np import numpy.testing as nt @@ -1250,7 +1248,7 @@ def test_pixels_mask(self): ) nt.assert_array_equal(pix, expected) - poly = Polygon2([(1, 2), (2, 2), (2, 4), (1, 4)]) + Polygon2([(1, 2), (2, 2), (2, 4), (1, 4)]) x = np.arange(24) im = Image(x, size=(4, 6)) # width x height pix = im.pixels_mask(mask) @@ -1344,16 +1342,16 @@ def test_init_input_check(self): # 1D array without size x = np.zeros((10,)) with self.assertRaises(ValueError): - y = Image(x) + Image(x) # 4D array without size x = np.zeros((10, 10, 3, 2)) with self.assertRaises(ValueError): - y = Image(x) + Image(x) # incorrect argument type with self.assertRaises(ValueError): - y = Image("image") + Image("image") def test_init_singleton_removal(self): x = np.zeros((5, 10, 1)) diff --git a/tests/test_image_io.py b/tests/test_image_io.py index 6008d018..21c11bc1 100644 --- a/tests/test_image_io.py +++ b/tests/test_image_io.py @@ -6,7 +6,6 @@ import io import os import unittest -from collections.abc import Iterable from pathlib import Path import numpy as np @@ -185,7 +184,7 @@ def test_anaglyph(self): # new test def test_disp(self): """Test image display""" - im = Image.Random(size=(50, 50), dtype="uint8") + Image.Random(size=(50, 50), dtype="uint8") # TODO: Test display (may require mock or headless mode) # im.disp(block=False) pass @@ -211,7 +210,7 @@ def test_metadata(self): # new test def test_showpixels(self): """Test showing pixel values overlay""" - im = Image.String("123|456|789") + Image.String("123|456|789") # TODO: Test pixel value display # im.showpixels() pass @@ -219,8 +218,8 @@ def test_showpixels(self): # new test def test_stdisp(self): """Test stereo image pair display""" - im_left = Image.Random(size=(50, 50), dtype="uint8") - im_right = Image.Random(size=(50, 50), dtype="uint8") + Image.Random(size=(50, 50), dtype="uint8") + Image.Random(size=(50, 50), dtype="uint8") # TODO: Test stereo display # im_left.stdisp(im_right) pass @@ -228,7 +227,7 @@ def test_stdisp(self): # new test def test_write(self): """Test writing image to file""" - im = Image.Random(size=(50, 50), dtype="uint8") + Image.Random(size=(50, 50), dtype="uint8") # TODO: Test writing to temp file and reading back # import tempfile # with tempfile.NamedTemporaryFile(suffix='.png') as f: diff --git a/tests/test_image_line_features.py b/tests/test_image_line_features.py index 03aa6921..8efd99c6 100644 --- a/tests/test_image_line_features.py +++ b/tests/test_image_line_features.py @@ -5,7 +5,6 @@ import cv2 import numpy as np -import numpy.testing as nt from machinevisiontoolbox import Image @@ -15,7 +14,7 @@ class TestImageLineFeatures(unittest.TestCase): def test_hough(self): """Test Hough transform for line detection""" # Create simple image with lines - im = Image.Zeros(size=(100, 100), dtype="uint8") + Image.Zeros(size=(100, 100), dtype="uint8") # Draw a line (diagonal) # TODO: Add actual line drawing # hough_result = im.Hough() @@ -32,7 +31,7 @@ def test_accumulator(self): def test_lines(self): """Test standard Hough line detection""" # Create image with known lines - im = Image.Zeros(size=(100, 100), dtype="uint8") + Image.Zeros(size=(100, 100), dtype="uint8") # TODO: Draw lines and detect them pass diff --git a/tests/test_image_morph.py b/tests/test_image_morph.py index ffab1fb7..8a4fea36 100644 --- a/tests/test_image_morph.py +++ b/tests/test_image_morph.py @@ -4,7 +4,6 @@ import numpy as np import numpy.testing as nt -import spatialmath.base.argcheck as argcheck from machinevisiontoolbox import Image diff --git a/tests/test_image_region_features.py b/tests/test_image_region_features.py index 878dd171..5aaef495 100644 --- a/tests/test_image_region_features.py +++ b/tests/test_image_region_features.py @@ -3,8 +3,6 @@ import unittest import cv2 -import numpy as np -import numpy.testing as nt from machinevisiontoolbox import Image diff --git a/tests/test_image_sources.py b/tests/test_image_sources.py index 5142aacc..2ee55225 100644 --- a/tests/test_image_sources.py +++ b/tests/test_image_sources.py @@ -2,8 +2,6 @@ # test for Image input/output -import contextlib -import io import json import os import subprocess @@ -27,7 +25,7 @@ _torch_available = False try: - import labelme # noqa: F401 + __import__("labelme") _labelme_available = True except ImportError: @@ -50,7 +48,7 @@ VideoFile, ZipArchive, ) -from machinevisiontoolbox.base import iread, mvtb_path_to_datafile +from machinevisiontoolbox.base import mvtb_path_to_datafile def _has_file(*args): diff --git a/tests/test_image_spatial.py b/tests/test_image_spatial.py index b13b234f..b99e7286 100644 --- a/tests/test_image_spatial.py +++ b/tests/test_image_spatial.py @@ -236,7 +236,7 @@ def test_kernel_dog_explicit_sigma2(self): nt.assert_array_almost_equal(K1.K, K2.K) def test_bordertype_sp_exclude_raises(self): - im = Image.Random(size=(10, 10)) + Image.Random(size=(10, 10)) from machinevisiontoolbox.ImageSpatial import ImageSpatialMixin with self.assertRaises(ValueError): diff --git a/tests/test_image_whole_features.py b/tests/test_image_whole_features.py index 2c1d7455..ef2704b8 100644 --- a/tests/test_image_whole_features.py +++ b/tests/test_image_whole_features.py @@ -327,14 +327,14 @@ def test_printstats_before_stats_accessed(self): def test_peaks(self): """Test peak finding in histogram""" im = Image.String("000011112222") - hist = im.hist() + im.hist() peaks = im.peaks() self.assertIsNotNone(peaks) # new test def test_plot(self): """Test plotting histogram""" - im = Image.Random(size=(50, 50), dtype="uint8") + Image.Random(size=(50, 50), dtype="uint8") # TODO: Test histogram plotting (may require mock) # im.plot() pass diff --git a/tests/test_pointcloud.py b/tests/test_pointcloud.py index 53745f87..8b28ddd0 100644 --- a/tests/test_pointcloud.py +++ b/tests/test_pointcloud.py @@ -2,15 +2,13 @@ import unittest -import matplotlib.pyplot as plt import numpy as np import numpy.testing as nt -from spatialmath import SE3 from machinevisiontoolbox import CentralCamera, Image, PointCloud try: - import open3d # noqa: F401 + __import__("open3d") open3d_available = True except ImportError: @@ -54,7 +52,7 @@ def test_read(self): try: - import plotly # noqa: F401 + __import__("plotly") plotly_available = True except ImportError: diff --git a/tests/test_ros.py b/tests/test_ros.py index ec4a0d82..a51781e5 100644 --- a/tests/test_ros.py +++ b/tests/test_ros.py @@ -96,7 +96,7 @@ def test_exact_match(self): self.assertIsNotNone(ts) def test_case_insensitive(self): - ts1 = _resolve_typestore("ROS1_NOETIC") + _resolve_typestore("ROS1_NOETIC") ts2 = _resolve_typestore("ros1_noetic") # both should return a typestore without raising self.assertIsNotNone(ts2) @@ -211,7 +211,7 @@ def test_imu_passthrough_has_topic_and_timestamp(self): def test_context_manager_closes(self): bag = self._bag() with bag: - imgs = list(bag) + list(bag) # reader should be closed after exiting context self.assertIsNone(bag.reader) @@ -313,7 +313,7 @@ def test_frozen(self): def _make_mock_stream(output="image", message="sensor_msgs/CompressedImage"): """Build a ROSTopic-like object bypassing roslibpy entirely.""" try: - import roslibpy + __import__("roslibpy") except ImportError: pytest.skip("roslibpy not installed") @@ -586,7 +586,6 @@ def test_exact_match(self): self.assertEqual(b.timestamp, t) def test_within_tolerance_matches(self): - tol = 20_000_000 # 20 ms in ns t0 = 1_000_000_000 # stream2 is 10 ms ahead — within 20 ms tolerance s1 = _fake_stream(t0) @@ -651,7 +650,7 @@ def test_str_includes_topics(self): _websockets_available = False try: - import websockets # noqa: F401 + __import__("websockets") _websockets_available = True except ImportError: