File: test_utils_delay.py

package info (click to toggle)
dogtail 2.0.1-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 1,108 kB
  • sloc: python: 8,020; makefile: 45; sh: 7
file content (63 lines) | stat: -rw-r--r-- 1,402 bytes parent folder | download
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/python3
"""
Unit tests for the dogtail.utils delays.
"""


import os
from time import time

import unittest

from dogtail.utils import do_delay
from dogtail.config import config


class TestDelay(unittest.TestCase):
    """
    Class to test dogtail's utils do_delay method.
    """

    def test_do_delay_implicit(self):
        """
        Test utils do_delay function by setting config value.
        """

        config.default_delay = 2.0
        start_time = time()
        do_delay()
        self.assertTrue(time() - start_time >= 2.0)


    def test_do_delay_explicit(self):
        """
        Test utils do_delay function by passing value to the method.
        """

        config.default_delay = 2.0
        start_time = time()
        do_delay(2.0)
        self.assertTrue(time() - start_time >= 2.0)


    def test_do_delay_debug_sleep(self):
        """
        Test utils do_delay function with debug_sleep option.
        """

        config.default_delay = 2.0
        config.debug_sleep = True
        start_time = time()
        do_delay(2.0)

        self.assertTrue(os.path.isfile(config.debug_file))

        with open(config.debug_file, "r", encoding="utf-8") as _f:
            file_content = _f.read()
            self.assertTrue("Debug Sleep: " in file_content)

        self.assertTrue(time() - start_time >= 2.0)


if __name__ == "__main__":
    unittest.main()