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

tableau / TabPy / 19636239578

25 Nov 2024 10:31PM UTC coverage: 54.229% (-3.4%) from 57.612%
19636239578

push

github

web-flow
Merge pull request #652 from tableau/remote_server

Add capability to deploy models remotely

21 of 42 new or added lines in 5 files covered. (50.0%)

82 existing lines in 5 files now uncovered.

1340 of 2471 relevant lines covered (54.23%)

0.54 hits per line

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

43.64
/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_docstring() -- returns documentation for the Query Object
18
    """
19

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

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

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

32
    @abc.abstractmethod
1✔
33
    def get_docstring(self):
1✔
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
        """
UNCOV
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)
×
UNCOV
55
        self._save_local(path)
×
56

57
    def _save_local(self, path):
1✔
58
        """Save current query object to local path
59
        """
UNCOV
60
        try:
×
UNCOV
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

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

73
    @classmethod
1✔
74
    def load(cls, path):
1✔
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):
1✔
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):
1✔
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):
1✔
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