Apply suggestions from code review of branch dont-mutate-tuning-files

Co-authored-by: Joe Knapper <joe.knapper@glasgow.ac.uk>
This commit is contained in:
Julian Stirling 2025-10-29 12:47:38 +00:00
parent e9c912d910
commit 7d583dcf94
2 changed files with 14 additions and 7 deletions

View file

@ -17,11 +17,11 @@ def camera_test_client(
): ):
"""Yield a camera ThingClient on a camera server. """Yield a camera ThingClient on a camera server.
This is a context manager not a pytest fixture as it needs to be created This is a context manager, not a pytest fixture, as it needs to be created
multiple times in some tests. multiple times in some tests.
:param cam: The camera Thing to be used. If not supplied a new one will be created. :param cam: The camera Thing to be used. If not supplied a new one will be created.
:param settings_folder: The settings folder for the camera, if none is supplies new :param settings_folder: The settings folder for the camera, if none is supplied, new
temporary directory will be used as the settings folder. temporary directory will be used as the settings folder.
""" """
if cam is None: if cam is None:

View file

@ -36,14 +36,21 @@ def find_tuning_algo(tuning: dict[str, dict], name: str) -> dict[str, Any]:
it can be tested independently of installing picamera2 it can be tested independently of installing picamera2
:param tuning: The camera tuning dictionary :param tuning: The camera tuning dictionary
:param name: The name of the algorithm :param name: The key for the algorithm in the tuning file
:return: The algorithm from the tuning dictionary. Editing this will edit the :return: The algorithm from the tuning dictionary. Editing this will edit the
original dictionary. original dictionary.
""" """
version = tuning.get("version", 1) version = tuning.get("version", 1)
# Version 1 of the tuning files was simply a dictionary of algorithms. Later
# versions have an "algorithms" key, the value of which is a list of algorithms.
if version == 1: if version == 1:
return tuning[name] return tuning[name]
return next(algo for algo in tuning["algorithms"] if name in algo)[name] # The tuning file "algorithms" is a list of dictionaries
algorithms = tuning["algorithms"]
# The list is a list of dictionaries that have 1 key: the algorithm name
algo_dict = next(algo for algo in algorithms if name in algo)
# We want the value for that key, which is a dictionary of algorithm parameters
return algo_dict[name]
def set_static_lst( def set_static_lst(
@ -136,8 +143,8 @@ def set_ce_to_disabled(
) -> dict: ) -> dict:
"""Set ``ce_enable`` in ``rpi.contrast`` to zero to disable adaptive contrast enhancement. """Set ``ce_enable`` in ``rpi.contrast`` to zero to disable adaptive contrast enhancement.
:param tuning: The raspberry pi tuning file. :param tuning: The raspberry pi camera tuning file.
:returns: A deepcopu of the input file set ce_enable to 0. :returns: A deepcopy of the input file with ce_enable set to 0.
""" """
output_tuning = deepcopy(tuning) output_tuning = deepcopy(tuning)
contrast = find_tuning_algo(output_tuning, "rpi.contrast") contrast = find_tuning_algo(output_tuning, "rpi.contrast")