[Libvirt-cim] [PATCH 1 of 2] [TEST] Add get_subset_test_list(): lists the tests in a given set of test dirs

Kaitlin Rupert kaitlin at linux.vnet.ibm.com
Wed Nov 18 21:46:53 UTC 2009


# HG changeset patch
# User Kaitlin Rupert <karupert at us.ibm.com>
# Date 1258580377 28800
# Node ID dfe044c37ec5b9f87db1a377743d9b928180018c
# Parent  c7907449b007aece4418f03272d8754b5fd41ac2
[TEST] Add get_subset_test_list(): lists the tests in a given set of test dirs

This function allows you to get the list of tests in the specified directories.
It supports two ways of specifying directories:

[dir1:dir2]  or [dir1,dir2,dir3]

Signed-off-by: Kaitlin Rupert <karupert at us.ibm.com>

diff -r c7907449b007 -r dfe044c37ec5 lib/VirtLib/groups.py
--- a/lib/VirtLib/groups.py	Mon Nov 09 13:24:52 2009 -0800
+++ b/lib/VirtLib/groups.py	Wed Nov 18 13:39:37 2009 -0800
@@ -37,7 +37,18 @@
         if os.path.isdir(group_p):
             ret.append(filename)
 
-    ret.sort()
+    #sort() doesn't handle upper and lower case comparisons properly.
+    #The following manipulation will ensure the list is in the same
+    #order 'ls' returns on a directory
+    tmp = []
+    for i, group in enumerate(ret):
+        tmp.append([group.lower(), group])
+
+    tmp.sort()
+    ret = []
+    for key, group in tmp:
+        ret.append(group)
+
     return ret
 
 def list_tests_in_group(test_suite, group_name):
@@ -93,3 +104,46 @@
             ret.append({ 'group': group, 'test': test})
             
     return ret
+
+def get_subset_test_list(test_suite, test_subset):
+    """Return a list of dictionaries for a specific set of groups.
+       It will contain the group and test filename
+    """
+    ret = []
+  
+    str = test_subset.strip('[]')
+
+    if test_subset.find(",") >= 0:
+        groups = str.split(',')
+
+    elif test_subset.find(":") >= 0:
+        groups = str.split(':')
+        if len(groups) != 2:
+            return ret
+
+        all_groups = list_groups(test_suite)
+        index_start = all_groups.index(groups[0])
+        index_end = all_groups.index(groups[1])
+
+        if index_start < 0:
+            print "Group %s (%d) was not found" % (groups[0], index_start)
+            return ret
+        elif index_end < 0:
+            print "Group %s (%d) was not found" % (groups[1], index_end)
+            return ret
+        elif index_end < index_start:
+            print "Group %s's index (%d) is < Group %s's index (%d)" % \
+                   (groups[1], index_end, groups[0], index_start)
+            return ret
+
+        groups = all_groups[index_start:index_end + 1]
+
+    else:
+        return ret
+
+    for group in groups:
+        tmp = get_group_test_list(test_suite, group)
+        ret = ret + tmp
+
+    return ret
+




More information about the Libvirt-cim mailing list