Diff looks like this: - @dwarf_test - @wraps(attrvalue) - def dwarf_test_method(self, attrvalue=attrvalue): - self.debug_info = "dwarf" - return attrvalue(self) - dwarf_method_name = attrname + "_dwarf" - dwarf_test_method.__name__ = dwarf_method_name - newattrs[dwarf_method_name] = dwarf_test_method
... + for category in supported_categories: + @add_test_categories([category]) + @wraps(attrvalue) + def test_method(self, attrvalue=attrvalue): + self.debug_info = category + return attrvalue(self) + method_name = attrname + "_" + category + test_method.__name__ = method_name + newattrs[method_name] = test_method So it looks like it's still under a different function. The difference is that before (in the - section of the diff) there were 3 different functions with 3 different names. For example `dwarf_test_method` above. In the new code (+ section of the diff) it looks like one function defined 3 different times with the same name `test_method`. But each of these should be a distinct function object that is defined in the context of the closure determined by the enclosing scope (the for loop in this case). So all 3 functions are actually different. self is just an argument to the function, not some magic value like `this` in C++, so as in the previous version, the `debug_info` that gets modified is on whatever instance of `self` gets passed into the function, same as before. Tamas or Pavel can probably clarify, but that's my understanding. On Mon, Dec 14, 2015 at 2:09 PM Siva Chandra <sivachan...@google.com> wrote: > Previously, self.debug_info was under different functions > (dwarf_test_method, dwo_test_method etc.). Now, they are all under > test_method. Even I am equally ignorant about the Python nuances here. > > On Mon, Dec 14, 2015 at 2:04 PM, Zachary Turner <ztur...@google.com> > wrote: > > The previous code was just an unrolled loop as far as I can tell. Do you > > mean the loop has different behavior than the unrolled loop? Because it > > looks identical to me (although admittedly python has a lot of nuances > that > > I don't understand in great detail) > > > > On Mon, Dec 14, 2015 at 1:59 PM Siva Chandra <sivachan...@google.com> > wrote: > >> > >> On Mon, Dec 14, 2015 at 10:49 AM, Zachary Turner via lldb-commits > >> <lldb-commits@lists.llvm.org> wrote: > >> > Modified: lldb/trunk/packages/Python/lldbsuite/test/lldbtest.py > >> > URL: > >> > > http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/lldbtest.py?rev=255525&r1=255524&r2=255525&view=diff > >> > > >> > > ============================================================================== > >> > --- lldb/trunk/packages/Python/lldbsuite/test/lldbtest.py (original) > >> > +++ lldb/trunk/packages/Python/lldbsuite/test/lldbtest.py Mon Dec 14 > >> > 12:49:16 2015 > >> > @@ -549,48 +549,6 @@ def no_debug_info_test(func): > >> > wrapper.__no_debug_info_test__ = True > >> > return wrapper > >> > > >> > -def dsym_test(func): > >> > - """Decorate the item as a dsym test.""" > >> > - if isinstance(func, type) and issubclass(func, > unittest2.TestCase): > >> > - raise Exception("@dsym_test can only be used to decorate a > test > >> > method") > >> > - @wraps(func) > >> > - def wrapper(self, *args, **kwargs): > >> > - if configuration.dont_do_dsym_test: > >> > - self.skipTest("dsym tests") > >> > - return func(self, *args, **kwargs) > >> > - > >> > - # Mark this function as such to separate them from the regular > >> > tests. > >> > - wrapper.__dsym_test__ = True > >> > - return wrapper > >> > - > >> > -def dwarf_test(func): > >> > - """Decorate the item as a dwarf test.""" > >> > - if isinstance(func, type) and issubclass(func, > unittest2.TestCase): > >> > - raise Exception("@dwarf_test can only be used to decorate a > >> > test method") > >> > - @wraps(func) > >> > - def wrapper(self, *args, **kwargs): > >> > - if configuration.dont_do_dwarf_test: > >> > - self.skipTest("dwarf tests") > >> > - return func(self, *args, **kwargs) > >> > - > >> > - # Mark this function as such to separate them from the regular > >> > tests. > >> > - wrapper.__dwarf_test__ = True > >> > - return wrapper > >> > - > >> > -def dwo_test(func): > >> > - """Decorate the item as a dwo test.""" > >> > - if isinstance(func, type) and issubclass(func, > unittest2.TestCase): > >> > - raise Exception("@dwo_test can only be used to decorate a > test > >> > method") > >> > - @wraps(func) > >> > - def wrapper(self, *args, **kwargs): > >> > - if configuration.dont_do_dwo_test: > >> > - self.skipTest("dwo tests") > >> > - return func(self, *args, **kwargs) > >> > - > >> > - # Mark this function as such to separate them from the regular > >> > tests. > >> > - wrapper.__dwo_test__ = True > >> > - return wrapper > >> > - > >> > def debugserver_test(func): > >> > """Decorate the item as a debugserver test.""" > >> > if isinstance(func, type) and issubclass(func, > unittest2.TestCase): > >> > @@ -2270,32 +2228,26 @@ class LLDBTestCaseFactory(type): > >> > newattrs = {} > >> > for attrname, attrvalue in attrs.items(): > >> > if attrname.startswith("test") and not getattr(attrvalue, > >> > "__no_debug_info_test__", False): > >> > - @dsym_test > >> > - @wraps(attrvalue) > >> > - def dsym_test_method(self, attrvalue=attrvalue): > >> > - self.debug_info = "dsym" > >> > - return attrvalue(self) > >> > - dsym_method_name = attrname + "_dsym" > >> > - dsym_test_method.__name__ = dsym_method_name > >> > - newattrs[dsym_method_name] = dsym_test_method > >> > - > >> > - @dwarf_test > >> > - @wraps(attrvalue) > >> > - def dwarf_test_method(self, attrvalue=attrvalue): > >> > - self.debug_info = "dwarf" > >> > - return attrvalue(self) > >> > - dwarf_method_name = attrname + "_dwarf" > >> > - dwarf_test_method.__name__ = dwarf_method_name > >> > - newattrs[dwarf_method_name] = dwarf_test_method > >> > - > >> > - @dwo_test > >> > - @wraps(attrvalue) > >> > - def dwo_test_method(self, attrvalue=attrvalue): > >> > - self.debug_info = "dwo" > >> > - return attrvalue(self) > >> > - dwo_method_name = attrname + "_dwo" > >> > - dwo_test_method.__name__ = dwo_method_name > >> > - newattrs[dwo_method_name] = dwo_test_method > >> > + target_platform = > >> > lldb.DBG.GetSelectedPlatform().GetTriple().split('-')[2] > >> > + > >> > + # If any debug info categories were explicitly > tagged, > >> > assume that list to be > >> > + # authoritative. If none were specified, try with > all > >> > debug info formats. > >> > + all_dbginfo_categories = > >> > set(test_categories.debug_info_categories) > >> > + categories = set(getattr(attrvalue, "categories", > [])) > >> > & all_dbginfo_categories > >> > + if not categories: > >> > + categories = all_dbginfo_categories > >> > + > >> > + supported_categories = [x for x in categories > >> > + if > >> > test_categories.is_supported_on_platform(x, target_platform)] > >> > + for category in supported_categories: > >> > + @add_test_categories([category]) > >> > + @wraps(attrvalue) > >> > + def test_method(self, attrvalue=attrvalue): > >> > + self.debug_info = category > >> > >> I believe test methods are added here to the same class. In which > >> case, self.debug_info is overwritten with each iteration of this for > >> loop. > >> > >> > + return attrvalue(self) > >> > + method_name = attrname + "_" + category > >> > + test_method.__name__ = method_name > >> > + newattrs[method_name] = test_method > >> > else: > >> > newattrs[attrname] = attrvalue > >> > return super(LLDBTestCaseFactory, cls).__new__(cls, name, > >> > bases, newattrs) >
_______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits