From fed66d78280f64e049ce5d2b55a2041905d4d11a Mon Sep 17 00:00:00 2001 From: David Hammer <dhammer@mailbox.org> Date: Thu, 10 Feb 2022 15:44:15 +0100 Subject: [PATCH] Follow some flake8 hints --- src/calng/AgipdCorrection.py | 2 -- src/calng/DsscCorrection.py | 1 - src/calng/base_correction.py | 3 +-- src/tests/problem.py | 2 ++ src/tests/test_agipd_kernels.py | 1 - src/tests/test_calcat_utils.py | 17 ++++++++--------- src/tests/test_dssc_kernels.py | 1 + src/tests/test_utils.py | 9 +++++---- 8 files changed, 17 insertions(+), 19 deletions(-) diff --git a/src/calng/AgipdCorrection.py b/src/calng/AgipdCorrection.py index c0b1d9a4..baaaa95c 100644 --- a/src/calng/AgipdCorrection.py +++ b/src/calng/AgipdCorrection.py @@ -12,7 +12,6 @@ from karabo.bound import ( OVERWRITE_ELEMENT, STRING_ELEMENT, VECTOR_STRING_ELEMENT, - State, ) from . import base_gpu, calcat_utils, utils @@ -624,7 +623,6 @@ class AgipdCorrection(BaseCorrection): self._has_updated_bad_pixel_selection = False - def _initialization(self): self._update_bad_pixel_selection() super()._initialization() diff --git a/src/calng/DsscCorrection.py b/src/calng/DsscCorrection.py index c228648a..650dcd47 100644 --- a/src/calng/DsscCorrection.py +++ b/src/calng/DsscCorrection.py @@ -7,7 +7,6 @@ from karabo.bound import ( KARABO_CLASSINFO, OVERWRITE_ELEMENT, VECTOR_STRING_ELEMENT, - State, ) from . import base_gpu, calcat_utils, utils diff --git a/src/calng/base_correction.py b/src/calng/base_correction.py index 1bfa1895..db273a91 100644 --- a/src/calng/base_correction.py +++ b/src/calng/base_correction.py @@ -1,4 +1,3 @@ -import collections import enum import gc import pathlib @@ -771,7 +770,7 @@ class BaseCorrection(PythonDevice): ) elif name.startswith("browse_schema"): if ":" in name: - prefix = name[len("browse_schema:") :] + prefix = name[len("browse_schema:"):] else: prefix = "managed" payload["data"] = scenes.recursive_subschema_scene( diff --git a/src/tests/problem.py b/src/tests/problem.py index 97c2ca2c..a9590844 100644 --- a/src/tests/problem.py +++ b/src/tests/problem.py @@ -3,6 +3,7 @@ from calng import utils calls = 0 + @utils.threadsafe_cache def will_raise_once(argument): global calls @@ -11,6 +12,7 @@ def will_raise_once(argument): raise Exception("That's just what I do") return argument + 1 + try: will_raise_once(0) except Exception as ex: diff --git a/src/tests/test_agipd_kernels.py b/src/tests/test_agipd_kernels.py index 73b776ab..8f0f9aca 100644 --- a/src/tests/test_agipd_kernels.py +++ b/src/tests/test_agipd_kernels.py @@ -1,7 +1,6 @@ import h5py import numpy as np import pathlib -import pytest from calng import AgipdCorrection diff --git a/src/tests/test_calcat_utils.py b/src/tests/test_calcat_utils.py index 4b647c80..91be20dc 100644 --- a/src/tests/test_calcat_utils.py +++ b/src/tests/test_calcat_utils.py @@ -1,5 +1,4 @@ import pathlib -import timeit from calng import AgipdCorrection, DsscCorrection from calng.utils import Stopwatch @@ -101,22 +100,22 @@ def test_agipd_constants_and_caching_and_async(): with Stopwatch() as timer_async_cold: # TODO: put this sort of thing in BaseCalcatFriend - threads = [] - for constant in AgipdCorrection.AgipdConstants: - thread = device.calibration_constant_manager.get_constant_version_and_call_me_back( + threads = [ + device.calibration_constant_manager.get_constant_version_and_call_me_back( constant, backcall ) - threads.append(thread) + for constant in AgipdCorrection.AgipdConstants + ] for thread in threads: thread.join() with Stopwatch() as timer_async_warm: - threads = [] - for constant in AgipdCorrection.AgipdConstants: - thread = device.calibration_constant_manager.get_constant_version_and_call_me_back( + threads = [ + device.calibration_constant_manager.get_constant_version_and_call_me_back( constant, backcall ) - threads.append(thread) + for constant in AgipdCorrection.AgipdConstants + ] for thread in threads: thread.join() diff --git a/src/tests/test_dssc_kernels.py b/src/tests/test_dssc_kernels.py index 95c3ec55..8277ae25 100644 --- a/src/tests/test_dssc_kernels.py +++ b/src/tests/test_dssc_kernels.py @@ -18,6 +18,7 @@ raw_data = np.random.randint( low=0, high=2000, size=(memory_cells, pixels_y, pixels_x), dtype=input_dtype ) + # TODO: gather CPU implementations elsewhere def correct_cpu(data, cell_table, offset_map): corr = np.squeeze(data).astype(corr_dtype, copy=True) diff --git a/src/tests/test_utils.py b/src/tests/test_utils.py index 91b1f280..ebe7d640 100644 --- a/src/tests/test_utils.py +++ b/src/tests/test_utils.py @@ -48,7 +48,7 @@ class TestThreadsafeCache: assert len(calls) == 1, "omitting default args doesn't matter" def test_threadsafeness(self): - # wow, synchronization (presumably) makes this take forever *without* the decorator... + # wow, synchronization (presumably) makes this take forever *without* decorator from_was_called = [] base_sleep = 1 @@ -64,8 +64,8 @@ class TestThreadsafeCache: letters = "abcd" start_ts = timeit.default_timer() for i in range(num_threads): - for l in letters: - thread = threading.Thread(target=was_called, args=(l,)) + for letter in letters: + thread = threading.Thread(target=was_called, args=(letter,)) thread.start() threads.append(thread) submitted_ts = timeit.default_timer() @@ -85,7 +85,8 @@ class TestThreadsafeCache: letters ), "Caching prevents recomputation due to threading" - # check that the function was not locked too broadly (should run faster than sequential lower bound) + # check that the function was not locked too broadly + # (should run faster than sequential lower bound) reasonable_time_to_spawn_thread = 0.45 / 1000 cutoff = ( len(letters) * base_sleep + reasonable_time_to_spawn_thread * num_threads -- GitLab