From 77acda840a56287405cbb4390984a3bff13c9981 Mon Sep 17 00:00:00 2001 From: Markus Zolliker Date: Fri, 12 Nov 2021 17:13:40 +0100 Subject: [PATCH] fix tests from mlz repo - fix omit_unchanged - names too short + other pylint complains Change-Id: I3c277b461fad1a5fdf8e76ff1cc42b8742d1de16 Change-Id: I58fb64f91bcc2efef20df68f5c63a64315413286 --- secop/params.py | 2 +- secop/persistent.py | 2 +- test/test_iohandler.py | 7 ++++++- test/test_params.py | 2 +- test/test_properties.py | 28 ++++++++++++++-------------- 5 files changed, 23 insertions(+), 18 deletions(-) diff --git a/secop/params.py b/secop/params.py index e80e6c4..9add5a8 100644 --- a/secop/params.py +++ b/secop/params.py @@ -367,6 +367,7 @@ class Command(Accessible): self.description = inspect.cleandoc(argument.__doc__) self.name = self.func.__name__ # this is probably not needed self._inherit = inherit # save for __set_name__ + self.ownProperties = self.propertyValues.copy() def __set_name__(self, owner, name): self.name = name @@ -375,7 +376,6 @@ class Command(Accessible): (owner.__name__, name)) self.datatype = CommandType(self.argument, self.result) - self.ownProperties = self.propertyValues.copy() if self.export is True: predefined_cls = PREDEFINED_ACCESSIBLES.get(name, None) if predefined_cls is Command: diff --git a/secop/persistent.py b/secop/persistent.py index e35a61f..57a5190 100644 --- a/secop/persistent.py +++ b/secop/persistent.py @@ -57,7 +57,7 @@ import json from secop.lib import getGeneralConfig from secop.datatypes import EnumType -from secop.params import Parameter, Property, BoolType, Command +from secop.params import Parameter, Property, Command from secop.modules import HasAccessibles diff --git a/test/test_iohandler.py b/test/test_iohandler.py index 21012ce..f860a10 100644 --- a/test/test_iohandler.py +++ b/test/test_iohandler.py @@ -71,7 +71,11 @@ class Data: class DispatcherStub: - OMIT_UNCHANGED_WITHIN = 0 + # the first update from the poller comes a very short time after the + # initial value from the timestamp. However, in the test below + # the second update happens after the updates dict is cleared + # -> we have to inhibit the 'omit unchanged update' feature + omit_unchanged_within = 0 def __init__(self, updates): self.updates = updates @@ -108,6 +112,7 @@ def test_IOHandler(): group1 = Hdl('group1', 'SIMPLE?', '%g') group2 = Hdl('group2', 'CMD?%(channel)d', '%g,%s,%d') + class Module1(Module): channel = Property('the channel', IntRange(), default=3) loop = Property('the loop', IntRange(), default=2) diff --git a/test/test_params.py b/test/test_params.py index 8951979..bf39577 100644 --- a/test/test_params.py +++ b/test/test_params.py @@ -93,7 +93,7 @@ def test_Override(): assert id(Mod.p3) == id(Base.p3) assert repr(Mod.p2) == repr(Base.p2) # must be a clone assert repr(Mod.p3) == repr(Base.p3) # must be a clone - assert Mod.p1.default == True + assert Mod.p1.default is True # manipulating default makes Base.p1 and Mod.p1 match Mod.p1.default = False assert repr(Mod.p1) == repr(Base.p1) diff --git a/test/test_properties.py b/test/test_properties.py index 9e68765..3aca31b 100644 --- a/test/test_properties.py +++ b/test/test_properties.py @@ -162,23 +162,23 @@ def test_Property_override(): def test_Properties_mro(): - class A(HasProperties): - p = Property('base', StringType(), 'base', export='always') + class Base(HasProperties): + prop = Property('base', StringType(), 'base', export='always') - class B(A): + class SubA(Base): pass - class C(A): - p = Property('sub', FloatRange(), extname='p') + class SubB(Base): + prop = Property('sub', FloatRange(), extname='prop') - class D(C, B): - p = 1 + class FinalBA(SubB, SubA): + prop = 1 - class E(B, C): - p = 2 + class FinalAB(SubA, SubB): + prop = 2 - assert B().exportProperties() == {'_p': 'base'} - assert D().exportProperties() == {'p': 1.0} - # in an older implementation the following would fail, as B.p is constructed first - # and then B.p overrides C.p - assert E().exportProperties() == {'p': 2.0} + assert SubA().exportProperties() == {'_prop': 'base'} + assert FinalBA().exportProperties() == {'prop': 1.0} + # in an older implementation the following would fail, as SubA.p is constructed first + # and then SubA.p overrides SubB.p + assert FinalAB().exportProperties() == {'prop': 2.0}