Autofix import order

This commit is contained in:
Julian Stirling 2025-12-02 16:26:15 +00:00
parent 98cdb276d8
commit 7bc4c514a6
59 changed files with 244 additions and 236 deletions

View file

@ -7,11 +7,12 @@ The mocks do not subclass Things. Instead, they return predefined
answers to functions.
"""
from unittest.mock import Mock, PropertyMock
from openflexure_microscope_server.background_detect import (
BackgroundDetectorStatus,
ColourChannelDetectSettings,
)
from unittest.mock import Mock, PropertyMock
class MockCameraThing(Mock):

View file

@ -3,8 +3,8 @@
This doesn't check the behaviour of the JPEG shaprness monitor.
"""
import pytest
import numpy as np
import pytest
from openflexure_microscope_server.things.autofocus import (
AutofocusThing,

View file

@ -5,19 +5,19 @@ This tests both the base class an individual algorithms.
import re
import numpy as np
import pytest
from pydantic import BaseModel
import numpy as np
from openflexure_microscope_server.background_detect import (
MissingBackgroundDataError,
BackgroundDetectAlgorithm,
ChannelDistributions,
ColourChannelDetectSettings,
ColourChannelDetectLUV,
_chunked_stds,
ChannelDeviationLUV,
ChannelBlankError,
ChannelDeviationLUV,
ChannelDistributions,
ColourChannelDetectLUV,
ColourChannelDetectSettings,
MissingBackgroundDataError,
_chunked_stds,
)
RNG = np.random.default_rng()

View file

@ -3,9 +3,9 @@
import tempfile
from contextlib import contextmanager
import numpy as np
import pytest
from fastapi.testclient import TestClient
import numpy as np
from PIL import Image
import labthings_fastapi as lt

View file

@ -3,9 +3,8 @@
from random import randint
import numpy as np
from PIL import Image
import pytest
from PIL import Image
from openflexure_microscope_server.things.camera import (
CameraMemoryBuffer,

View file

@ -7,8 +7,8 @@ on camera functionality using the simulation camera are in "test_camera".
import pytest
from openflexure_microscope_server.things.camera import BaseCamera
from openflexure_microscope_server.things.camera.simulation import SimulatedCamera
from openflexure_microscope_server.things.camera.opencv import OpenCVCamera
from openflexure_microscope_server.things.camera.simulation import SimulatedCamera
@pytest.fixture

View file

@ -1,10 +1,11 @@
"""Test the configuration handling functions in utilities."""
import pytest
import os
import json
import os
from json import JSONDecodeError
import pytest
from openflexure_microscope_server import utilities

View file

@ -12,18 +12,18 @@ import json
import os
import tempfile
from fastapi.testclient import TestClient
from PIL import Image
import numpy as np
import piexif
import pytest
from fastapi.testclient import TestClient
from PIL import Image
import labthings_fastapi as lt
from openflexure_microscope_server.things.camera.simulation import SimulatedCamera
from openflexure_microscope_server.things.stage.dummy import DummyStage
from openflexure_microscope_server.things.autofocus import AutofocusThing
from openflexure_microscope_server.things.camera.simulation import SimulatedCamera
from openflexure_microscope_server.things.camera_stage_mapping import CameraStageMapper
from openflexure_microscope_server.things.stage.dummy import DummyStage
@pytest.fixture

View file

@ -1,7 +1,7 @@
"""Test server booting and shut down."""
from socket import gethostname
import asyncio
from socket import gethostname
# Import as ofm server to attempt to minimise confusion with server as a var in other
# functions and also FastAPI `Server`.

View file

@ -1,12 +1,12 @@
"""Test the server's logging configuration and handling."""
import logging
import os
import tempfile
import logging
from fastapi.responses import PlainTextResponse
from fastapi import HTTPException
import pytest
from fastapi import HTTPException
from fastapi.responses import PlainTextResponse
from openflexure_microscope_server import logging as ofm_logging

View file

@ -2,9 +2,8 @@
from copy import deepcopy
import pytest
import numpy as np
import pytest
from openflexure_microscope_server.things.camera import (
picamera_tuning_file_utils as tf_utils,

View file

@ -5,9 +5,9 @@ import logging
import pytest
from openflexure_microscope_server.things.stage.sangaboard import (
SangaboardThing,
REQUIRED_VERSION,
RECOMMENDED_VERSION,
REQUIRED_VERSION,
SangaboardThing,
)

View file

@ -1,8 +1,8 @@
"""Test the functionality in the scan_directories module."""
from datetime import datetime, timedelta
from copy import copy
import json
from copy import copy
from datetime import datetime, timedelta
from math import floor
from openflexure_microscope_server.scan_directories import ScanData

View file

@ -1,24 +1,24 @@
"""Test the functionality in the scan_directories module."""
import tempfile
import os
import math
import shutil
import logging
import random
import time
import json
import logging
import math
import os
import random
import shutil
import tempfile
import time
from collections import namedtuple
import pytest
from openflexure_microscope_server.scan_directories import (
ScanDirectoryManager,
SCAN_DATA_FILENAME,
NotEnoughFreeSpaceError,
ScanDirectory,
ScanDirectoryManager,
ScanInfo,
get_files_in_zip,
NotEnoughFreeSpaceError,
SCAN_DATA_FILENAME,
)
from .test_scan_data import _fake_scan_data

View file

@ -4,10 +4,12 @@ As well as low level function by function tests, this test suite also provides t
that simulate scanning a sample, checking that the expected path is followed.
"""
import pytest
from copy import copy
import pytest
from openflexure_microscope_server import scan_planners
from .utilities import scan_test_helpers

View file

@ -1,9 +1,9 @@
"""Test the code that mounts static files to the server, without creating a server."""
import asyncio
import os
import shutil
import tempfile
import asyncio
import pytest
from starlette.responses import FileResponse, RedirectResponse

View file

@ -1,7 +1,7 @@
"""Test server booting and shut down."""
import os
import json
import os
from copy import deepcopy
import pytest

View file

@ -13,31 +13,31 @@ For these tests to reliably represent real behaviour the mock Things will need t
be tested for matching signatures with dynamically generated clients.
"""
from typing import Callable, Optional
import tempfile
import logging
import os
import shutil
import logging
import tempfile
from datetime import datetime
from typing import Callable, Optional
from fastapi import HTTPException
import pytest
from fastapi import HTTPException
from labthings_fastapi.exceptions import InvocationCancelledError
from openflexure_microscope_server.things.smart_scan import (
SmartScanThing,
ScanNotRunningError,
)
from openflexure_microscope_server.scan_directories import (
ScanData,
NotEnoughFreeSpaceError,
ScanData,
)
from openflexure_microscope_server.things.smart_scan import (
ScanNotRunningError,
SmartScanThing,
)
from .mock_things.mock_csm import MockCSMThing
from .mock_things.mock_autofocus import MockAutoFocusThing
from .mock_things.mock_stage import MockStageThing
from .mock_things.mock_camera import MockCameraThing
from .mock_things.mock_csm import MockCSMThing
from .mock_things.mock_stage import MockStageThing
# A global logger to pass in as an Invocation Logger
LOGGER = logging.getLogger("mock-invocation_logger")

View file

@ -1,31 +1,32 @@
"""Tests for the smart and fast stacking."""
from typing import Optional
import logging
import tempfile
from random import randint
import logging
from typing import Optional
import pytest
import numpy as np
from hypothesis import given, strategies as st
import pytest
from fastapi.testclient import TestClient
from hypothesis import given
from hypothesis import strategies as st
import labthings_fastapi as lt
from openflexure_microscope_server.scan_directories import IMAGE_REGEX
from openflexure_microscope_server.things.autofocus import (
AutofocusThing,
StackParams,
CaptureInfo,
MIN_TEST_IMAGE_COUNT,
EXTRA_STACK_CAPTURES,
MAX_TEST_IMAGE_COUNT,
MIN_TEST_IMAGE_COUNT,
AutofocusThing,
CaptureInfo,
NotAPeakError,
StackParams,
_count_turning_points,
_get_capture_by_id,
_get_capture_index_by_id,
EXTRA_STACK_CAPTURES,
NotAPeakError,
_get_peak_turning_point,
_count_turning_points,
)
from openflexure_microscope_server.scan_directories import IMAGE_REGEX
LOGGER = logging.getLogger("mock-invocation_logger")
RANDOM_GENERATOR = np.random.default_rng()

View file

@ -1,12 +1,13 @@
"""Test the stage without creating a full HTTP server and socket connection."""
import tempfile
import itertools
import tempfile
from fastapi.testclient import TestClient
import pytest
from fastapi.testclient import TestClient
from httpx import HTTPStatusError
from hypothesis import given, settings, HealthCheck, strategies as st
from hypothesis import HealthCheck, given, settings
from hypothesis import strategies as st
import labthings_fastapi as lt
from labthings_fastapi.exceptions import NotConnectedToServerError
@ -17,7 +18,6 @@ from openflexure_microscope_server.things.stage import (
)
from openflexure_microscope_server.things.stage.dummy import DummyStage
from .mock_things.mock_cancel import MockCancel
# Keep the size and number of moves fairly small or the tests can take forever

View file

@ -1,13 +1,13 @@
"""File contains unit tests for stage_measure."""
from copy import copy
import logging
import dataclasses
import logging
import tempfile
from copy import copy
from fastapi.testclient import TestClient
import numpy as np
import pytest
from fastapi.testclient import TestClient
import labthings_fastapi as lt

View file

@ -6,20 +6,20 @@ generated, and the subprocess calling works as expected.
import logging
import os
from copy import copy
import uuid
import threading
import time
import uuid
from copy import copy
import pytest
import labthings_fastapi as lt
from openflexure_microscope_server.stitching import (
BaseStitcher,
PreviewStitcher,
FinalStitcher,
STITCHING_RESOLUTION,
BaseStitcher,
FinalStitcher,
PreviewStitcher,
StitcherValidationError,
)

View file

@ -1,16 +1,16 @@
"""Tests that version strings can be produced reliably."""
import subprocess
import logging
import os
import re
import tempfile
import shutil
import subprocess
import tempfile
import warnings
import logging
import pytest
from hypothesis import strategies as st
from hypothesis.errors import NonInteractiveExampleWarning
import pytest
from openflexure_microscope_server import utilities

View file

@ -4,8 +4,8 @@ At the top level are some basic testing functions. More specific testing utiliti
provided by modules inside the package.
"""
from typing import Protocol, Iterable
from collections.abc import Hashable
from typing import Iterable, Protocol
class SizedIterableHashable(Iterable[Hashable], Protocol):

View file

@ -11,11 +11,11 @@ import os
import pickle
import numpy as np
from scipy import interpolate
from matplotlib import pyplot as plt
from matplotlib.path import Path as MatPath
from matplotlib.patches import PathPatch
from matplotlib.figure import Figure
from matplotlib.patches import PathPatch
from matplotlib.path import Path as MatPath
from scipy import interpolate
from openflexure_microscope_server import scan_planners
@ -145,8 +145,8 @@ def example_smart_spiral(
def profile_example_smart_spiral():
"""Profile running an example scan and print the cumulative profile stats."""
import pstats
import cProfile
import pstats
profiler = cProfile.Profile()
profiler.runcall(example_smart_spiral)