[Lldb-commits] [PATCH] Allow ExpectedFailure* decorators to work with optional arguments

Ying Chen chying at google.com
Thu Mar 26 16:30:46 PDT 2015


Sorry for the delay. Had to spend some time to understand decorator in Python.
As suggested by Chaoren, removed bugnumber check from all caller functions, and handle None case in expectedFailure.


http://reviews.llvm.org/D8595

Files:
  test/lldbtest.py

Index: test/lldbtest.py
===================================================================
--- test/lldbtest.py
+++ test/lldbtest.py
@@ -549,59 +549,60 @@
             if expected_fn(self):
                 raise case._UnexpectedSuccess(sys.exc_info(), bugnumber)
         return wrapper
-    if bugnumber: 
-        if callable(bugnumber):
-            return expectedFailure_impl(bugnumber)
-        else:
-            return expectedFailure_impl
+    # if bugnumber is not-callable(incluing None), that means decorator function is called with optional arguments
+    # return decorator in this case, so it will be used to decorating original method
+    if callable(bugnumber):
+        return expectedFailure_impl(bugnumber)
+    else:
+        return expectedFailure_impl
 
 def expectedFailureCompiler(compiler, compiler_version=None, bugnumber=None):
     if compiler_version is None:
         compiler_version=['=', None]
     def fn(self):
         return compiler in self.getCompiler() and self.expectedCompilerVersion(compiler_version)
-    if bugnumber: return expectedFailure(fn, bugnumber)
+    return expectedFailure(fn, bugnumber)
 
 # to XFAIL a specific clang versions, try this
 # @expectedFailureClang('bugnumber', ['<=', '3.4'])
 def expectedFailureClang(bugnumber=None, compiler_version=None):
-    if bugnumber: return expectedFailureCompiler('clang', compiler_version, bugnumber)
+    return expectedFailureCompiler('clang', compiler_version, bugnumber)
 
 def expectedFailureGcc(bugnumber=None, compiler_version=None):
-    if bugnumber: return expectedFailureCompiler('gcc', compiler_version, bugnumber)
+    return expectedFailureCompiler('gcc', compiler_version, bugnumber)
 
 def expectedFailureIcc(bugnumber=None):
-    if bugnumber: return expectedFailureCompiler('icc', None, bugnumber)
+    return expectedFailureCompiler('icc', None, bugnumber)
 
 def expectedFailureArch(arch, bugnumber=None):
     def fn(self):
         return arch in self.getArchitecture()
-    if bugnumber: return expectedFailure(fn, bugnumber)
+    return expectedFailure(fn, bugnumber)
 
 def expectedFailurei386(bugnumber=None):
-    if bugnumber: return expectedFailureArch('i386', bugnumber)
+    return expectedFailureArch('i386', bugnumber)
 
 def expectedFailurex86_64(bugnumber=None):
-    if bugnumber: return expectedFailureArch('x86_64', bugnumber)
+    return expectedFailureArch('x86_64', bugnumber)
 
 def expectedFailureOS(oslist, bugnumber=None, compilers=None):
     def fn(self):
         return (lldb.DBG.GetSelectedPlatform().GetTriple().split('-')[2] in oslist and
                 self.expectedCompiler(compilers))
-    if bugnumber: return expectedFailure(fn, bugnumber)
+    return expectedFailure(fn, bugnumber)
 
 def expectedFailureDarwin(bugnumber=None, compilers=None):
     # For legacy reasons, we support both "darwin" and "macosx" as OS X triples.
-    if bugnumber: return expectedFailureOS(['darwin', 'macosx'], bugnumber, compilers)
+    return expectedFailureOS(['darwin', 'macosx'], bugnumber, compilers)
 
 def expectedFailureFreeBSD(bugnumber=None, compilers=None):
-    if bugnumber: return expectedFailureOS(['freebsd'], bugnumber, compilers)
+    return expectedFailureOS(['freebsd'], bugnumber, compilers)
 
 def expectedFailureLinux(bugnumber=None, compilers=None):
-    if bugnumber: return expectedFailureOS(['linux'], bugnumber, compilers)
+    return expectedFailureOS(['linux'], bugnumber, compilers)
 
 def expectedFailureWindows(bugnumber=None, compilers=None):
-    if bugnumber: return expectedFailureOS(['windows'], bugnumber, compilers)
+    return expectedFailureOS(['windows'], bugnumber, compilers)
 
 def expectedFailureLLGS(bugnumber=None, compilers=None):
     def fn(self):
@@ -610,7 +611,7 @@
             return False
         self.runCmd('settings show platform.plugin.linux.use-llgs-for-local')
         return 'true' in self.res.GetOutput() and self.expectedCompiler(compilers)
-    if bugnumber: return expectedFailure(fn, bugnumber)
+    return expectedFailure(fn, bugnumber)
 
 def skipIfRemote(func):
     """Decorate the item to skip tests if testing remotely."""

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D8595.22769.patch
Type: text/x-patch
Size: 4146 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20150326/05f391e2/attachment.bin>


More information about the lldb-commits mailing list