def test_cleanup(self): channel_pair = TaborChannelPair(self.instrument, identifier='asd', channels=(1, 2)) self.instrument.paranoia_level = 0 self.reset_instrument_logs() channel_pair._segment_references = np.array([1, 2, 0, 1], dtype=np.uint32) channel_pair._segment_capacity = 192 + np.array([0, 16, 32, 32], dtype=np.uint32) channel_pair._segment_lengths = 192 + np.array([0, 0, 16, 16], dtype=np.uint32) channel_pair._segment_hashes = np.array([1, 2, 3, 4], dtype=np.int64) channel_pair.cleanup() np.testing.assert_equal(channel_pair._segment_references, np.array([1, 2, 0, 1], dtype=np.uint32)) np.testing.assert_equal( channel_pair._segment_capacity, 192 + np.array([0, 16, 32, 32], dtype=np.uint32)) np.testing.assert_equal( channel_pair._segment_lengths, 192 + np.array([0, 0, 16, 16], dtype=np.uint32)) np.testing.assert_equal(channel_pair._segment_hashes, np.array([1, 2, 3, 4], dtype=np.int64)) channel_pair._segment_references = np.array([1, 2, 0, 1, 0], dtype=np.uint32) channel_pair._segment_capacity = 192 + np.array([0, 16, 32, 32, 32], dtype=np.uint32) channel_pair._segment_lengths = 192 + np.array([0, 0, 16, 16, 0], dtype=np.uint32) channel_pair._segment_hashes = np.array([1, 2, 3, 4, 5], dtype=np.int64) channel_pair.cleanup() np.testing.assert_equal(channel_pair._segment_references, np.array([1, 2, 0, 1], dtype=np.uint32)) np.testing.assert_equal( channel_pair._segment_capacity, 192 + np.array([0, 16, 32, 32], dtype=np.uint32)) np.testing.assert_equal( channel_pair._segment_lengths, 192 + np.array([0, 0, 16, 16], dtype=np.uint32)) np.testing.assert_equal(channel_pair._segment_hashes, np.array([1, 2, 3, 4], dtype=np.int64))
def test_remove(self): channel_pair = TaborChannelPair(self.instrument, identifier='asd', channels=(1, 2)) calls = [] program_name = 'test' def dummy_free_program(name): self.assertIs(name, program_name) calls.append('free_program') def dummy_cleanup(): calls.append('cleanup') channel_pair.cleanup = dummy_cleanup channel_pair.free_program = dummy_free_program channel_pair.remove(program_name) self.assertEqual(calls, ['free_program', 'cleanup'])