Add punctuation to docstrings
This commit is contained in:
parent
4dc41bb008
commit
80beeea07b
34 changed files with 232 additions and 235 deletions
|
|
@ -13,5 +13,5 @@ class MockAutoFocusThing:
|
|||
mock_call_count = {"looping_autofocus": 0}
|
||||
|
||||
def looping_autofocus(self, dz: int = 2000, start: str = "centre") -> None: # noqa: ARG002
|
||||
"""Mock autofocus with no return"""
|
||||
"""Mock autofocus with no return."""
|
||||
self.mock_call_count["looping_autofocus"] += 1
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ RANDOM_GENERATOR = np.random.default_rng()
|
|||
|
||||
|
||||
def random_image():
|
||||
"""Create a random image"""
|
||||
"""Create a random image."""
|
||||
imarray = RANDOM_GENERATOR.integers(
|
||||
low=0, high=255, size=(100, 100, 3), dtype="uint8"
|
||||
)
|
||||
|
|
@ -24,14 +24,14 @@ def random_image():
|
|||
|
||||
|
||||
def random_metadata():
|
||||
"""Create a misc dictionary to pretend to be metadata"""
|
||||
"""Create a misc dictionary to pretend to be metadata."""
|
||||
# Not very metadata like, but we are just checking that the same dict it
|
||||
# is returned
|
||||
return {"a": randint(1, 100), "b": randint(1, 100)}
|
||||
|
||||
|
||||
def test_add_and_get_image():
|
||||
"""Check images can be captured and retrieved"""
|
||||
"""Check images can be captured and retrieved."""
|
||||
mem_buf = CameraMemoryBuffer()
|
||||
misc_image = random_image()
|
||||
buffer_id = mem_buf.add_image(misc_image)
|
||||
|
|
@ -44,7 +44,7 @@ def test_add_and_get_image():
|
|||
|
||||
|
||||
def test_add_and_get_image_twice():
|
||||
"""Check images can be retrieved twice if remove flag set false"""
|
||||
"""Check images can be retrieved twice if remove flag set false."""
|
||||
mem_buf = CameraMemoryBuffer()
|
||||
misc_image = random_image()
|
||||
buffer_id = mem_buf.add_image(misc_image)
|
||||
|
|
@ -60,7 +60,7 @@ def test_add_and_get_image_twice():
|
|||
|
||||
|
||||
def test_get_without_id():
|
||||
"""Check images can be captured and retrieved without ID"""
|
||||
"""Check images can be captured and retrieved without ID."""
|
||||
mem_buf = CameraMemoryBuffer()
|
||||
misc_image = random_image()
|
||||
mem_buf.add_image(misc_image)
|
||||
|
|
@ -92,7 +92,7 @@ def test_get_two_images():
|
|||
|
||||
|
||||
def test_get_two_images_without_setting_buffer_size():
|
||||
"""Check two images can't be retrieved if the buffer size isn't set"""
|
||||
"""Check two images can't be retrieved if the buffer size isn't set."""
|
||||
mem_buf = CameraMemoryBuffer()
|
||||
misc_image1 = random_image()
|
||||
misc_image2 = random_image()
|
||||
|
|
@ -106,7 +106,7 @@ def test_get_two_images_without_setting_buffer_size():
|
|||
|
||||
|
||||
def test_buffer_size_changing():
|
||||
"""Check buffer size resets back to 1 when if not set"""
|
||||
"""Check buffer size resets back to 1 when if not set."""
|
||||
mem_buf = CameraMemoryBuffer()
|
||||
misc_image1 = random_image()
|
||||
misc_image2 = random_image()
|
||||
|
|
@ -126,7 +126,7 @@ def test_buffer_size_changing():
|
|||
|
||||
|
||||
def test_capture_two_images_get_without_id():
|
||||
"""Check that all images are deleted when getting without id"""
|
||||
"""Check that all images are deleted when getting without id."""
|
||||
mem_buf = CameraMemoryBuffer()
|
||||
misc_image1 = random_image()
|
||||
misc_image2 = random_image()
|
||||
|
|
@ -142,7 +142,7 @@ def test_capture_two_images_get_without_id():
|
|||
|
||||
|
||||
def test_buffer_size_respected():
|
||||
"""Capture 10 images with a buffer size of 5. Check only last 5 exist"""
|
||||
"""Capture 10 images with a buffer size of 5. Check only last 5 exist."""
|
||||
mem_buf = CameraMemoryBuffer()
|
||||
|
||||
images = []
|
||||
|
|
@ -163,7 +163,7 @@ def test_buffer_size_respected():
|
|||
|
||||
|
||||
def test_clear_buffer():
|
||||
"""Capture 10 images clear the buffer and check they are gone"""
|
||||
"""Capture 10 images clear the buffer and check they are gone."""
|
||||
mem_buf = CameraMemoryBuffer()
|
||||
|
||||
images = []
|
||||
|
|
@ -184,7 +184,7 @@ def test_clear_buffer():
|
|||
|
||||
|
||||
def test_get_metadata_too():
|
||||
"""Capture 10 images with metadata and check metadata is returned as expected"""
|
||||
"""Capture 10 images with metadata and check metadata is returned as expected."""
|
||||
mem_buf = CameraMemoryBuffer()
|
||||
|
||||
images = []
|
||||
|
|
|
|||
|
|
@ -28,13 +28,13 @@ BASE_SCAN_DIR = os.path.join(tempfile.gettempdir(), "scans")
|
|||
|
||||
|
||||
def _clear_scan_dir() -> None:
|
||||
"""Delete the scan dir"""
|
||||
"""Delete the scan dir."""
|
||||
if os.path.exists(BASE_SCAN_DIR):
|
||||
shutil.rmtree(BASE_SCAN_DIR)
|
||||
|
||||
|
||||
def _add_fake_image(scan_dir: ScanDirectory) -> None:
|
||||
"""Make a fake image on disk in the scan directory"""
|
||||
"""Make a fake image on disk in the scan directory."""
|
||||
unique = False
|
||||
while not unique:
|
||||
x_pos = random.randint(-10000, 10000)
|
||||
|
|
@ -63,7 +63,7 @@ def _add_fake_file(
|
|||
|
||||
|
||||
def _make_fake_dzi(scan_dir: ScanDirectory, n_layers: int = 8) -> None:
|
||||
"""Create a fake DZI in a scan
|
||||
"""Create a fake DZI in a scan.
|
||||
|
||||
:param n_layers: The number of layers of tiles. I.e. tile directories numbered
|
||||
0...(n_layers-1) will be created. Default 8
|
||||
|
|
@ -96,7 +96,7 @@ def _make_fake_dzi(scan_dir: ScanDirectory, n_layers: int = 8) -> None:
|
|||
|
||||
|
||||
def test_basic_directory_operations():
|
||||
"""Test some basic operations
|
||||
"""Test some basic operations.
|
||||
|
||||
Test some basic operations, including:
|
||||
- ScanDirectoryManager creates a scan directory
|
||||
|
|
@ -156,7 +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
|
||||
|
|
@ -183,7 +183,7 @@ def test_scan_sequence_and_listing():
|
|||
|
||||
|
||||
def test_scan_name_non_sequential():
|
||||
"""Check new scan has the correct name if the directories are not sequential"""
|
||||
"""Check new scan has the correct name if the directories are not sequential."""
|
||||
_clear_scan_dir()
|
||||
os.makedirs(os.path.join(BASE_SCAN_DIR, "fake_scan_0001"))
|
||||
os.makedirs(os.path.join(BASE_SCAN_DIR, "fake_scan_0002"))
|
||||
|
|
@ -217,7 +217,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("")
|
||||
|
|
@ -225,7 +225,7 @@ def test_no_scan_names_given():
|
|||
|
||||
|
||||
def test_scan_info():
|
||||
"""Test the scan info is correct even using fake scan data"""
|
||||
"""Test the scan info is correct even using fake scan data."""
|
||||
_clear_scan_dir()
|
||||
scan_dir_manager = ScanDirectoryManager(BASE_SCAN_DIR)
|
||||
scan_dir = scan_dir_manager.new_scan_dir("fake_scan")
|
||||
|
|
@ -252,7 +252,7 @@ def test_scan_info():
|
|||
|
||||
|
||||
def test_get_final_stitch():
|
||||
"""Check that the final stitch can be retrieved"""
|
||||
"""Check that the final stitch can be retrieved."""
|
||||
_clear_scan_dir()
|
||||
scan_dir_manager = ScanDirectoryManager(BASE_SCAN_DIR)
|
||||
scan_dir = scan_dir_manager.new_scan_dir("fake_scan")
|
||||
|
|
@ -280,7 +280,7 @@ def test_get_final_stitch():
|
|||
|
||||
|
||||
def test_empty_scan_info():
|
||||
"""Test the scan info is correct even if the scan is empty"""
|
||||
"""Test the scan info is correct even if the scan is empty."""
|
||||
_clear_scan_dir()
|
||||
scan_dir_manager = ScanDirectoryManager(BASE_SCAN_DIR)
|
||||
scan_dir = scan_dir_manager.new_scan_dir("fake_scan")
|
||||
|
|
@ -298,7 +298,7 @@ def test_empty_scan_info():
|
|||
|
||||
|
||||
def test_zipping_scan_data():
|
||||
"""Test zipping the scan images with fake image data"""
|
||||
"""Test zipping the scan images with fake image data."""
|
||||
# Run twice, once calling the ScanDirectory directly,
|
||||
# Once calling the ScanDirectoryManager
|
||||
for caller in ["scan_dir", "manager"]:
|
||||
|
|
@ -338,7 +338,7 @@ def test_zipping_scan_data():
|
|||
|
||||
|
||||
def test_all_files():
|
||||
"""Test all_files returns the path, and respects skipped directories"""
|
||||
"""Test all_files returns the path, and respects skipped directories."""
|
||||
_clear_scan_dir()
|
||||
scan_dir_manager = ScanDirectoryManager(BASE_SCAN_DIR)
|
||||
scan_dir = scan_dir_manager.new_scan_dir("fake_scan")
|
||||
|
|
@ -393,7 +393,7 @@ def test_none_returned_for_missing_images_dir():
|
|||
|
||||
|
||||
def test_extracting_files():
|
||||
"""Test the private _find_files method of ScanDirectories
|
||||
"""Test the private _find_files method of ScanDirectories.
|
||||
|
||||
Add files to directory and check expected returns.
|
||||
"""
|
||||
|
|
@ -445,7 +445,7 @@ DiskUsage = namedtuple("DiskUsage", ["total", "used", "free"])
|
|||
|
||||
@pytest.mark.parametrize("free_space", [500_000_001, 700_000_000, 5_000_000_000])
|
||||
def test_disk_not_full(mocker, free_space):
|
||||
"""Check no error thrown if disk has over 500MB of space"""
|
||||
"""Check no error thrown if disk has over 500MB of space."""
|
||||
total_space = 16_000_000_000
|
||||
# Mock the disk_usage
|
||||
mocker.patch(
|
||||
|
|
@ -461,7 +461,7 @@ def test_disk_not_full(mocker, free_space):
|
|||
|
||||
@pytest.mark.parametrize("free_space", [100_000_000, 499_999_999])
|
||||
def test_disk_full(mocker, free_space):
|
||||
"""Check error thrown if disk has under 500MB of space"""
|
||||
"""Check error thrown if disk has under 500MB of space."""
|
||||
total_space = 16_000_000_000
|
||||
# Mock the disk_usage
|
||||
mocker.patch(
|
||||
|
|
|
|||
|
|
@ -41,14 +41,14 @@ SCAN_DIR = os.path.join(tempfile.gettempdir(), "scans")
|
|||
|
||||
|
||||
def _clear_scan_dir() -> None:
|
||||
"""Delete the scan dir"""
|
||||
"""Delete the scan dir."""
|
||||
if os.path.exists(SCAN_DIR):
|
||||
shutil.rmtree(SCAN_DIR)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def smart_scan_thing():
|
||||
"""Return a smart scan thing as a fixture"""
|
||||
"""Return a smart scan thing as a fixture."""
|
||||
return SmartScanThing(SCAN_DIR)
|
||||
|
||||
|
||||
|
|
@ -75,7 +75,7 @@ def test_inaccessible_scan_methods(smart_scan_thing):
|
|||
|
||||
|
||||
def test_private_delete_scan(smart_scan_thing, caplog):
|
||||
"""Test the private _delete_scan method deletes directories or warns if it can't"""
|
||||
"""Test the private _delete_scan method deletes directories or warns if it can't."""
|
||||
_clear_scan_dir()
|
||||
with caplog.at_level(logging.INFO):
|
||||
fake_scan_name = "fake_scan_0001"
|
||||
|
|
@ -101,7 +101,7 @@ def test_private_delete_scan(smart_scan_thing, caplog):
|
|||
|
||||
|
||||
def test_public_delete_scan(smart_scan_thing, caplog):
|
||||
"""Test the delete_scan API call deletes directories or warns if it can't"""
|
||||
"""Test the delete_scan API call deletes directories or warns if it can't."""
|
||||
_clear_scan_dir()
|
||||
with caplog.at_level(logging.INFO):
|
||||
fake_scan_name = "fake_scan_0001"
|
||||
|
|
@ -152,7 +152,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
|
||||
|
|
|
|||
|
|
@ -90,7 +90,7 @@ def test_stack_params_not_enough_test_images(save_ims, extra_ims):
|
|||
extra_ims=even_integers(min_value=0, max_value=10),
|
||||
)
|
||||
def test_stack_params_negative_images_to_save(save_ims, extra_ims):
|
||||
"""save_ims is negative so images_to_save is negative, failing validation
|
||||
"""save_ims is negative so images_to_save is negative, failing validation.
|
||||
|
||||
For arguments see test_stack_params_validation
|
||||
"""
|
||||
|
|
@ -110,7 +110,7 @@ def test_stack_params_negative_images_to_save(save_ims, extra_ims):
|
|||
extra_ims=odd_integers(min_value=0, max_value=10),
|
||||
)
|
||||
def test_even_min_images_to_test(save_ims, extra_ims):
|
||||
"""extra_ims is odd so min_images_to_test is even, failing validation
|
||||
"""extra_ims is odd so min_images_to_test is even, failing validation.
|
||||
|
||||
For arguments see test_stack_params_validation
|
||||
"""
|
||||
|
|
@ -130,7 +130,7 @@ def test_even_min_images_to_test(save_ims, extra_ims):
|
|||
extra_ims=odd_integers(min_value=0, max_value=10),
|
||||
)
|
||||
def test_even_images_to_save(save_ims, extra_ims):
|
||||
"""save_ims is even so images_to_save is even, failing validation
|
||||
"""save_ims is even so images_to_save is even, failing validation.
|
||||
|
||||
For arguments see test_stack_params_validation
|
||||
"""
|
||||
|
|
@ -146,7 +146,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.
|
||||
"""
|
||||
|
|
@ -187,7 +187,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
|
||||
"""
|
||||
|
|
@ -204,14 +204,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):
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ from collections.abc import Hashable
|
|||
|
||||
|
||||
class SizedIterableHashable(Iterable[Hashable], Protocol):
|
||||
"""A protocol for sized iterable of hashable objects"""
|
||||
"""A protocol for sized iterable of hashable objects."""
|
||||
|
||||
def __len__(self) -> int:
|
||||
"""Add a len function to protocol so Python knows the object is sized."""
|
||||
|
|
|
|||
|
|
@ -44,14 +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)
|
||||
|
|
@ -184,7 +184,7 @@ def get_expected_result_for_example_smart_spiral(
|
|||
|
||||
|
||||
def load_sample_points(sample_name: str):
|
||||
"""Return the points to generate the FakeSample corresponding to the given input name
|
||||
"""Return the points to generate the FakeSample corresponding to the given input name.
|
||||
|
||||
Options are "lobed", "regular", and "core".
|
||||
"""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue