class TestRateStat(TestCase): def setUp(self): super(TestRateStat, self).setUp() self.stat = RateStat("foo") def test_string_no_data(self): with patch("calico.stats.monotonic_time", autospec=True) as m_time: m_time.return_value = 1234 self.stat.reset() self.assertEqual(str(self.stat), "foo: 0 in 0.0s (0.000/s)") def test_string_with_data_zero_time(self): with patch("calico.stats.monotonic_time", autospec=True) as m_time: m_time.return_value = 1234 self.stat.reset() self.stat.store_occurance() self.stat.store_occurance() self.assertEqual(str(self.stat), "foo: 2 in 0.0s (0.000/s)") def test_string_with_data_and_time(self): with patch("calico.stats.monotonic_time", autospec=True) as m_time: m_time.side_effect = iter([1234, 1235, 1235]) self.stat.reset() self.stat.store_occurance() self.stat.store_occurance() self.assertEqual(str(self.stat), "foo: 2 in 1.0s (2.000/s)")