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

zincware / MDSuite / 3999396905

pending completion
3999396905

push

github-actions

GitHub
[merge before other PRs] ruff updates (#580)

960 of 1311 branches covered (73.23%)

Branch coverage included in aggregate %.

15 of 15 new or added lines in 11 files covered. (100.0%)

4034 of 4930 relevant lines covered (81.83%)

3.19 hits per line

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

76.47
/mdsuite/database/types.py
1
"""
2
MDSuite: A Zincwarecode package.
3

4
License
5
-------
6
This program and the accompanying materials are made available under the terms
7
of the Eclipse Public License v2.0 which accompanies this distribution, and is
8
available at https://www.eclipse.org/legal/epl-v20.html
9

10
SPDX-License-Identifier: EPL-2.0
11

12
Copyright Contributors to the Zincwarecode Project.
13

14
Contact Information
15
-------------------
16
email: zincwarecode@gmail.com
17
github: https://github.com/zincware
18
web: https://zincwarecode.com/
19

20
Citation
21
--------
22
If you use this module please cite us with:
23

24
Summary
25
-------
26
"""
27

28
import json
4✔
29

30
from sqlalchemy.ext.mutable import Mutable
4✔
31
from sqlalchemy.types import VARCHAR, TypeDecorator
4✔
32

33

34
class JSONEncodedDict(TypeDecorator):
4✔
35
    """Represents an immutable structure as a json-encoded string."""
36

37
    impl = VARCHAR
4✔
38

39
    def process_bind_param(self, value: dict, dialect):
4✔
40
        """Provide a bound value processing function.
41

42
        Convert a dictionary to a json string and store the string in the database
43
        """
44
        if value is not None:
4!
45
            value = json.dumps(value)
4✔
46
        return value
4✔
47

48
    def process_result_value(self, value, dialect) -> dict:
4✔
49
        """Receive a result-row column value to be converted.
50

51
        Convert a loaded string from the database into a dict object
52
        """
53
        if value is not None:
4!
54
            value = json.loads(value)
4✔
55
        return value
4✔
56

57

58
class MutableDict(Mutable, dict):
4✔
59
    """Subclassed version of a dictionary used in the database."""
60

61
    @classmethod
4✔
62
    def coerce(cls, key, value):
3✔
63
        """Convert plain dictionaries to MutableDict."""
64
        if not isinstance(value, MutableDict):
4!
65
            if isinstance(value, dict):
4!
66
                return MutableDict(value)
4✔
67

68
            # this call will raise ValueError
69
            return Mutable.coerce(key, value)
×
70
        else:
71
            return value
×
72

73
    def __setitem__(self, key, value):
4✔
74
        """Detect dictionary set events and emit change events."""
75
        dict.__setitem__(self, key, value)
4✔
76
        self.changed()
4✔
77

78
    def __delitem__(self, key):
4✔
79
        """Detect dictionary del events and emit change events."""
80
        dict.__delitem__(self, key)
×
81
        self.changed()
×
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