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

tableau / TabPy / 6237828526

19 Sep 2023 03:39PM UTC coverage: 53.676% (-3.9%) from 57.586%
6237828526

Pull #616

github

web-flow
Merge 84e040e7e into 96aa26252
Pull Request #616: DRAFT: Fix Scrutinizer

1263 of 2353 relevant lines covered (53.68%)

0.54 hits per line

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

32.14
/tabpy/tabpy_tools/custom_query_object.py
1
import logging
1✔
2
from .query_object import QueryObject as _QueryObject
1✔
3

4

5
logger = logging.getLogger(__name__)
1✔
6

7

8
class CustomQueryObject(_QueryObject):
1✔
9
    def __init__(self, query, description=""):
1✔
10
        """Create a new CustomQueryObject.
11

12
        Parameters
13
        -----------
14

15
        query : function
16
            Function that defines a custom query method. The query can have any
17
            signature, but input and output of the query needs to be JSON
18
            serializable.
19

20
        description : str
21
            The description of the custom query object
22

23
        """
24
        super().__init__(description)
×
25

26
        self.custom_query = query
×
27

28
    def query(self, *args, **kwargs):
1✔
29
        """Query the custom defined query method using the given input.
30

31
        Parameters
32
        ----------
33
        args : list
34
            positional arguments to the query
35

36
        kwargs : dict
37
            keyword arguments to the query
38

39
        Returns
40
        -------
41
        out: object.
42
            The results depends on the implementation of the query method.
43
            Typically the return value will be whatever that function returns.
44

45
        See Also
46
        --------
47
        QueryObject
48
        """
49
        # include the dependent files in sys path so that the query can run
50
        # correctly
51

52
        try:
×
53
            logger.debug(
×
54
                "Running custom query with arguments " f"({args}, {kwargs})..."
55
            )
56
            ret = self.custom_query(*args, **kwargs)
×
57
        except Exception as e:
×
58
            logger.exception(
×
59
                "Exception hit when running custom query, error: " f"{str(e)}"
60
            )
61
            raise
×
62

63
        logger.debug(f"Received response {ret}")
×
64
        try:
×
65
            return self._make_serializable(ret)
×
66
        except Exception as e:
×
67
            logger.exception(
×
68
                "Cannot properly serialize custom query result, " f"error: {str(e)}"
69
            )
70
            raise
×
71

72
    def get_doc_string(self):
1✔
73
        """Get doc string from customized query"""
74
        if self.custom_query.__doc__ is not None:
×
75
            return self.custom_query.__doc__
×
76
        else:
77
            return "-- no docstring found in query function --"
×
78

79
    def get_methods(self):
1✔
80
        return [self.get_query_method()]
×
81

82
    def get_query_method(self):
1✔
83
        return {"method": "query"}
×
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