def test_await(self): latch = CountUpDownLatch() latch._lock = MagicMock() # Simulate a count down when the wait is called. latch._lock.wait = MagicMock(side_effect=latch.count_down) latch.await() # This should be a no-op as count is 0. latch.count_up() latch.await() # This should call the wait method latch._lock.wait.assert_called_once_with()
def test_await(self): latch = CountUpDownLatch() latch._lock = MagicMock() # Simulate a count down when the wait is called. latch._lock.wait = MagicMock(side_effect=latch.count_down) latch. await () # This should be a no-op as count is 0. latch.count_up() latch. await () # This should call the wait method latch._lock.wait.assert_called_once_with()
def test_count(self): """ Test that count is updated and decremented correctly """ latch = CountUpDownLatch() latch._lock = MagicMock() self.assertEqual(latch.count, 0) self.assertRaises(ValueError, latch.count_down) latch.count_up() self.assertEqual(latch.count, 1) latch.count_down() self.assertEqual(latch.count, 0) latch._lock.notifyAll.assert_called_once_with()