The following pull request was submitted through Github. It can be accessed and reviewed at: https://github.com/lxc/pylxd/pull/444
This e-mail was sent by the LXC bot, direct replies will not reach the author unless they happen to be subscribed to this list. === Description (from pull-request) ===
From f41d4edc862697c6ae6b0a88942d8fe78b92b5b1 Mon Sep 17 00:00:00 2001 From: Alberto Donato <alberto.don...@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."""
_______________________________________________ lxc-devel mailing list lxc-devel@lists.linuxcontainers.org http://lists.linuxcontainers.org/listinfo/lxc-devel