code style reformatting using black
This commit is contained in:
parent
4127bcffd0
commit
744cb0c503
1 changed files with 21394 additions and 10488 deletions
|
|
@ -26,7 +26,6 @@ from xml.dom import minidom
|
|||
|
||||
|
||||
class MemoryTest(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.host = helpers.FakeSAT()
|
||||
|
||||
|
|
@ -37,14 +36,19 @@ class MemoryTest(unittest.TestCase):
|
|||
@param security_level: security level of the parameters
|
||||
@return (str)
|
||||
"""
|
||||
|
||||
def getParam(name):
|
||||
return """
|
||||
<param name="%(param_name)s" label="%(param_label)s" value="true" type="bool" %(security)s/>
|
||||
""" % {'param_name': name,
|
||||
'param_label': _(name),
|
||||
'security': '' if security_level is None else ('security="%d"' % security_level)
|
||||
}
|
||||
params = ''
|
||||
""" % {
|
||||
"param_name": name,
|
||||
"param_label": _(name),
|
||||
"security": ""
|
||||
if security_level is None
|
||||
else ('security="%d"' % security_level),
|
||||
}
|
||||
|
||||
params = ""
|
||||
if "1" in param:
|
||||
params += getParam(Const.ENABLE_UNIBOX_PARAM)
|
||||
if "2" in param:
|
||||
|
|
@ -60,9 +64,9 @@ class MemoryTest(unittest.TestCase):
|
|||
</individual>
|
||||
</params>
|
||||
""" % {
|
||||
'category_name': Const.COMPOSITION_KEY,
|
||||
'category_label': _(Const.COMPOSITION_KEY),
|
||||
'params': params
|
||||
"category_name": Const.COMPOSITION_KEY,
|
||||
"category_label": _(Const.COMPOSITION_KEY),
|
||||
"params": params,
|
||||
}
|
||||
|
||||
def _paramExists(self, param="1", src=None):
|
||||
|
|
@ -86,7 +90,10 @@ class MemoryTest(unittest.TestCase):
|
|||
if type_node.nodeName not in ("individual", "general", "params"):
|
||||
continue
|
||||
for cat_node in type_node.childNodes:
|
||||
if cat_node.nodeName != "category" or cat_node.getAttribute("name") != category:
|
||||
if (
|
||||
cat_node.nodeName != "category"
|
||||
or cat_node.getAttribute("name") != category
|
||||
):
|
||||
continue
|
||||
for param in cat_node.childNodes:
|
||||
if param.nodeName == "param" and param.getAttribute("name") == name:
|
||||
|
|
@ -100,7 +107,11 @@ class MemoryTest(unittest.TestCase):
|
|||
@param exists (boolean): True to assert the param exists, False to assert it doesn't
|
||||
@param deferred (boolean): True if this method is called from a Deferred callback
|
||||
"""
|
||||
msg = "Expected parameter not found!\n" if exists else "Unexpected parameter found!\n"
|
||||
msg = (
|
||||
"Expected parameter not found!\n"
|
||||
if exists
|
||||
else "Unexpected parameter found!\n"
|
||||
)
|
||||
if deferred:
|
||||
# in this stack we can see the line where the error came from,
|
||||
# if limit=5, 6 is not enough you can increase the value
|
||||
|
|
@ -116,21 +127,25 @@ class MemoryTest(unittest.TestCase):
|
|||
|
||||
def assertParamExists_async(self, src, param="1"):
|
||||
"""@param src: a deferred result from Memory.getParams"""
|
||||
self.assertParam_generic(param, minidom.parseString(src.encode("utf-8")), True, True)
|
||||
self.assertParam_generic(
|
||||
param, minidom.parseString(src.encode("utf-8")), True, True
|
||||
)
|
||||
|
||||
def assertParamNotExists_async(self, src, param="1"):
|
||||
"""@param src: a deferred result from Memory.getParams"""
|
||||
self.assertParam_generic(param, minidom.parseString(src.encode("utf-8")), False, True)
|
||||
self.assertParam_generic(
|
||||
param, minidom.parseString(src.encode("utf-8")), False, True
|
||||
)
|
||||
|
||||
def _getParams(self, security_limit, app='', profile_key='@NONE@'):
|
||||
def _getParams(self, security_limit, app="", profile_key="@NONE@"):
|
||||
"""Get the parameters accessible with the given security limit and application name.
|
||||
|
||||
@param security_limit (int): the security limit
|
||||
@param app (str): empty string or "libervia"
|
||||
@param profile_key
|
||||
"""
|
||||
if profile_key == '@NONE@':
|
||||
profile_key = '@DEFAULT@'
|
||||
if profile_key == "@NONE@":
|
||||
profile_key = "@DEFAULT@"
|
||||
return self.host.memory.params.getParams(security_limit, app, profile_key)
|
||||
|
||||
def test_updateParams(self):
|
||||
|
|
@ -141,14 +156,17 @@ class MemoryTest(unittest.TestCase):
|
|||
previous = self.host.memory.params.dom.cloneNode(True)
|
||||
# now check if it is really updated and not duplicated
|
||||
self.host.memory.updateParams(self._getParamXML())
|
||||
self.assertEqual(previous.toxml().encode("utf-8"), self.host.memory.params.dom.toxml().encode("utf-8"))
|
||||
self.assertEqual(
|
||||
previous.toxml().encode("utf-8"),
|
||||
self.host.memory.params.dom.toxml().encode("utf-8"),
|
||||
)
|
||||
|
||||
self.host.memory.reinit()
|
||||
# check successive updates (without intersection)
|
||||
self.host.memory.updateParams(self._getParamXML('1'))
|
||||
self.host.memory.updateParams(self._getParamXML("1"))
|
||||
self.assertParamExists("1")
|
||||
self.assertParamNotExists("2")
|
||||
self.host.memory.updateParams(self._getParamXML('2'))
|
||||
self.host.memory.updateParams(self._getParamXML("2"))
|
||||
self.assertParamExists("1")
|
||||
self.assertParamExists("2")
|
||||
|
||||
|
|
@ -156,19 +174,22 @@ class MemoryTest(unittest.TestCase):
|
|||
|
||||
self.host.memory.reinit()
|
||||
# check successive updates (with intersection)
|
||||
self.host.memory.updateParams(self._getParamXML('1'))
|
||||
self.host.memory.updateParams(self._getParamXML("1"))
|
||||
self.assertParamExists("1")
|
||||
self.assertParamNotExists("2")
|
||||
self.host.memory.updateParams(self._getParamXML('12'))
|
||||
self.host.memory.updateParams(self._getParamXML("12"))
|
||||
self.assertParamExists("1")
|
||||
self.assertParamExists("2")
|
||||
|
||||
# successive updates with or without intersection should have the same result
|
||||
self.assertEqual(previous.toxml().encode("utf-8"), self.host.memory.params.dom.toxml().encode("utf-8"))
|
||||
self.assertEqual(
|
||||
previous.toxml().encode("utf-8"),
|
||||
self.host.memory.params.dom.toxml().encode("utf-8"),
|
||||
)
|
||||
|
||||
self.host.memory.reinit()
|
||||
# one update with two params in a new category
|
||||
self.host.memory.updateParams(self._getParamXML('12'))
|
||||
self.host.memory.updateParams(self._getParamXML("12"))
|
||||
self.assertParamExists("1")
|
||||
self.assertParamExists("2")
|
||||
|
||||
|
|
@ -196,7 +217,6 @@ class MemoryTest(unittest.TestCase):
|
|||
return self._getParams(1).addCallback(self.assertParamExists_async)
|
||||
|
||||
def test_paramsRegisterApp(self):
|
||||
|
||||
def register(xml, security_limit, app):
|
||||
"""
|
||||
@param xml: XML definition of the parameters to be added
|
||||
|
|
@ -271,17 +291,23 @@ class MemoryTest(unittest.TestCase):
|
|||
self.host.memory.reinit()
|
||||
params = self._getParamXML(security_level=1)
|
||||
self.host.memory.paramsRegisterApp(params, 1, Const.APP_NAME)
|
||||
self._getParams(1, '').addCallback(self.assertParamExists_async)
|
||||
self._getParams(1, "").addCallback(self.assertParamExists_async)
|
||||
self._getParams(1, Const.APP_NAME).addCallback(self.assertParamExists_async)
|
||||
self._getParams(1, 'another_dummy_frontend').addCallback(self.assertParamNotExists_async)
|
||||
self._getParams(1, "another_dummy_frontend").addCallback(
|
||||
self.assertParamNotExists_async
|
||||
)
|
||||
|
||||
# the same with several parameters registered at the same time
|
||||
self.host.memory.reinit()
|
||||
params = self._getParamXML('12', security_level=0)
|
||||
params = self._getParamXML("12", security_level=0)
|
||||
self.host.memory.paramsRegisterApp(params, 5, Const.APP_NAME)
|
||||
self._getParams(5, '').addCallback(self.assertParamExists_async)
|
||||
self._getParams(5, '').addCallback(self.assertParamExists_async, "2")
|
||||
self._getParams(5, "").addCallback(self.assertParamExists_async)
|
||||
self._getParams(5, "").addCallback(self.assertParamExists_async, "2")
|
||||
self._getParams(5, Const.APP_NAME).addCallback(self.assertParamExists_async)
|
||||
self._getParams(5, Const.APP_NAME).addCallback(self.assertParamExists_async, "2")
|
||||
self._getParams(5, 'another_dummy_frontend').addCallback(self.assertParamNotExists_async)
|
||||
return self._getParams(5, 'another_dummy_frontend').addCallback(self.assertParamNotExists_async, "2")
|
||||
self._getParams(5, "another_dummy_frontend").addCallback(
|
||||
self.assertParamNotExists_async
|
||||
)
|
||||
return self._getParams(5, "another_dummy_frontend").addCallback(
|
||||
self.assertParamNotExists_async, "2"
|
||||
)
|
||||
|
|
|
|||
Loading…
Reference in a new issue