[lxc-devel] [pylxd/master] make AttributeDict iterable, drop special method
albertodonato on Github
lxc-bot at linuxcontainers.org
Tue Dec 15 11:40:13 UTC 2020
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 302 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20201215/5410df4a/attachment.bin>
-------------- next part --------------
From f41d4edc862697c6ae6b0a88942d8fe78b92b5b1 Mon Sep 17 00:00:00 2001
From: Alberto Donato <alberto.donato at canonical.com>
Date: Tue, 15 Dec 2020 12:39:21 +0100
Subject: [PATCH] make AttributeDict iterable, drop special method
---
pylxd/models/_model.py | 5 ++---
pylxd/tests/models/test_model.py | 4 ++--
pylxd/tests/models/test_network.py | 2 +-
3 files changed, 5 insertions(+), 6 deletions(-)
diff --git a/pylxd/models/_model.py b/pylxd/models/_model.py
index 65d3a11d..f2c8260c 100644
--- a/pylxd/models/_model.py
+++ b/pylxd/models/_model.py
@@ -13,7 +13,6 @@
# under the License.
import os
import warnings
-from copy import deepcopy
from pylxd import exceptions
@@ -27,8 +26,8 @@ def __init__(self, dct):
for key, value in dct.items():
setattr(self, key, value)
- def _asdict(self):
- return deepcopy(self.__dict__)
+ def __iter__(self):
+ return iter(self.__dict__.items())
class Attribute:
diff --git a/pylxd/tests/models/test_model.py b/pylxd/tests/models/test_model.py
index cda5182f..5ef514b6 100644
--- a/pylxd/tests/models/test_model.py
+++ b/pylxd/tests/models/test_model.py
@@ -39,10 +39,10 @@ def test_from_dict(self):
assert a.foo == "bar"
assert a.baz == "bza"
- def test_as_dict(self):
+ def test_iterable(self):
d = {"foo": "bar", "baz": "bza"}
a = model.AttributeDict(d)
- assert a._asdict() == d
+ assert dict(a) == d
class TestModel(testing.PyLXDTestCase):
diff --git a/pylxd/tests/models/test_network.py b/pylxd/tests/models/test_network.py
index 148950f6..a6431c09 100644
--- a/pylxd/tests/models/test_network.py
+++ b/pylxd/tests/models/test_network.py
@@ -254,7 +254,7 @@ def test_state(self):
}
)
network = models.Network.get(self.client, "eth0")
- assert network.state()._asdict() == state
+ assert dict(network.state()) == state
def test_str(self):
"""Network is printed in JSON format."""
More information about the lxc-devel
mailing list