Added basic unit tests of non-integrated functions

This commit is contained in:
Joel Collins 2020-11-25 15:25:17 +00:00
parent f54684b460
commit 5137d1b9dc
7 changed files with 228 additions and 46 deletions

View file

@ -33,7 +33,7 @@ def construct_grid(initial, step_sizes, n_steps, style="raster"):
if style == "spiral":
# deal with the centre image immediately
coord = initial
arr.append(initial)
arr.append([initial])
# for spiral, n_steps is the number of shells, and so only requires n_steps[0]
for i in range(2, n_steps[0] + 1):
arr.append([])
@ -66,16 +66,6 @@ def construct_grid(initial, step_sizes, n_steps, style="raster"):
return arr
def flatten_grid(grid):
"""
Convert a 3D list of scan positions into a flat list
of sequential positions.
"""
grid = list(itertools.chain(*grid))
return grid
### Capturing

View file

@ -26,7 +26,7 @@ class Timer(object):
def deserialise_array_b64(b64_string, dtype, shape):
flat_arr = np.fromstring(base64.b64decode(b64_string), dtype)
flat_arr = np.frombuffer(base64.b64decode(b64_string), dtype)
return flat_arr.reshape(shape)
@ -106,16 +106,6 @@ def axes_to_array(
return base_array
def filter_dict(dictionary: dict, keys: list):
# Get value by recursively applying getitem
val = reduce(operator.getitem, keys, dictionary)
# Create new dictionary by running reduce on key, val pairs
out = reduce(lambda x, y: {y: x}, reversed(keys), val)
return out
def entry_by_uuid(entry_id: str, object_list: list):
"""Return an object from a list, if <object>.id matches id argument."""
found = None
@ -132,26 +122,3 @@ def entry_by_uuid(entry_id: str, object_list: list):
if converter(o.id) == converter(entry_id):
found = o
return found
def recursively_apply(data, func):
"""
Recursively apply a function to a dictionary, list, array, or tuple
Args:
data: Input iterable data
func: Function to apply to all non-iterable values
"""
# If the object is a dictionary
if isinstance(data, abc.Mapping):
return {key: recursively_apply(val, func) for key, val in data.items()}
# If the object is iterable but NOT a dictionary or a string
elif (
isinstance(data, abc.Iterable)
and not isinstance(data, abc.Mapping)
and not isinstance(data, str)
):
return [recursively_apply(x, func) for x in data]
# if the object is neither a map nor iterable
else:
return func(data)