def test_lock_detach(self): """ Test that detach closes all acquired locks. """ sut = LockingProcessor(key='test_lockpath') insert = { 'inserts': ['a'], 'deletes': [], 'data': { 'a': { 'test_lockpath': '/path/to/some/file.txt.lck' } } } lock_mock = Mock(spec=_Lockfile) # Acquire lock expected = copy.deepcopy(insert) matches = MatchesSendDeltaItemInvocation(expected, sut.out_locked) send = Mock(spec=Scheduler.send) with patch('spreadflow_delta.proc._Lockfile.open', return_value=lock_mock) as open_mock: sut(insert, send) self.assertEquals(send.call_count, 1) self.assertThat(send.call_args, matches) open_mock.assert_called_once_with('/path/to/some/file.txt.lck') self.assertEquals(lock_mock.close.call_count, 0) # Call detach sut.detach() lock_mock.close.assert_called_once_with()