attd 0.4__tar.gz → 1.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- attd-1.1/.gitignore +3 -0
- attd-1.1/AUTHORS.md +1 -0
- attd-1.1/COPYING +21 -0
- attd-1.1/PKG-INFO +47 -0
- {attd-0.4 → attd-1.1}/README.md +10 -7
- {attd-0.4 → attd-1.1}/attd.py +30 -25
- attd-1.1/pyproject.toml +21 -0
- attd-0.4/PKG-INFO +0 -44
- attd-0.4/attd.egg-info/PKG-INFO +0 -44
- attd-0.4/attd.egg-info/SOURCES.txt +0 -8
- attd-0.4/attd.egg-info/dependency_links.txt +0 -1
- attd-0.4/attd.egg-info/top_level.txt +0 -1
- attd-0.4/setup.cfg +0 -4
- attd-0.4/setup.py +0 -17
- attd-0.4/test/test_attd.py +0 -153
attd-1.1/.gitignore
ADDED
attd-1.1/AUTHORS.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Osmo Salomaa <otsaloma@iki.fi>
|
attd-1.1/COPYING
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2017-2023 Osmo Salomaa
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
attd-1.1/PKG-INFO
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: attd
|
|
3
|
+
Version: 1.1
|
|
4
|
+
Summary: Dictionary with attribute access to keys
|
|
5
|
+
Project-URL: Homepage, https://github.com/otsaloma/attd
|
|
6
|
+
Author-email: Osmo Salomaa <otsaloma@iki.fi>
|
|
7
|
+
License-Expression: MIT
|
|
8
|
+
License-File: AUTHORS.md
|
|
9
|
+
License-File: COPYING
|
|
10
|
+
Requires-Python: >=3.1.0
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
|
|
13
|
+
# Attribute Dictionary
|
|
14
|
+
|
|
15
|
+
[](https://pypi.org/project/attd/)
|
|
16
|
+
[](https://pepy.tech/project/attd)
|
|
17
|
+
|
|
18
|
+
attd is a Python package that provides a dictionary with attribute
|
|
19
|
+
access to keys. It is especially convenient when working with deeply
|
|
20
|
+
nested data from JSON APIs.
|
|
21
|
+
|
|
22
|
+
## Installation
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
# Latest stable version
|
|
26
|
+
pip install -U attd
|
|
27
|
+
|
|
28
|
+
# Latest development version
|
|
29
|
+
pip install -U git+https://github.com/otsaloma/attd
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Documentation
|
|
33
|
+
|
|
34
|
+
```python
|
|
35
|
+
>>> from attd import AttributeDict
|
|
36
|
+
>>> data = AttributeDict({"a": {"b": {"c": 1}}})
|
|
37
|
+
>>> data["a"]["b"]["c"]
|
|
38
|
+
1
|
|
39
|
+
>>> data.a.b.c
|
|
40
|
+
1
|
|
41
|
+
>>> from attd import FallbackAttributeDict
|
|
42
|
+
>>> data = FallbackAttributeDict()
|
|
43
|
+
>>> data["a"]["b"]["c"]
|
|
44
|
+
{}
|
|
45
|
+
>>> data.a.b.c
|
|
46
|
+
{}
|
|
47
|
+
```
|
{attd-0.4 → attd-1.1}/README.md
RENAMED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
Attribute Dictionary
|
|
2
|
-
====================
|
|
1
|
+
# Attribute Dictionary
|
|
3
2
|
|
|
4
|
-
[](https://travis-ci.org/otsaloma/attd)
|
|
5
3
|
[](https://pypi.org/project/attd/)
|
|
4
|
+
[](https://pepy.tech/project/attd)
|
|
6
5
|
|
|
7
6
|
attd is a Python package that provides a dictionary with attribute
|
|
8
7
|
access to keys. It is especially convenient when working with deeply
|
|
@@ -11,7 +10,11 @@ nested data from JSON APIs.
|
|
|
11
10
|
## Installation
|
|
12
11
|
|
|
13
12
|
```bash
|
|
14
|
-
|
|
13
|
+
# Latest stable version
|
|
14
|
+
pip install -U attd
|
|
15
|
+
|
|
16
|
+
# Latest development version
|
|
17
|
+
pip install -U git+https://github.com/otsaloma/attd
|
|
15
18
|
```
|
|
16
19
|
|
|
17
20
|
## Documentation
|
|
@@ -24,9 +27,9 @@ pip install attd
|
|
|
24
27
|
>>> data.a.b.c
|
|
25
28
|
1
|
|
26
29
|
>>> from attd import FallbackAttributeDict
|
|
27
|
-
>>> data = FallbackAttributeDict(
|
|
30
|
+
>>> data = FallbackAttributeDict()
|
|
28
31
|
>>> data["a"]["b"]["c"]
|
|
29
|
-
|
|
32
|
+
{}
|
|
30
33
|
>>> data.a.b.c
|
|
31
|
-
|
|
34
|
+
{}
|
|
32
35
|
```
|
{attd-0.4 → attd-1.1}/attd.py
RENAMED
|
@@ -23,25 +23,11 @@
|
|
|
23
23
|
"""Dictionary with attribute access to keys."""
|
|
24
24
|
|
|
25
25
|
import copy
|
|
26
|
-
import functools
|
|
27
26
|
import json
|
|
28
27
|
|
|
29
28
|
__all__ = ("AttributeDict", "FallbackAttributeDict")
|
|
30
29
|
|
|
31
|
-
__version__ = "
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
def translate_error(fm, to):
|
|
35
|
-
def outer_wrapper(function):
|
|
36
|
-
@functools.wraps(function)
|
|
37
|
-
def inner_wrapper(*args, **kwargs):
|
|
38
|
-
try:
|
|
39
|
-
return function(*args, **kwargs)
|
|
40
|
-
except fm as error:
|
|
41
|
-
raise to(str(error))
|
|
42
|
-
return inner_wrapper
|
|
43
|
-
return outer_wrapper
|
|
44
|
-
|
|
30
|
+
__version__ = "1.1"
|
|
45
31
|
|
|
46
32
|
class AttributeDict(dict):
|
|
47
33
|
|
|
@@ -66,20 +52,42 @@ class AttributeDict(dict):
|
|
|
66
52
|
return value
|
|
67
53
|
|
|
68
54
|
def __copy__(self):
|
|
69
|
-
return self.
|
|
55
|
+
return self.copy()
|
|
70
56
|
|
|
71
57
|
def __deepcopy__(self, memo=None):
|
|
72
58
|
# deepcopying via a plain dict is a lot faster due to some
|
|
73
59
|
# dict-specific optimizations that are not in use with subclasses.
|
|
74
60
|
return self.__class__(copy.deepcopy(dict(self)))
|
|
75
61
|
|
|
76
|
-
@translate_error(KeyError, AttributeError)
|
|
77
62
|
def __delattr__(self, name):
|
|
78
|
-
|
|
63
|
+
try:
|
|
64
|
+
return self.__delitem__(name)
|
|
65
|
+
except KeyError as error:
|
|
66
|
+
raise AttributeError(str(error))
|
|
79
67
|
|
|
80
|
-
@translate_error(KeyError, AttributeError)
|
|
81
68
|
def __getattr__(self, name):
|
|
82
|
-
|
|
69
|
+
try:
|
|
70
|
+
return self.__getitem__(name)
|
|
71
|
+
except KeyError as error:
|
|
72
|
+
raise AttributeError(str(error))
|
|
73
|
+
|
|
74
|
+
def __ior__(self, other):
|
|
75
|
+
self.update(other)
|
|
76
|
+
return self
|
|
77
|
+
|
|
78
|
+
def __or__(self, other):
|
|
79
|
+
if not isinstance(other, dict):
|
|
80
|
+
return NotImplemented
|
|
81
|
+
new = self.copy()
|
|
82
|
+
new.update(other)
|
|
83
|
+
return new
|
|
84
|
+
|
|
85
|
+
def __ror__(self, other):
|
|
86
|
+
if not isinstance(other, dict):
|
|
87
|
+
return NotImplemented
|
|
88
|
+
new = self.__class__(other)
|
|
89
|
+
new.update(self)
|
|
90
|
+
return new
|
|
83
91
|
|
|
84
92
|
def __setattr__(self, name, value):
|
|
85
93
|
return self.__setitem__(name, value)
|
|
@@ -113,12 +121,9 @@ class AttributeDict(dict):
|
|
|
113
121
|
kwargs.setdefault("indent", 2)
|
|
114
122
|
return json.dumps(self, **kwargs)
|
|
115
123
|
|
|
116
|
-
|
|
117
124
|
class FallbackAttributeDict(AttributeDict):
|
|
118
125
|
|
|
119
126
|
"""Attribute dictionary returning {} for missing keys."""
|
|
120
127
|
|
|
121
|
-
def
|
|
122
|
-
|
|
123
|
-
return super().__getitem__(key)
|
|
124
|
-
return self.__class__({})
|
|
128
|
+
def __missing__(self, key):
|
|
129
|
+
return self.__class__()
|
attd-1.1/pyproject.toml
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "attd"
|
|
7
|
+
dynamic = ["version"]
|
|
8
|
+
description = "Dictionary with attribute access to keys"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = "MIT"
|
|
11
|
+
requires-python = ">=3.1.0"
|
|
12
|
+
authors = [{ name = "Osmo Salomaa", email = "otsaloma@iki.fi" }]
|
|
13
|
+
|
|
14
|
+
[project.urls]
|
|
15
|
+
Homepage = "https://github.com/otsaloma/attd"
|
|
16
|
+
|
|
17
|
+
[tool.hatch.version]
|
|
18
|
+
path = "attd.py"
|
|
19
|
+
|
|
20
|
+
[tool.hatch.build.targets.sdist]
|
|
21
|
+
include = ["attd.py"]
|
attd-0.4/PKG-INFO
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.1
|
|
2
|
-
Name: attd
|
|
3
|
-
Version: 0.4
|
|
4
|
-
Summary: Dictionary with attribute access to keys
|
|
5
|
-
Home-page: https://github.com/otsaloma/attd
|
|
6
|
-
Author: Osmo Salomaa
|
|
7
|
-
Author-email: otsaloma@iki.fi
|
|
8
|
-
License: MIT
|
|
9
|
-
Description: Attribute Dictionary
|
|
10
|
-
====================
|
|
11
|
-
|
|
12
|
-
[](https://travis-ci.org/otsaloma/attd)
|
|
13
|
-
[](https://pypi.org/project/attd/)
|
|
14
|
-
|
|
15
|
-
attd is a Python package that provides a dictionary with attribute
|
|
16
|
-
access to keys. It is especially convenient when working with deeply
|
|
17
|
-
nested data from JSON APIs.
|
|
18
|
-
|
|
19
|
-
## Installation
|
|
20
|
-
|
|
21
|
-
```bash
|
|
22
|
-
pip install attd
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
## Documentation
|
|
26
|
-
|
|
27
|
-
```python
|
|
28
|
-
>>> from attd import AttributeDict
|
|
29
|
-
>>> data = AttributeDict({"a": {"b": {"c": 1}}})
|
|
30
|
-
>>> data["a"]["b"]["c"]
|
|
31
|
-
1
|
|
32
|
-
>>> data.a.b.c
|
|
33
|
-
1
|
|
34
|
-
>>> from attd import FallbackAttributeDict
|
|
35
|
-
>>> data = FallbackAttributeDict({})
|
|
36
|
-
>>> data["a"]["b"]["c"]
|
|
37
|
-
FallbackAttributeDict()
|
|
38
|
-
>>> data.a.b.c
|
|
39
|
-
FallbackAttributeDict()
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
Platform: UNKNOWN
|
|
43
|
-
Requires-Python: >=3.1.0
|
|
44
|
-
Description-Content-Type: text/markdown
|
attd-0.4/attd.egg-info/PKG-INFO
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.1
|
|
2
|
-
Name: attd
|
|
3
|
-
Version: 0.4
|
|
4
|
-
Summary: Dictionary with attribute access to keys
|
|
5
|
-
Home-page: https://github.com/otsaloma/attd
|
|
6
|
-
Author: Osmo Salomaa
|
|
7
|
-
Author-email: otsaloma@iki.fi
|
|
8
|
-
License: MIT
|
|
9
|
-
Description: Attribute Dictionary
|
|
10
|
-
====================
|
|
11
|
-
|
|
12
|
-
[](https://travis-ci.org/otsaloma/attd)
|
|
13
|
-
[](https://pypi.org/project/attd/)
|
|
14
|
-
|
|
15
|
-
attd is a Python package that provides a dictionary with attribute
|
|
16
|
-
access to keys. It is especially convenient when working with deeply
|
|
17
|
-
nested data from JSON APIs.
|
|
18
|
-
|
|
19
|
-
## Installation
|
|
20
|
-
|
|
21
|
-
```bash
|
|
22
|
-
pip install attd
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
## Documentation
|
|
26
|
-
|
|
27
|
-
```python
|
|
28
|
-
>>> from attd import AttributeDict
|
|
29
|
-
>>> data = AttributeDict({"a": {"b": {"c": 1}}})
|
|
30
|
-
>>> data["a"]["b"]["c"]
|
|
31
|
-
1
|
|
32
|
-
>>> data.a.b.c
|
|
33
|
-
1
|
|
34
|
-
>>> from attd import FallbackAttributeDict
|
|
35
|
-
>>> data = FallbackAttributeDict({})
|
|
36
|
-
>>> data["a"]["b"]["c"]
|
|
37
|
-
FallbackAttributeDict()
|
|
38
|
-
>>> data.a.b.c
|
|
39
|
-
FallbackAttributeDict()
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
Platform: UNKNOWN
|
|
43
|
-
Requires-Python: >=3.1.0
|
|
44
|
-
Description-Content-Type: text/markdown
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
attd
|
attd-0.4/setup.cfg
DELETED
attd-0.4/setup.py
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env python3
|
|
2
|
-
|
|
3
|
-
from setuptools import setup
|
|
4
|
-
|
|
5
|
-
setup(
|
|
6
|
-
name="attd",
|
|
7
|
-
version="0.4",
|
|
8
|
-
author="Osmo Salomaa",
|
|
9
|
-
author_email="otsaloma@iki.fi",
|
|
10
|
-
description="Dictionary with attribute access to keys",
|
|
11
|
-
long_description=open("README.md", "r").read(),
|
|
12
|
-
long_description_content_type="text/markdown",
|
|
13
|
-
url="https://github.com/otsaloma/attd",
|
|
14
|
-
license="MIT",
|
|
15
|
-
py_modules=["attd"],
|
|
16
|
-
python_requires=">=3.1.0",
|
|
17
|
-
)
|
attd-0.4/test/test_attd.py
DELETED
|
@@ -1,153 +0,0 @@
|
|
|
1
|
-
# -*- coding: utf-8 -*-
|
|
2
|
-
|
|
3
|
-
# Copyright (c) 2017 Osmo Salomaa
|
|
4
|
-
#
|
|
5
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
# of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
# in the Software without restriction, including without limitation the rights
|
|
8
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
# copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
# furnished to do so, subject to the following conditions:
|
|
11
|
-
#
|
|
12
|
-
# The above copyright notice and this permission notice shall be included in
|
|
13
|
-
# all copies or substantial portions of the Software.
|
|
14
|
-
#
|
|
15
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
-
# THE SOFTWARE.
|
|
22
|
-
|
|
23
|
-
import copy
|
|
24
|
-
|
|
25
|
-
from attd import AttributeDict
|
|
26
|
-
from attd import FallbackAttributeDict
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
class TestAttributeDict:
|
|
30
|
-
|
|
31
|
-
def setup_method(self, method):
|
|
32
|
-
self.ad = AttributeDict()
|
|
33
|
-
|
|
34
|
-
def test___delattr__(self):
|
|
35
|
-
self.ad.test = 1
|
|
36
|
-
assert "test" in self.ad
|
|
37
|
-
assert hasattr(self.ad, "test")
|
|
38
|
-
del self.ad.test
|
|
39
|
-
assert "test" not in self.ad
|
|
40
|
-
assert not hasattr(self.ad, "test")
|
|
41
|
-
|
|
42
|
-
def test___getattr__(self):
|
|
43
|
-
self.ad.test = 1
|
|
44
|
-
assert self.ad.test == 1
|
|
45
|
-
assert self.ad.test is self.ad["test"]
|
|
46
|
-
|
|
47
|
-
def test___setattr__(self):
|
|
48
|
-
self.ad.test = 1
|
|
49
|
-
assert self.ad.test == 1
|
|
50
|
-
assert self.ad.test is self.ad["test"]
|
|
51
|
-
|
|
52
|
-
def test___setattr____conflict(self):
|
|
53
|
-
self.ad.items = []
|
|
54
|
-
assert callable(self.ad.items)
|
|
55
|
-
|
|
56
|
-
def test___setattr____nested(self):
|
|
57
|
-
self.ad.test = {"test": {"nested": 1}}
|
|
58
|
-
assert self.ad.test.test.nested == 1
|
|
59
|
-
|
|
60
|
-
def test___setitem__(self):
|
|
61
|
-
self.ad["test"] = 1
|
|
62
|
-
assert self.ad["test"] == 1
|
|
63
|
-
assert self.ad.test is self.ad["test"]
|
|
64
|
-
|
|
65
|
-
def test_copy(self):
|
|
66
|
-
self.ad.a = 1
|
|
67
|
-
self.ad.b = "test"
|
|
68
|
-
self.ad.c = AttributeDict()
|
|
69
|
-
self.ad.c.d = 1
|
|
70
|
-
self.ad.c.e = "test"
|
|
71
|
-
adc = self.ad.copy()
|
|
72
|
-
assert isinstance(adc, AttributeDict)
|
|
73
|
-
assert isinstance(adc.c, AttributeDict)
|
|
74
|
-
assert adc == self.ad
|
|
75
|
-
assert adc is not self.ad
|
|
76
|
-
assert adc.c == self.ad.c
|
|
77
|
-
assert adc.c is self.ad.c
|
|
78
|
-
|
|
79
|
-
def test_copy_copy(self):
|
|
80
|
-
self.ad.a = 1
|
|
81
|
-
self.ad.b = "test"
|
|
82
|
-
self.ad.c = AttributeDict()
|
|
83
|
-
self.ad.c.d = 1
|
|
84
|
-
self.ad.c.e = "test"
|
|
85
|
-
adc = copy.copy(self.ad)
|
|
86
|
-
assert isinstance(adc, AttributeDict)
|
|
87
|
-
assert isinstance(adc.c, AttributeDict)
|
|
88
|
-
assert adc == self.ad
|
|
89
|
-
assert adc is not self.ad
|
|
90
|
-
assert adc.c == self.ad.c
|
|
91
|
-
assert adc.c is self.ad.c
|
|
92
|
-
|
|
93
|
-
def test_deepcopy(self):
|
|
94
|
-
self.ad.a = 1
|
|
95
|
-
self.ad.b = "test"
|
|
96
|
-
self.ad.c = AttributeDict()
|
|
97
|
-
self.ad.c.d = 1
|
|
98
|
-
self.ad.c.e = "test"
|
|
99
|
-
adc = copy.deepcopy(self.ad)
|
|
100
|
-
assert isinstance(adc, AttributeDict)
|
|
101
|
-
assert isinstance(adc.c, AttributeDict)
|
|
102
|
-
assert adc == self.ad
|
|
103
|
-
assert adc is not self.ad
|
|
104
|
-
assert adc.c == self.ad.c
|
|
105
|
-
assert adc.c is not self.ad.c
|
|
106
|
-
|
|
107
|
-
def test_setdefault(self):
|
|
108
|
-
self.ad.setdefault("test", 1)
|
|
109
|
-
assert self.ad["test"] == 1
|
|
110
|
-
assert self.ad.test is self.ad["test"]
|
|
111
|
-
|
|
112
|
-
def test_setdefault__nested(self):
|
|
113
|
-
self.ad.test = {"test": {"nested": 1}}
|
|
114
|
-
assert self.ad.test.test.nested == 1
|
|
115
|
-
|
|
116
|
-
def test_update(self):
|
|
117
|
-
self.ad.update({"test": 1})
|
|
118
|
-
assert self.ad["test"] == 1
|
|
119
|
-
assert self.ad.test is self.ad["test"]
|
|
120
|
-
|
|
121
|
-
def test_update__nested(self):
|
|
122
|
-
self.ad.update({"test": {"nested": 1}})
|
|
123
|
-
assert self.ad.test.nested == 1
|
|
124
|
-
|
|
125
|
-
def test_from_json(self):
|
|
126
|
-
test = AttributeDict.from_json('{"test": 1}')
|
|
127
|
-
assert isinstance(test, AttributeDict)
|
|
128
|
-
assert test == {"test": 1}
|
|
129
|
-
|
|
130
|
-
def test_to_json(self):
|
|
131
|
-
self.ad.test = 1
|
|
132
|
-
test = self.ad.to_json()
|
|
133
|
-
test = AttributeDict.from_json(test)
|
|
134
|
-
assert test == self.ad
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
class TestFallbackAttributeDict:
|
|
138
|
-
|
|
139
|
-
def setup_method(self, method):
|
|
140
|
-
self.ad = FallbackAttributeDict()
|
|
141
|
-
|
|
142
|
-
def test___coerce(self):
|
|
143
|
-
d = {"a": {"b": {"c": 1}}}
|
|
144
|
-
ad = FallbackAttributeDict(d)
|
|
145
|
-
assert ad.a.b.c == 1
|
|
146
|
-
assert ad.a.b.d == {}
|
|
147
|
-
assert ad.a.b.d.e == {}
|
|
148
|
-
|
|
149
|
-
def test___getattr__(self):
|
|
150
|
-
assert self.ad.a.b.c == {}
|
|
151
|
-
|
|
152
|
-
def test___getitem__(self):
|
|
153
|
-
assert self.ad["a"]["b"]["c"] == {}
|