Starting docstring on the same lines as the quotations

This commit is contained in:
Julian Stirling 2025-07-10 01:04:26 +01:00
parent be6a6ca6fe
commit 35d47fe3ed
28 changed files with 92 additions and 214 deletions

View file

@ -1,6 +1,4 @@
"""
Tests for the built in buffer for the camera.
"""
"""Tests for the built in buffer for the camera."""
from random import randint

View file

@ -156,9 +156,7 @@ def test_basic_directory_operations():
def test_scan_sequence_and_listing():
"""
Check created scans are added in order and listed correctly
"""
"""Check created scans are added in order and listed correctly"""
_clear_scan_dir()
scan_dir_manager = ScanDirectoryManager(BASE_SCAN_DIR)
# Make 4 scans
@ -185,8 +183,7 @@ def test_scan_sequence_and_listing():
def test_scan_name_non_sequential():
"""
Check created scans is the correct name if the directories
"""Check created scans is the correct name if the directories
are not sequential
"""
_clear_scan_dir()
@ -213,9 +210,7 @@ def test_scan_name_non_sequential():
def test_all_scan_names_taken():
"""
If the next sequential scan name needs more than 4 digits check error is thrown.
"""
"""If the next sequential scan name needs more than 4 digits check error is thrown."""
_clear_scan_dir()
os.makedirs(os.path.join(BASE_SCAN_DIR, "fake_scan_9999"))
scan_dir_manager = ScanDirectoryManager(BASE_SCAN_DIR)
@ -224,9 +219,7 @@ def test_all_scan_names_taken():
def test_no_scan_names_given():
"""
Check correct default scan name is used if empty string is given
"""
"""Check correct default scan name is used if empty string is given"""
_clear_scan_dir()
scan_dir_manager = ScanDirectoryManager(BASE_SCAN_DIR)
scan_dir = scan_dir_manager.new_scan_dir("")

View file

@ -222,8 +222,7 @@ def test_mark_wrong_location():
def test_closest_focus_wth_large_numbers():
"""
The number of steps gets very large in reality runs some tests to check
"""The number of steps gets very large in reality runs some tests to check
that everything works well with huge numbers of steps
"""
intial_position = (0, 0)

View file

@ -1,5 +1,4 @@
"""
Test the SmartScanThing *without* connecting it to a LabThings Server.
"""Test the SmartScanThing *without* connecting it to a LabThings Server.
By testing without connecting to the LabThings server it is possible to
directly poll any properties and to start any methods.
@ -151,8 +150,7 @@ def test_delete_all_scans(smart_scan_thing, caplog):
def _run_only_outer_scan(adjust_inital_state: Optional[Callable] = None):
"""
Create a subclass of SmartScanThing to mock _run_scan and run sample_scan
"""Create a subclass of SmartScanThing to mock _run_scan and run sample_scan
This should do all the set up for a scan, move into the mocked
_run_scan method where this can be tested. Once this is done

View file

@ -1,5 +1,4 @@
"""
Tests for the smart/fast stacking.
"""Tests for the smart/fast stacking.
Currently these tests don't test the Thing itself, just surrounding functionality
"""
@ -146,8 +145,7 @@ def test_even_images_to_save(save_ims, extra_ims):
def test_computed_stack_params():
"""
Test StackParams computed properties are as expected
"""Test StackParams computed properties are as expected
Not using hypothesis or we will just copy in the same formulas.
"""
@ -188,8 +186,7 @@ def test_computed_stack_params():
def random_capture(set_id: Optional[int] = None):
"""
Create a capture with random values
"""Create a capture with random values
:param set_id: Optional, use to set a fixed id rather than a random one
"""
@ -206,18 +203,14 @@ def random_capture(set_id: Optional[int] = None):
def test_capture_filename_matches_regex():
"""
For 100 random captures check the image always matches the regex
"""
"""For 100 random captures check the image always matches the regex"""
for _ in range(100):
assert IMAGE_REGEX.search(random_capture().filename)
@given(st.integers(min_value=0, max_value=5000))
def test_retrieval_of_captures(start):
"""
For 20 random captures, check each can be retrieved correctly by id
"""
"""For 20 random captures, check each can be retrieved correctly by id"""
captures = [random_capture(start + i) for i in range(20)]
for i, capture in enumerate(captures):

View file

@ -1,5 +1,4 @@
"""
Utilities for testing and debugging.
"""Utilities for testing and debugging.
At the top level are some basic testing functions. More specific testing utilities are
provided by modules inside the package.

View file

@ -14,21 +14,18 @@ THIS_DIR = os.path.dirname(os.path.realpath(__file__))
class FakeSample:
"""
A fake sample to test scan algorithms. The sample is able to return
"""A fake sample to test scan algorithms. The sample is able to return
whether a given position is sample, no image associated with the sample
"""
def __init__(self, xy_points: list[tuple[int, int]]):
"""
Create the sample from a spline interpolation around
"""Create the sample from a spline interpolation around
the given points.
"""
self._sample_perimeter = interp_closed_path(xy_points, 500)
def is_sample(self, pos: tuple[int, int], im_size: tuple[int, int]) -> bool:
"""
Return whether an image at a given location with a given image size
"""Return whether an image at a given location with a given image size
is on the sample
This doesn't check the entire image field as this is designed to be used
@ -47,18 +44,14 @@ class FakeSample:
@property
def patch(self) -> PathPatch:
"""
The sample as a matplotlib patch for plotting
"""
"""The sample as a matplotlib patch for plotting"""
patch = PathPatch(self._sample_perimeter)
patch.set(color=(1.0, 0.8, 1.0, 1.0))
return patch
def visualise_scan(sample: FakeSample, planner: scan_planners.ScanPlanner) -> Figure:
"""
For a given sample and scanner object return a matplotlib figure of the scan
"""
"""For a given sample and scanner object return a matplotlib figure of the scan"""
fig, ax = plt.subplots(figsize=(8, 8))
ax.add_artist(sample.patch)
xh, yh = zip(*planner._path_history)
@ -84,8 +77,7 @@ def visualise_scan(sample: FakeSample, planner: scan_planners.ScanPlanner) -> Fi
def interp_closed_path(xy_points: list[tuple[int, int]], n_points: int) -> MatPath:
"""
Given a lists of xy_points interpolate an n_point closed curve. This can be used
"""Given a lists of xy_points interpolate an n_point closed curve. This can be used
to create an arbitrary sample shape plan a scan.
Modified from:
@ -113,8 +105,7 @@ def interp_closed_path(xy_points: list[tuple[int, int]], n_points: int) -> MatPa
def example_smart_spiral(
sample_name: str = "lobed",
) -> tuple[FakeSample, scan_planners.ScanPlanner]:
"""
Run an example scan and return the sample scanned and the planner object
"""Run an example scan and return the sample scanned and the planner object
after scan is complete
"""
xy_sample_points = load_sample_points(sample_name)
@ -135,8 +126,7 @@ def example_smart_spiral(
def profile_and_save_plot_for_example_smart_spiral():
"""
Run the example scan and save a plot and the profile data
"""Run the example scan and save a plot and the profile data
Also print the cumulative stats
@ -162,8 +152,7 @@ def profile_and_save_plot_for_example_smart_spiral():
def update_example_smart_spiral_pickle(sample_name: str):
"""
Pickle the ScanPlanner for the example_smart_spiral(),
"""Pickle the ScanPlanner for the example_smart_spiral(),
this is done so the history can be compared by testing to check
the algorithm is unchanged.
@ -182,8 +171,7 @@ def update_example_smart_spiral_pickle(sample_name: str):
def get_expected_result_for_example_smart_spiral(
sample_name: str,
) -> scan_planners.ScanPlanner:
"""
Return the expected ScanPlanner object for the example_smart_spiral(),
"""Return the expected ScanPlanner object for the example_smart_spiral(),
this is pickled, so that it can be committed.
"""
pkl_fname = os.path.join(THIS_DIR, f"example_smart_spiral_{sample_name}.pkl")