Merge pull request #2502 from mhils/optmanager

Fix optmanager equality check and deepcopy
This commit is contained in:
Maximilian Hils 2017-08-07 16:22:33 +02:00 committed by GitHub
commit 6d9b5b0c06
2 changed files with 13 additions and 3 deletions

View File

@ -150,13 +150,17 @@ class OptManager:
self.changed.connect(_call, weak=False)
def __eq__(self, other):
return self._options == other._options
if isinstance(other, OptManager):
return self._options == other._options
return False
def __copy__(self):
def __deepcopy__(self, memodict = None):
o = OptManager()
o.__dict__["_options"] = copy.deepcopy(self._options)
o.__dict__["_options"] = copy.deepcopy(self._options, memodict)
return o
__copy__ = __deepcopy__
def __getattr__(self, attr):
if attr in self._options:
return self._options[attr].current()

View File

@ -73,6 +73,11 @@ def test_required_int():
o.parse_setval("required_int", None)
def test_deepcopy():
o = TD()
copy.deepcopy(o)
def test_options():
o = TO()
assert o.keys() == {"bool", "one", "two", "required_int"}
@ -244,6 +249,7 @@ def test_serialize():
o2 = TD2()
optmanager.load(o2, data)
assert o2 == o
assert not o == 42
t = """
unknown: foo