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

uwefladrich / scriptengine / 6353713488

29 Sep 2023 03:27PM UTC coverage: 89.365% (+2.1%) from 87.306%
6353713488

Pull #97

github

uwefladrich
Add further tests for Context
Pull Request #97: Implement a better Context class

255 of 255 new or added lines in 19 files covered. (100.0%)

1773 of 1984 relevant lines covered (89.36%)

0.89 hits per line

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

27.45
/src/scriptengine/tasks/base/include.py
1
"""Include task for ScriptEngine
1✔
2

3
   The Include task reads a YAML file, parses the content to create a
4
   ScriptEngine script and lets the active ScriptEngine instance execute it.
5
"""
6

7
import copy
1✔
8
from pathlib import Path
1✔
9

10
from scriptengine.context import Context
1✔
11
from scriptengine.exceptions import ScriptEngineTaskRunError
1✔
12
from scriptengine.tasks.core import Task, timed_runner
1✔
13
from scriptengine.yaml.parser import parse_file
1✔
14

15

16
def _file_in_paths(file, paths=None):
1✔
17
    if file.is_absolute():
×
18
        if file.is_file():
×
19
            return file
×
20
        raise FileNotFoundError
×
21

22
    searched_paths = []
×
23
    for p in paths or []:
×
24
        if p not in searched_paths:
×
25
            searched_paths.append(p)
×
26
            fpath = p / file
×
27
            if fpath.is_file():
×
28
                return fpath
×
29
    raise FileNotFoundError
×
30

31

32
class Include(Task):
1✔
33

34
    _required_arguments = ("src",)
1✔
35

36
    def __init__(self, arguments):
1✔
37
        Include.check_arguments(arguments)
×
38
        super().__init__(arguments)
×
39

40
    def __str__(self):
1✔
41
        return f"Include: {self.src}"
×
42

43
    @timed_runner
1✔
44
    def run(self, context):
1✔
45

46
        src = Path(self.getarg("src", context))
×
47
        self.log_info(f"Include script from {src}")
×
48

49
        # Search for include file in '.', old cwd, and script_path
50
        cwd = Path(".")
×
51
        ocwd = Path(context["se"]["cli"]["cwd"])
×
52
        script_path = (Path(p) for p in context["se"]["cli"]["script_path"])
×
53
        search_path = (cwd, ocwd, *script_path)
×
54
        self.log_debug(
×
55
            f"Include file search path: {tuple(str(p) for p in search_path)}"
56
        )
57

58
        try:
×
59
            inc_file = _file_in_paths(src, search_path)
×
60
        except FileNotFoundError:
×
61
            if self.getarg("ignore_not_found", default=False):
×
62
                self.log_warning(f"Include file not found: {src}")
×
63
                return
×
64
            self.log_error(f"Include file not found: {src}")
×
65
            raise ScriptEngineTaskRunError
×
66
        self.log_debug(f"Include file found: {str(inc_file)}")
×
67

68
        script = parse_file(inc_file)
×
69

70
        self.log_debug(f"Execute include script: {inc_file}")
×
71
        local_context = Context(copy.deepcopy(context))
×
72
        context_update = local_context["se"]["instance"].run(script, local_context)
×
73
        self.log_debug(f"Finished executing include script: {inc_file}")
×
74

75
        return context_update or None
×
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