• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

uwefladrich / scriptengine / 7800592980

06 Feb 2024 01:38PM UTC coverage: 91.467% (+0.004%) from 91.463%
7800592980

Pull #109

github

uwefladrich
Update CHANGES
Pull Request #109: Have base.task_timer return proper Context

16 of 19 new or added lines in 2 files covered. (84.21%)

1908 of 2086 relevant lines covered (91.47%)

0.91 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

69.23
/src/scriptengine/tasks/base/task_timer.py
1
"""TaskTimer for ScriptEngine."""
1✔
2

3
from scriptengine.context import Context
1✔
4
from scriptengine.exceptions import ScriptEngineTaskRunError
1✔
5
from scriptengine.tasks.core import Task
1✔
6

7

8
class TaskTimer(Task):
1✔
9
    """TaskTimer, controls ScriptEngine task timing feature
1✔
10

11
    Arguments:
12
      mode (required):   one of
13
                         False:       Timing is switched off.
14
                         'basic':     Each task is timed, log messages are
15
                                      written according to 'logging'
16
                                      argument.
17
                         'classes':   As for 'basic', plus times are
18
                                      accumulated for task classes.
19
                         'instances': As for 'classes', plus times are
20
                                      accumulated for each individual task
21
                                      instance.
22
     logging (optional): one of
23
                         False:   No time logging after each task. Does not
24
                                  affect statistic collection.
25
                         'info':  Logging to the info logger.
26
                         'debug': Logging to the debug logger.
27
    """
28

29
    _required_arguments = ("mode",)
1✔
30

31
    def __init__(self, arguments):
1✔
32
        TaskTimer.check_arguments(arguments)
1✔
33
        super().__init__(arguments)
1✔
34

35
    def run(self, context):
1✔
36
        mode = self.getarg("mode", context)
1✔
37
        if mode not in (False, "basic", "classes", "instances"):
1✔
NEW
38
            msg = (
×
39
                'Unknown mode in TaskTimer: must be one of "off", "basic", '
40
                f'"classes", "instances", not "{mode}"'
41
            )
42
            self.log_error(msg)
×
43
            raise ScriptEngineTaskRunError(msg)
×
44

45
        if mode:
1✔
46
            logging = self.getarg("logging", context, default=False)
1✔
47
            if logging not in (False, "info", "debug"):
1✔
NEW
48
                msg = (
×
49
                    "Unknown logging mode in TaskTimer: must be one of "
50
                    f'"off", "info", "debug", not "{logging}"'
51
                )
52
                self.log_error(msg)
×
53
                raise ScriptEngineTaskRunError(msg)
×
54
            self.log_info(
1✔
55
                f'Task timing activated in mode "{mode}" and ' f'logging to "{logging}"'
56
            )
57
        else:
58
            logging = False
×
NEW
59
            self.log_info("Task timing is switched off")
×
60

61
        return Context({"se.tasks.timing": {"mode": mode, "logging": logging}})
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc