コード例 #1
0
 def test_clock_tick_with_timestamp(self, monkeypatch):
     def mytime():
         return 1436345964.484081
     monkeypatch.setattr(time, 'time', mytime)
     # print(time.time())
     c = Clock(94132454961709074)
     assert c.l == 1436347274196
     assert c.c == 18
     c.update(94132454961709075)
     assert c.c == 20  # tick() increments c by 1 as well
コード例 #2
0
def clock():
    return Clock()
コード例 #3
0
 def test_create_clock_from_timestamp(self):
     c = Clock(94132454961709074)
     assert c.l == 1436347274196
     assert c.c == 18
コード例 #4
0
 def test_clock_seconds_should_be_bounded(self):
     c = Clock().seconds()
     t = time.time()
     assert (c - t) < 0.002
コード例 #5
0
            prev = cur

    def test_create_clock_from_timestamp(self):
        c = Clock(94132454961709074)
        assert c.l == 1436347274196
        assert c.c == 18

    def test_clock_seconds_should_be_bounded(self):
        c = Clock().seconds()
        t = time.time()
        assert (c - t) < 0.002

    def test_clock_tick_with_timestamp(self, monkeypatch):
        def mytime():
            return 1436345964.484081
        monkeypatch.setattr(time, 'time', mytime)
        # print(time.time())
        c = Clock(94132454961709074)
        assert c.l == 1436347274196
        assert c.c == 18
        c.update(94132454961709075)
        assert c.c == 20  # tick() increments c by 1 as well


if __name__ == '__main__':
    clock = Clock()
    for i in range(100):
        clock.tick()
        print("%r, %r" % (clock.timestamp(), time.time()))
        time.sleep(0.1)