[gnome-continuous-yocto/gnomeostree-3.28-rocko: 3343/8267] oe-selftest: fix handling of test cases without ID in --list-tests-by



commit 59c8ae17420564a08490d7978560ef276c2b089a
Author: Maciej Borzecki <maciej borzecki rndity com>
Date:   Thu Nov 10 13:18:37 2016 +0100

    oe-selftest: fix handling of test cases without ID in --list-tests-by
    
    Running `oe-selftest --list-tests-by module wic` will produce the
    following backtrace:
    
    Traceback (most recent call last):
      File "<snip>/poky/scripts/oe-selftest", line 668, in <module>
        ret = main()
      File "<snip>/poky/scripts/oe-selftest", line 486, in main
        list_testsuite_by(criteria, keyword)
      File "<snip>/poky/scripts/oe-selftest", line 340, in list_testsuite_by
        ts = sorted([ (tc.tcid, tc.tctag, tc.tcname, tc.tcclass, tc.tcmodule) for tc in 
get_testsuite_by(criteria, keyword) ])
    TypeError: unorderable types: int() < NoneType()
    
    The root cause is that a test case does not necessarily have an ID
    assigned, hence its value is None. Since Python 3 does not allow
    comparison of heterogeneous types, TypeError is raised.
    
    (From OE-Core rev: 71c6790689e2cbd3c4e882335b3b03e635ad46ed)
    
    Signed-off-by: Maciej Borzecki <maciej borzecki rndity com>
    Signed-off-by: Ross Burton <ross burton intel com>
    Signed-off-by: Richard Purdie <richard purdie linuxfoundation org>

 scripts/oe-selftest |   13 +++++++++----
 1 files changed, 9 insertions(+), 4 deletions(-)
---
diff --git a/scripts/oe-selftest b/scripts/oe-selftest
index d9ffd40..c3215ea 100755
--- a/scripts/oe-selftest
+++ b/scripts/oe-selftest
@@ -336,10 +336,15 @@ def list_testsuite_by(criteria, keyword):
     # Get a testsuite based on 'keyword'
     # criteria: name, class, module, id, tag
     # keyword: a list of tests, classes, modules, ids, tags
-
-    ts = sorted([ (tc.tcid, tc.tctag, tc.tcname, tc.tcclass, tc.tcmodule) for tc in 
get_testsuite_by(criteria, keyword) ])
-
-    print('%-4s\t%-20s\t%-60s\t%-25s\t%-20s' % ('id', 'tag', 'name', 'class', 'module'))
+    def tc_key(t):
+        if t[0] is None:
+            return  (0,) + t[1:]
+        return t
+    # tcid may be None if no ID was assigned, in which case sorted() will throw
+    # a TypeError as Python 3 does not allow comparison (<,<=,>=,>) of
+    # heterogeneous types, handle this by using a custom key generator
+    ts = sorted([ (tc.tcid, tc.tctag, tc.tcname, tc.tcclass, tc.tcmodule) \
+                  for tc in get_testsuite_by(criteria, keyword) ], key=tc_key)
     print('_' * 150)
     for t in ts:
         if isinstance(t[1], (tuple, list)):


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]