[pgAdmin][RM4560] Allow RE-SQL test cases to be run for a module using --modules

Aditya Toshniwal <[email protected]>
Newsgroups gmane.comp.db.postgresql.pgadmin.devel
Message-ID <CAM9w-_m7v1hvvCZKV3ibXcs8aC0wOLR9mvJ__1jZqLpre8NdQQ@mail.gmail.com>
Hi Hackers,

Attached patch will allow to RE-SQL to run for certain modules using a
command line flag --modules foo,bar.
Added the info to README.

Kindly review.

-- 
Thanks and Regards,
Aditya Toshniwal
Software Engineer | EnterpriseDB India | Pune
"Don't Complain about Heat, Plant a TREE"
RM4560.patch (application/octet-stream, 4.3 KB)
diff --git a/web/pgadmin/utils/route.py b/web/pgadmin/utils/route.py
index 8629dbbd..6e99c7ed 100644
--- a/web/pgadmin/utils/route.py
+++ b/web/pgadmin/utils/route.py
@@ -65,7 +65,8 @@ class TestsGeneratorRegistry(ABCMeta):
         all_modules.append('regression.re_sql.tests.test_resql')
 
         # If specific modules are to be tested, exclude others
-        if len(for_modules) > 0:
+        # for modules are handled differently for resql
+        if not is_resql_only and len(for_modules) > 0:
             all_modules = [module_name
                            for module_name in all_modules
                            for fmod in for_modules
@@ -79,6 +80,7 @@ class TestsGeneratorRegistry(ABCMeta):
         # Check if only reverse engineered sql test cases to run
         # if yes then import only that module
         if is_resql_only:
+            BaseTestGenerator.setForModules(for_modules)
             try:
                 import_module('regression.re_sql.tests.test_resql')
             except ImportError:
@@ -147,3 +149,7 @@ class BaseTestGenerator(unittest.TestCase):
     @classmethod
     def setExcludePkgs(cls, exclude_pkgs):
         cls.exclude_pkgs = exclude_pkgs
+
+    @classmethod
+    def setForModules(cls, for_modules):
+        cls.for_modules = for_modules
diff --git a/web/regression/README b/web/regression/README
index fec091e2..abc929ae 100644
--- a/web/regression/README
+++ b/web/regression/README
@@ -151,6 +151,9 @@ Python Tests:
 - Execute only reverse engineered sql test framework for all nodes
      run 'python runtests.py --pkg resql'
 
+- Execute only reverse engineered sql test framework for some modules
+     run 'python runtests.py --pkg resql --modules sequences,functions'
+
 - Execute test framework for entire package
 
      Example 1) Run test framework for 'browser' package
diff --git a/web/regression/re_sql/tests/test_resql.py b/web/regression/re_sql/tests/test_resql.py
index ee777a6b..8d8fd381 100644
--- a/web/regression/re_sql/tests/test_resql.py
+++ b/web/regression/re_sql/tests/test_resql.py
@@ -22,7 +22,7 @@ from pgadmin.utils.versioned_template_loader import \
     get_version_mapping_directories
 
 
-def create_resql_module_list(all_modules, exclude_pkgs):
+def create_resql_module_list(all_modules, exclude_pkgs, for_modules):
     """
     This function is used to create the module list for reverse engineered
     SQL by iterating all the modules.
@@ -41,7 +41,13 @@ def create_resql_module_list(all_modules, exclude_pkgs):
             module_name_list = complete_module_name[0].split(".")
             module_name = module_name_list[len(module_name_list) - 1]
 
-            resql_module_list[module_name] = os.path.join(*module_name_list)
+            if len(for_modules) > 0:
+                if module_name in for_modules:
+                    resql_module_list[module_name] = \
+                        os.path.join(*module_name_list)
+            else:
+                resql_module_list[module_name] = \
+                    os.path.join(*module_name_list)
 
     return resql_module_list
 
@@ -87,7 +93,8 @@ class ReverseEngineeredSQLTestCases(BaseTestGenerator):
 
         resql_module_list = create_resql_module_list(
             BaseTestGenerator.re_sql_module_list,
-            BaseTestGenerator.exclude_pkgs)
+            BaseTestGenerator.exclude_pkgs,
+            getattr(BaseTestGenerator, 'for_modules', []))
 
         for module in resql_module_list:
             self.table_id = None
diff --git a/web/regression/runtests.py b/web/regression/runtests.py
index df94be3a..540eae65 100644
--- a/web/regression/runtests.py
+++ b/web/regression/runtests.py
@@ -253,9 +253,13 @@ def get_test_modules(arguments):
     if arguments['pkg'] is None or arguments['pkg'] == "all":
         TestsGeneratorRegistry.load_generators('pgadmin', exclude_pkgs)
     elif arguments['pkg'] is not None and arguments['pkg'] == "resql":
+        for_modules = []
+        if arguments['modules'] is not None:
+            for_modules = arguments['modules'].split(',')
+
         # Load the reverse engineering sql test module
         TestsGeneratorRegistry.load_generators('pgadmin', exclude_pkgs,
-                                               is_resql_only=True)
+                                               for_modules, is_resql_only=True)
     else:
         for_modules = []
         if arguments['modules'] is not None:
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.