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

datajoint / datajoint-python / #12897

pending completion
#12897

push

travis-ci

web-flow
<a href="https://github.com/datajoint/datajoint-python/commit/<a class=hub.com/datajoint/datajoint-python/commit/715ab40552f63cd79723ed2830c6691b2cb228b9">715ab4055<a href="https://github.com/datajoint/datajoint-python/commit/715ab40552f63cd79723ed2830c6691b2cb228b9">">Merge </a><a class="double-link" href="https://github.com/datajoint/datajoint-python/commit/<a class="double-link" href="https://github.com/datajoint/datajoint-python/commit/0a4f193031d8b1e14b09ec62d83c5def3b7421b0">0a4f19303</a>">0a4f19303</a><a href="https://github.com/datajoint/datajoint-python/commit/715ab40552f63cd79723ed2830c6691b2cb228b9"> into 3b6e84588">3b6e84588</a>

69 of 69 new or added lines in 9 files covered. (100.0%)

3125 of 3454 relevant lines covered (90.47%)

0.9 hits per line

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

66.67
/datajoint/attribute_adapter.py
1
import re
1✔
2
from .errors import DataJointError, _support_adapted_types
1✔
3
from .plugin import type_plugins
1✔
4

5

6
class AttributeAdapter:
1✔
7
    """
8
    Base class for adapter objects for user-defined attribute types.
9
    """
10

11
    @property
1✔
12
    def attribute_type(self):
1✔
13
        """
14
        :return: a supported DataJoint attribute type to use; e.g. "longblob", "blob@store"
15
        """
16
        raise NotImplementedError("Undefined attribute adapter")
×
17

18
    def get(self, value):
1✔
19
        """
20
        convert value retrieved from the the attribute in a table into the adapted type
21

22
        :param value: value from the database
23

24
        :return: object of the adapted type
25
        """
26
        raise NotImplementedError("Undefined attribute adapter")
×
27

28
    def put(self, obj):
1✔
29
        """
30
        convert an object of the adapted type into a value that DataJoint can store in a table attribute
31

32
        :param obj: an object of the adapted type
33
        :return: value to store in the database
34
        """
35
        raise NotImplementedError("Undefined attribute adapter")
×
36

37

38
def get_adapter(context, adapter_name):
1✔
39
    """
40
    Extract the AttributeAdapter object by its name from the context and validate.
41
    """
42
    if not _support_adapted_types():
1✔
43
        raise DataJointError("Support for Adapted Attribute types is disabled.")
×
44
    adapter_name = adapter_name.lstrip("<").rstrip(">")
1✔
45
    try:
1✔
46
        adapter = (
1✔
47
            context[adapter_name]
48
            if adapter_name in context
49
            else type_plugins[adapter_name]["object"].load()
50
        )
51
    except KeyError:
×
52
        raise DataJointError(
×
53
            "Attribute adapter '{adapter_name}' is not defined.".format(
54
                adapter_name=adapter_name
55
            )
56
        )
57
    if not isinstance(adapter, AttributeAdapter):
1✔
58
        raise DataJointError(
×
59
            "Attribute adapter '{adapter_name}' must be an instance of datajoint.AttributeAdapter".format(
60
                adapter_name=adapter_name
61
            )
62
        )
63
    if not isinstance(adapter.attribute_type, str) or not re.match(
1✔
64
        r"^\w", adapter.attribute_type
65
    ):
66
        raise DataJointError(
×
67
            "Invalid attribute type {type} in attribute adapter '{adapter_name}'".format(
68
                type=adapter.attribute_type, adapter_name=adapter_name
69
            )
70
        )
71
    return adapter
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

© 2026 Coveralls, Inc