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

tethysplatform / tethys / 12042567348

27 Nov 2024 02:24AM UTC coverage: 100.0%. Remained the same
12042567348

push

github

web-flow
Update release.yml

11178 of 11178 relevant lines covered (100.0%)

1.0 hits per line

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

100.0
/tethys_apps/base/function_extractor.py
1
class TethysFunctionExtractor:
1✔
2
    """
3
    Base class for PersistentStore and HandoffHandler that returns a function handle from a string path to the function.
4

5
    Attributes:
6
        path (str): The path to a function in the form "app_name.module_name.function_name" or the function object.
7
    """
8

9
    PATH_PREFIX = "tethysapp"
1✔
10

11
    def __init__(self, path, prefix=PATH_PREFIX, throw=False):
1✔
12
        self.path = path
1✔
13
        self.prefix = prefix
1✔
14
        self._throw = throw
1✔
15
        self._valid = None
1✔
16
        self._function = None
1✔
17

18
        # Handle function object case
19
        if not isinstance(path, str):
1✔
20
            if callable(path):
1✔
21
                self._valid = True
1✔
22
                self._function = path
1✔
23

24
    def _extract_function(self):
1✔
25
        if not self._function and self._valid is None:
1✔
26
            try:
1✔
27
                # Split into parts and extract function name
28
                module_path, function_name = self.path.rsplit(".", 1)
1✔
29

30
                # Pre-process handler path
31
                full_module_path = (
1✔
32
                    ".".join((self.prefix, module_path)) if self.prefix else module_path
33
                )
34

35
                # Import module
36
                module = __import__(full_module_path, fromlist=[str(function_name)])
1✔
37

38
            except (ValueError, ImportError) as e:
1✔
39
                self._valid = False
1✔
40
                if self._throw:
1✔
41
                    raise e
1✔
42
            else:
43
                # Get the function
44
                self._function = getattr(module, function_name)
1✔
45
                self._valid = True
1✔
46

47
    @property
1✔
48
    def valid(self):
1✔
49
        """
50
        True if function is valid otherwise False.
51
        """
52
        if self._valid is None:
1✔
53
            self._extract_function()
1✔
54
        return self._valid
1✔
55

56
    @property
1✔
57
    def function(self):
1✔
58
        """
59
        The function pointed to by the path_str attribute.
60

61
        Returns:
62
            A handle to a Python function or None if function is not valid.
63
        """
64
        if self._function is None:
1✔
65
            self._extract_function()
1✔
66
        return self._function
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

© 2025 Coveralls, Inc