File: tests_stopwatch.py

package info (click to toggle)
scoop 0.7.1-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 1,260 kB
  • ctags: 814
  • sloc: python: 6,035; makefile: 119; sh: 5
file content (46 lines) | stat: -rw-r--r-- 1,253 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
from scoop._types import StopWatch

import unittest
import time

class TestStopWatch(unittest.TestCase):
    def __init__(self, *args, **kwargs):
        super(TestStopWatch, self).__init__(*args, **kwargs)

    def test_get(self):
        watch = StopWatch()
        first = watch.get()
        time.sleep(0.1)
        second = watch.get()
        # *nix tend to overshoot a tiny bit, Windows tend to always be under
        # by max. 1ms
        self.assertAlmostEqual(second - first, 0.1, places=2)

    def test_halt(self):
        watch = StopWatch()
        watch.halt()
        first = watch.get()
        time.sleep(0.1)
        second = watch.get()
        self.assertEqual(first, second)

    def test_resume(self):
        watch = StopWatch()
        watch.halt()
        first = watch.get()
        watch.resume()
        time.sleep(0.1)
        second = watch.get()
        # See test_get
        self.assertAlmostEqual(second - first, 0.1, places=2)

    def test_reset(self):
        watch = StopWatch()
        time.sleep(0.1)
        watch.reset()
        self.assertLess(watch.get(), 0.001)


if __name__ == "__main__":
    t = unittest.TestLoader().loadTestsFromTestCase(TestStopWatch)
    unittest.TextTestRunner(verbosity=2).run(t)