Mercurial > libervia-backend
diff sat/test/test_memory.py @ 2624:56f94936df1e
code style reformatting using black
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 27 Jun 2018 20:14:46 +0200 |
parents | 26edcf3a30eb |
children | 003b8b4b56a7 |
line wrap: on
line diff
--- a/sat/test/test_memory.py Wed Jun 27 07:51:29 2018 +0200 +++ b/sat/test/test_memory.py Wed Jun 27 20:14:46 2018 +0200 @@ -26,7 +26,6 @@ class MemoryTest(unittest.TestCase): - def setUp(self): self.host = helpers.FakeSAT() @@ -37,14 +36,19 @@ @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 @@ </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 @@ 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 @@ @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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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" + )