• 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

36.73
/tabpy/tabpy_tools/query_object.py
1
import abc
1✔
2
import logging
1✔
3
import os
1✔
4
import json
1✔
5
import shutil
1✔
6

7
import cloudpickle as _cloudpickle
1✔
8

9

10
logger = logging.getLogger(__name__)
1✔
11

12

13
class QueryObject(abc.ABC):
1✔
14
    """
15
    Derived class needs to implement the following interface:
16
      * query() -- given input, return query result
17
      * get_doc_string() -- returns documentation for the Query Object
18
    """
19

20
    def __init__(self, description=""):
1✔
21
        self.description = description
×
22

23
    def get_dependencies(self):
1✔
24
        """All endpoints this endpoint depends on"""
25
        return []
×
26

27
    @abc.abstractmethod
1✔
28
    def query(self, input):
29
        """execute query on the provided input"""
30
        pass
×
31

32
    @abc.abstractmethod
1✔
33
    def get_doc_string(self):
34
        """Returns documentation for the query object
35

36
        By default, this method returns the docstring for 'query' method
37
        Derived class may overwrite this method to dynamically create docstring
38
        """
39
        pass
×
40

41
    def save(self, path):
1✔
42
        """ Save query object to the given local path
43

44
        Parameters
45
        ----------
46
        path : str
47
          The location to save the query object to
48
        """
49
        if os.path.exists(path):
×
50
            logger.warning(
×
51
                f'Overwriting existing file "{path}" when saving query object'
52
            )
53
            rm_fn = os.remove if os.path.isfile(path) else shutil.rmtree
×
54
            rm_fn(path)
×
55
        self._save_local(path)
×
56

57
    def _save_local(self, path):
1✔
58
        """Save current query object to local path
59
        """
60
        try:
×
61
            os.makedirs(path)
×
62
        except OSError as e:
×
63
            import errno
×
64

65
            if e.errno == errno.EEXIST and os.path.isdir(path):
×
66
                pass
×
67
            else:
68
                raise
×
69

70
        with open(os.path.join(path, "pickle_archive"), "wb") as f:
×
71
            _cloudpickle.dump(self, f)
×
72

73
    @classmethod
1✔
74
    def load(cls, path):
75
        """ Load query object from given path
76
        """
77
        new_po = None
×
78
        new_po = cls._load_local(path)
×
79

80
        logger.info(f'Loaded query object "{type(new_po).__name__}" successfully')
×
81

82
        return new_po
×
83

84
    @classmethod
1✔
85
    def _load_local(cls, path):
86
        path = os.path.abspath(os.path.expanduser(path))
×
87
        with open(os.path.join(path, "pickle_archive"), "rb") as f:
×
88
            return _cloudpickle.load(f)
×
89

90
    @classmethod
1✔
91
    def _make_serializable(cls, result):
92
        """Convert a result from object query to python data structure that can
93
        easily serialize over network
94
        """
95
        try:
×
96
            json.dumps(result)
×
97
        except TypeError:
×
98
            raise TypeError(
×
99
                "Result from object query is not json serializable: " f"{result}"
100
            )
101

102
        return result
×
103

104
    # Returns an array of dictionary that contains the methods and their
105
    # corresponding schema information.
106
    @abc.abstractmethod
1✔
107
    def get_methods(self):
108
        return 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