diff sat/test/test_memory.py @ 4037:524856bd7b19

massive refactoring to switch from camelCase to snake_case: historically, Libervia (SàT before) was using camelCase as allowed by PEP8 when using a pre-PEP8 code, to use the same coding style as in Twisted. However, snake_case is more readable and it's better to follow PEP8 best practices, so it has been decided to move on full snake_case. Because Libervia has a huge codebase, this ended with a ugly mix of camelCase and snake_case. To fix that, this patch does a big refactoring by renaming every function and method (including bridge) that are not coming from Twisted or Wokkel, to use fully snake_case. This is a massive change, and may result in some bugs.
author Goffi <goffi@goffi.org>
date Sat, 08 Apr 2023 13:54:42 +0200
parents be6d91572633
children
line wrap: on
line diff
--- a/sat/test/test_memory.py	Fri Apr 07 15:18:39 2023 +0200
+++ b/sat/test/test_memory.py	Sat Apr 08 13:54:42 2023 +0200
@@ -29,7 +29,7 @@
     def setUp(self):
         self.host = helpers.FakeSAT()
 
-    def _getParamXML(self, param="1", security_level=None):
+    def _get_param_xml(self, param="1", security_level=None):
         """Generate XML for testing parameters
 
         @param param (str): a subset of "123"
@@ -37,7 +37,7 @@
         @return (str)
         """
 
-        def getParam(name):
+        def get_param(name):
             return """
             <param name="%(param_name)s" label="%(param_label)s" value="true" type="bool" %(security)s/>
             """ % {
@@ -50,11 +50,11 @@
 
         params = ""
         if "1" in param:
-            params += getParam(Const.ENABLE_UNIBOX_PARAM)
+            params += get_param(Const.ENABLE_UNIBOX_PARAM)
         if "2" in param:
-            params += getParam(Const.PARAM_IN_QUOTES)
+            params += get_param(Const.PARAM_IN_QUOTES)
         if "3" in param:
-            params += getParam("Dummy param")
+            params += get_param("Dummy param")
         return """
         <params>
         <individual>
@@ -69,7 +69,7 @@
             "params": params,
         }
 
-    def _paramExists(self, param="1", src=None):
+    def _param_exists(self, param="1", src=None):
         """
 
         @param param (str): a character in "12"
@@ -86,7 +86,7 @@
         for type_node in src.childNodes:
             # when src comes self.host.memory.params.dom, we have here
             # some "individual" or "general" elements, when it comes
-            # from Memory.getParams we have here a "params" elements
+            # from Memory.get_params we have here a "params" elements
             if type_node.nodeName not in ("individual", "general", "params"):
                 continue
             for cat_node in type_node.childNodes:
@@ -100,7 +100,7 @@
                         return True
         return False
 
-    def assertParam_generic(self, param="1", src=None, exists=True, deferred=False):
+    def assert_param_generic(self, param="1", src=None, exists=True, deferred=False):
         """
         @param param (str): a character in "12"
         @param src (DOM element): the top-level element to look in
@@ -116,28 +116,28 @@
             # 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
             msg += "\n".join(traceback.format_stack(limit=5 if exists else 6))
-        assertion = self._paramExists(param, src)
+        assertion = self._param_exists(param, src)
         getattr(self, "assert%s" % exists)(assertion, msg)
 
-    def assertParamExists(self, param="1", src=None):
-        self.assertParam_generic(param, src, True)
+    def assert_param_exists(self, param="1", src=None):
+        self.assert_param_generic(param, src, True)
 
-    def assertParamNotExists(self, param="1", src=None):
-        self.assertParam_generic(param, src, False)
+    def assert_param_not_exists(self, param="1", src=None):
+        self.assert_param_generic(param, src, False)
 
-    def assertParamExists_async(self, src, param="1"):
-        """@param src: a deferred result from Memory.getParams"""
-        self.assertParam_generic(
+    def assert_param_exists_async(self, src, param="1"):
+        """@param src: a deferred result from Memory.get_params"""
+        self.assert_param_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(
+    def assert_param_not_exists_async(self, src, param="1"):
+        """@param src: a deferred result from Memory.get_params"""
+        self.assert_param_generic(
             param, minidom.parseString(src.encode("utf-8")), False, True
         )
 
-    def _getParams(self, security_limit, app="", profile_key="@NONE@"):
+    def _get_params(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
@@ -146,16 +146,16 @@
         """
         if profile_key == "@NONE@":
             profile_key = "@DEFAULT@"
-        return self.host.memory.params.getParams(security_limit, app, profile_key)
+        return self.host.memory.params.get_params(security_limit, app, profile_key)
 
-    def test_updateParams(self):
+    def test_update_params(self):
         self.host.memory.reinit()
         # check if the update works
-        self.host.memory.updateParams(self._getParamXML())
-        self.assertParamExists()
+        self.host.memory.update_params(self._get_param_xml())
+        self.assert_param_exists()
         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.host.memory.update_params(self._get_param_xml())
         self.assertEqual(
             previous.toxml().encode("utf-8"),
             self.host.memory.params.dom.toxml().encode("utf-8"),
@@ -163,23 +163,23 @@
 
         self.host.memory.reinit()
         # check successive updates (without intersection)
-        self.host.memory.updateParams(self._getParamXML("1"))
-        self.assertParamExists("1")
-        self.assertParamNotExists("2")
-        self.host.memory.updateParams(self._getParamXML("2"))
-        self.assertParamExists("1")
-        self.assertParamExists("2")
+        self.host.memory.update_params(self._get_param_xml("1"))
+        self.assert_param_exists("1")
+        self.assert_param_not_exists("2")
+        self.host.memory.update_params(self._get_param_xml("2"))
+        self.assert_param_exists("1")
+        self.assert_param_exists("2")
 
         previous = self.host.memory.params.dom.cloneNode(True)  # save for later
 
         self.host.memory.reinit()
         # check successive updates (with intersection)
-        self.host.memory.updateParams(self._getParamXML("1"))
-        self.assertParamExists("1")
-        self.assertParamNotExists("2")
-        self.host.memory.updateParams(self._getParamXML("12"))
-        self.assertParamExists("1")
-        self.assertParamExists("2")
+        self.host.memory.update_params(self._get_param_xml("1"))
+        self.assert_param_exists("1")
+        self.assert_param_not_exists("2")
+        self.host.memory.update_params(self._get_param_xml("12"))
+        self.assert_param_exists("1")
+        self.assert_param_exists("2")
 
         # successive updates with or without intersection should have the same result
         self.assertEqual(
@@ -189,125 +189,125 @@
 
         self.host.memory.reinit()
         # one update with two params in a new category
-        self.host.memory.updateParams(self._getParamXML("12"))
-        self.assertParamExists("1")
-        self.assertParamExists("2")
+        self.host.memory.update_params(self._get_param_xml("12"))
+        self.assert_param_exists("1")
+        self.assert_param_exists("2")
 
-    def test_getParams(self):
+    def test_get_params(self):
         # tests with no security level on the parameter (most secure)
-        params = self._getParamXML()
+        params = self._get_param_xml()
         self.host.memory.reinit()
-        self.host.memory.updateParams(params)
-        self._getParams(Const.NO_SECURITY_LIMIT).addCallback(self.assertParamExists_async)
-        self._getParams(0).addCallback(self.assertParamNotExists_async)
-        self._getParams(1).addCallback(self.assertParamNotExists_async)
+        self.host.memory.update_params(params)
+        self._get_params(Const.NO_SECURITY_LIMIT).addCallback(self.assert_param_exists_async)
+        self._get_params(0).addCallback(self.assert_param_not_exists_async)
+        self._get_params(1).addCallback(self.assert_param_not_exists_async)
         # tests with security level 0 on the parameter (not secure)
-        params = self._getParamXML(security_level=0)
+        params = self._get_param_xml(security_level=0)
         self.host.memory.reinit()
-        self.host.memory.updateParams(params)
-        self._getParams(Const.NO_SECURITY_LIMIT).addCallback(self.assertParamExists_async)
-        self._getParams(0).addCallback(self.assertParamExists_async)
-        self._getParams(1).addCallback(self.assertParamExists_async)
+        self.host.memory.update_params(params)
+        self._get_params(Const.NO_SECURITY_LIMIT).addCallback(self.assert_param_exists_async)
+        self._get_params(0).addCallback(self.assert_param_exists_async)
+        self._get_params(1).addCallback(self.assert_param_exists_async)
         # tests with security level 1 on the parameter (more secure)
-        params = self._getParamXML(security_level=1)
+        params = self._get_param_xml(security_level=1)
         self.host.memory.reinit()
-        self.host.memory.updateParams(params)
-        self._getParams(Const.NO_SECURITY_LIMIT).addCallback(self.assertParamExists_async)
-        self._getParams(0).addCallback(self.assertParamNotExists_async)
-        return self._getParams(1).addCallback(self.assertParamExists_async)
+        self.host.memory.update_params(params)
+        self._get_params(Const.NO_SECURITY_LIMIT).addCallback(self.assert_param_exists_async)
+        self._get_params(0).addCallback(self.assert_param_not_exists_async)
+        return self._get_params(1).addCallback(self.assert_param_exists_async)
 
-    def test_paramsRegisterApp(self):
+    def test_params_register_app(self):
         def register(xml, security_limit, app):
             """
             @param xml: XML definition of the parameters to be added
             @param security_limit: -1 means no security, 0 is the maximum security then the higher the less secure
             @param app: name of the frontend registering the parameters
             """
-            helpers.muteLogging()
-            self.host.memory.paramsRegisterApp(xml, security_limit, app)
-            helpers.unmuteLogging()
+            helpers.mute_logging()
+            self.host.memory.params_register_app(xml, security_limit, app)
+            helpers.unmute_logging()
 
         # tests with no security level on the parameter (most secure)
-        params = self._getParamXML()
+        params = self._get_param_xml()
         self.host.memory.reinit()
         register(params, Const.NO_SECURITY_LIMIT, Const.APP_NAME)
-        self.assertParamExists()
+        self.assert_param_exists()
         self.host.memory.reinit()
         register(params, 0, Const.APP_NAME)
-        self.assertParamNotExists()
+        self.assert_param_not_exists()
         self.host.memory.reinit()
         register(params, 1, Const.APP_NAME)
-        self.assertParamNotExists()
+        self.assert_param_not_exists()
 
         # tests with security level 0 on the parameter (not secure)
-        params = self._getParamXML(security_level=0)
+        params = self._get_param_xml(security_level=0)
         self.host.memory.reinit()
         register(params, Const.NO_SECURITY_LIMIT, Const.APP_NAME)
-        self.assertParamExists()
+        self.assert_param_exists()
         self.host.memory.reinit()
         register(params, 0, Const.APP_NAME)
-        self.assertParamExists()
+        self.assert_param_exists()
         self.host.memory.reinit()
         register(params, 1, Const.APP_NAME)
-        self.assertParamExists()
+        self.assert_param_exists()
 
         # tests with security level 1 on the parameter (more secure)
-        params = self._getParamXML(security_level=1)
+        params = self._get_param_xml(security_level=1)
         self.host.memory.reinit()
         register(params, Const.NO_SECURITY_LIMIT, Const.APP_NAME)
-        self.assertParamExists()
+        self.assert_param_exists()
         self.host.memory.reinit()
         register(params, 0, Const.APP_NAME)
-        self.assertParamNotExists()
+        self.assert_param_not_exists()
         self.host.memory.reinit()
         register(params, 1, Const.APP_NAME)
-        self.assertParamExists()
+        self.assert_param_exists()
 
         # tests with security level 1 and several parameters being registered
-        params = self._getParamXML("12", security_level=1)
+        params = self._get_param_xml("12", security_level=1)
         self.host.memory.reinit()
         register(params, Const.NO_SECURITY_LIMIT, Const.APP_NAME)
-        self.assertParamExists()
-        self.assertParamExists("2")
+        self.assert_param_exists()
+        self.assert_param_exists("2")
         self.host.memory.reinit()
         register(params, 0, Const.APP_NAME)
-        self.assertParamNotExists()
-        self.assertParamNotExists("2")
+        self.assert_param_not_exists()
+        self.assert_param_not_exists("2")
         self.host.memory.reinit()
         register(params, 1, Const.APP_NAME)
-        self.assertParamExists()
-        self.assertParamExists("2")
+        self.assert_param_exists()
+        self.assert_param_exists("2")
 
         # tests with several parameters being registered in an existing category
         self.host.memory.reinit()
-        self.host.memory.updateParams(self._getParamXML("3"))
-        register(self._getParamXML("12"), Const.NO_SECURITY_LIMIT, Const.APP_NAME)
-        self.assertParamExists()
-        self.assertParamExists("2")
+        self.host.memory.update_params(self._get_param_xml("3"))
+        register(self._get_param_xml("12"), Const.NO_SECURITY_LIMIT, Const.APP_NAME)
+        self.assert_param_exists()
+        self.assert_param_exists("2")
         self.host.memory.reinit()
 
-    def test_paramsRegisterApp_getParams(self):
+    def test_params_register_app_get_params(self):
         # test retrieving the parameter for a specific frontend
         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, Const.APP_NAME).addCallback(self.assertParamExists_async)
-        self._getParams(1, "another_dummy_frontend").addCallback(
-            self.assertParamNotExists_async
+        params = self._get_param_xml(security_level=1)
+        self.host.memory.params_register_app(params, 1, Const.APP_NAME)
+        self._get_params(1, "").addCallback(self.assert_param_exists_async)
+        self._get_params(1, Const.APP_NAME).addCallback(self.assert_param_exists_async)
+        self._get_params(1, "another_dummy_frontend").addCallback(
+            self.assert_param_not_exists_async
         )
 
         # the same with several parameters registered at the same time
         self.host.memory.reinit()
-        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, 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
+        params = self._get_param_xml("12", security_level=0)
+        self.host.memory.params_register_app(params, 5, Const.APP_NAME)
+        self._get_params(5, "").addCallback(self.assert_param_exists_async)
+        self._get_params(5, "").addCallback(self.assert_param_exists_async, "2")
+        self._get_params(5, Const.APP_NAME).addCallback(self.assert_param_exists_async)
+        self._get_params(5, Const.APP_NAME).addCallback(self.assert_param_exists_async, "2")
+        self._get_params(5, "another_dummy_frontend").addCallback(
+            self.assert_param_not_exists_async
         )
-        return self._getParams(5, "another_dummy_frontend").addCallback(
-            self.assertParamNotExists_async, "2"
+        return self._get_params(5, "another_dummy_frontend").addCallback(
+            self.assert_param_not_exists_async, "2"
         )