Github user iyerr3 commented on a diff in the pull request:
https://github.com/apache/madlib/pull/290#discussion_r201876605
--- Diff: src/madpack/madpack.py ---
@@ -809,22 +811,100 @@ def parse_arguments():
help="Temporary directory location for
installation log files.")
parser.add_argument('-t', '--testcase', dest='testcase', default="",
- help="Module names to test, comma separated.
Effective only for install-check.")
+ help="Module names to test, comma separated.
Effective only for install-check, dev-check and unit-test.")
# Get the arguments
return parser.parse_args()
+def _is_madlib_installation_valid_for_tests(schema, db_madlib_ver):
+ # Compare OS and DB versions. Continue if OS = DB.
+ if get_rev_num(db_madlib_ver) != get_rev_num(new_madlib_ver):
+ _print_vers(new_madlib_ver, db_madlib_ver, con_args, schema)
+ info_(this, "Versions do not match. Unit-test stopped.", True)
+ return False
+ return True
+
+def _get_modset_for_tests(testcase, filename_prefix=''):
+ # Get all module and algo names to run tests for, is specified as a
comma
+ # separated list.
+ info_(this, "> Running unit test scripts for:", verbose)
+ caseset = (set([test.strip() for test in testcase.split(',')])
+ if testcase != "" else set())
+ modset = {}
+ for case in caseset:
+ if case.find('/') > -1:
+ [mod, algo] = case.split('/')
+ if mod not in modset:
+ modset[mod] = []
+ if algo not in modset[mod]:
+ modset[mod].append(filename_prefix+algo)
+ else:
+ modset[case] = []
+ return modset
+
+def run_unit_tests(args, testcase):
+ """
+ Run unit tests.
+ """
+ if not _is_madlib_installation_valid_for_tests(args['schema'],
+ args['db_madlib_ver']):
+ return
+ modset = _get_modset_for_tests(testcase, 'test_')
+ # Loop through all modules and run unit tests
+ for moduleinfo in portspecs['modules']:
--- End diff --
We've a similar loop/pattern in multiple places within `madpack.py`. Can we
refactor them all to simplify these functions.
---