From c489b8766338fae659ea618a6b599d26b19b3885 Mon Sep 17 00:00:00 2001 From: dpohl <pohl@physik.uni-bonn.de> Date: Wed, 18 Nov 2020 11:47:12 +0100 Subject: [PATCH] ENH: make sure mock is reset --- .../base/test_shift_and_inject.py | 41 ++++++++++--------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/bdaq53/tests/test_software/base/test_shift_and_inject.py b/bdaq53/tests/test_software/base/test_shift_and_inject.py index 8172ab06b..eda2b02d8 100644 --- a/bdaq53/tests/test_software/base/test_shift_and_inject.py +++ b/bdaq53/tests/test_software/base/test_shift_and_inject.py @@ -162,26 +162,27 @@ class TestShiftInject(unittest.TestCase): def store_cmd(cmd, repetitions=100): cmds.extend(cmd) - with mock.patch('bdaq53.chips.rd53a.RD53A.write_command', side_effect=store_cmd): - with DigitalScan(self.scan_configuration, bench_config=self.bench_config) as scan: - scan.configure() - cmds = [] # Reset command list, since only insterested in commands sent during scan for this test - scan.scan() - cmds_old = cmds.copy() - - cmds = [] - with DigitalScan(self.scan_configuration, bench_config=self.bench_config) as scan: - self.chip = scan.chip - scan._scan = self.old_scan_loop_digital - scan.configure() - cmds = [] # Reset command list, since only insterested in commands sent during scan for this test - scan.scan() - - # Use numpy arrays with data since they can be checked for equality much faster - a, b = np.array(cmds_old, dtype=np.int16), np.array(cmds, dtype=np.int16) - self.assertTrue(np.array_equal(a, b)) - - bhm.stop() + try: + with mock.patch('bdaq53.chips.rd53a.RD53A.write_command', side_effect=store_cmd): + with DigitalScan(self.scan_configuration, bench_config=self.bench_config) as scan: + scan.configure() + cmds = [] # Reset command list, since only insterested in commands sent during scan for this test + scan.scan() + cmds_old = cmds.copy() + + cmds = [] + with DigitalScan(self.scan_configuration, bench_config=self.bench_config) as scan: + self.chip = scan.chip + scan._scan = self.old_scan_loop_digital + scan.configure() + cmds = [] # Reset command list, since only insterested in commands sent during scan for this test + scan.scan() + + # Use numpy arrays with data since they can be checked for equality much faster + a, b = np.array(cmds_old, dtype=np.int16), np.array(cmds, dtype=np.int16) + self.assertTrue(np.array_equal(a, b)) + finally: + bhm.stop() def test_shift_inject_loop_rd53a(self): ''' Test if new shift and inject function sends the same commands as old one, in case of RD53A ''' -- GitLab