File: test_utils.py

package info (click to toggle)
gtg 0.6-12
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 9,492 kB
  • sloc: xml: 20,785; python: 17,657; sh: 158; makefile: 93
file content (23 lines) | stat: -rw-r--r-- 605 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
from unittest.mock import Mock


class MockThread(Mock):

    def __init__(self, *args, target=None, **kwargs):
        super().__init__()
        self._target = target

    def start(self):
        return self._target()


class MockTimer(MockThread):

    def __init__(self, *args, **kwargs):
        if 'function' in kwargs:
            super().__init__(target=kwargs['function'])
        elif len(args) >= 2:
            super().__init__(target=args[1])
        else:
            raise AssertionError("%s couldn't find delayed function call"
                                 % self.__class__.__name__)