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

uwefladrich / scriptengine / 7017582421

28 Nov 2023 10:42AM UTC coverage: 91.699% (+4.4%) from 87.286%
7017582421

push

github

uwefladrich
Fix handling of stderr in case command fails

15 of 15 new or added lines in 2 files covered. (100.0%)

21 existing lines in 4 files now uncovered.

1900 of 2072 relevant lines covered (91.7%)

0.92 hits per line

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

50.88
/src/scriptengine/engines/simple_script_engine.py
1
""" SimpleScriptEngine for ScriptEngine.
1✔
2

3
SimpleScriptEngine is a simplistic script engine. It runs all jobs sequentially
4
on the local machine, without consideration of job contexts. The
5
SimpleScriptEngine relies on the Job class to run the actual tasks/jobs.
6
"""
7

8
import copy
1✔
9
import logging
1✔
10
import sys
1✔
11
from pprint import pprint
1✔
12

13
from scriptengine.context import Context
1✔
14
from scriptengine.exceptions import (
1✔
15
    ScriptEngineJobError,
16
    ScriptEngineStopException,
17
    ScriptEngineTaskError,
18
)
19
from scriptengine.tasks.core import Task
1✔
20

21

22
class SimpleScriptEngine:
1✔
23
    def __init__(self):
1✔
24
        self.logger = logging.getLogger(
1✔
25
            "se.instance." + self.__class__.__name__.lower()
26
        )
27

28
    def _guarded_run(self, runner, context):
1✔
29
        try:
1✔
30
            return runner.run(context)
1✔
31
        except AttributeError as e:
×
UNCOV
32
            self.log_error(
×
33
                "STOPPING SimpleScriptEngine due to internal error: "
34
                f"Cannot run type {type(runner).__name__}"
35
            )
36
            error = e
×
37
        except ScriptEngineStopException:
×
38
            self.log_info("STOPPING SimpleScriptEngine instance upon request")
×
39
            error = None
×
40
        except ScriptEngineTaskError as e:
×
41
            if isinstance(runner, Task):
×
UNCOV
42
                self.log_error(
×
43
                    "STOPPING SimpleScriptEngine due to task error in "
44
                    f"{runner.reg_name} <{runner.shortid}>"
45
                )
46
            else:
UNCOV
47
                self.log_error(
×
48
                    "STOPPING SimpleScriptEngine due to task error in job "
49
                    f"<{runner.shortid}>"
50
                )
51
            error = e
×
52
        except ScriptEngineJobError as e:
×
UNCOV
53
            self.log_error(
×
54
                f"STOPPING SimpleScriptEngine due to job error in <{runner.shortid}>"
55
            )
56
            error = e
×
57
        if error:
×
58
            if self.logger.getEffectiveLevel() <= logging.DEBUG:
×
59
                self.log_error("Last context before error:")
×
60
                pprint(context)
×
61
                self.log_error("Traceback from error:")
×
UNCOV
62
                raise error
×
63
            else:
64
                self.log_error("For more debugging info, re-run with loglevel DEBUG")
×
UNCOV
65
        sys.exit()
×
66

67
    def run(self, script, context):
1✔
68
        local_context = Context(context)
1✔
69
        context_update = Context()
1✔
70
        for todo in script if isinstance(script, list) else [script]:
1✔
71
            c = self._guarded_run(todo, local_context)
1✔
72
            if c:
1✔
73
                local_context += c
1✔
74
                context_update += copy.deepcopy(c)
1✔
75
        return context_update or None
1✔
76

77
    def _log(self, level, msg):
1✔
78
        self.logger.log(level, msg)
×
79

80
    def log_debug(self, msg):
1✔
81
        self._log(logging.DEBUG, msg)
×
82

83
    def log_info(self, msg):
1✔
84
        self._log(logging.INFO, msg)
×
85

86
    def log_warning(self, msg):
1✔
87
        self._log(logging.WARNING, msg)
×
88

89
    def log_error(self, msg):
1✔
90
        self._log(logging.ERROR, msg)
×
91

92
    def log_critical(self, msg):
1✔
UNCOV
93
        self._log(logging.CRITICAL, msg)
×
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