2008-08-16 23:26:59 +08:00
|
|
|
"""
|
2010-01-02 06:05:00 +08:00
|
|
|
Python related collection nodes.
|
2008-08-16 23:26:59 +08:00
|
|
|
"""
|
|
|
|
import py
|
2009-09-01 22:10:21 +08:00
|
|
|
import inspect
|
2010-01-14 00:15:54 +08:00
|
|
|
from py._test.collect import configproperty, warnoldcollect
|
|
|
|
from py._test import funcargs
|
2010-02-04 23:01:02 +08:00
|
|
|
from py._code.code import TerminalRepr
|
2008-08-16 23:26:59 +08:00
|
|
|
|
|
|
|
class PyobjMixin(object):
|
|
|
|
def obj():
|
|
|
|
def fget(self):
|
|
|
|
try:
|
|
|
|
return self._obj
|
|
|
|
except AttributeError:
|
|
|
|
self._obj = obj = self._getobj()
|
|
|
|
return obj
|
|
|
|
def fset(self, value):
|
|
|
|
self._obj = value
|
|
|
|
return property(fget, fset, None, "underlying python object")
|
|
|
|
obj = obj()
|
|
|
|
|
|
|
|
def _getobj(self):
|
|
|
|
return getattr(self.parent.obj, self.name)
|
|
|
|
|
2009-02-27 18:18:27 +08:00
|
|
|
def getmodpath(self, stopatmodule=True, includemodule=False):
|
2008-08-16 23:26:59 +08:00
|
|
|
""" return python path relative to the containing module. """
|
|
|
|
chain = self.listchain()
|
|
|
|
chain.reverse()
|
|
|
|
parts = []
|
|
|
|
for node in chain:
|
|
|
|
if isinstance(node, Instance):
|
|
|
|
continue
|
2008-09-02 22:31:42 +08:00
|
|
|
name = node.name
|
|
|
|
if isinstance(node, Module):
|
|
|
|
assert name.endswith(".py")
|
|
|
|
name = name[:-3]
|
2009-02-27 18:18:27 +08:00
|
|
|
if stopatmodule:
|
|
|
|
if includemodule:
|
|
|
|
parts.append(name)
|
|
|
|
break
|
2008-09-02 22:31:42 +08:00
|
|
|
parts.append(name)
|
2008-08-16 23:26:59 +08:00
|
|
|
parts.reverse()
|
|
|
|
s = ".".join(parts)
|
|
|
|
return s.replace(".[", "[")
|
|
|
|
|
2009-05-12 19:39:09 +08:00
|
|
|
def _getfslineno(self):
|
2008-08-16 23:26:59 +08:00
|
|
|
try:
|
|
|
|
return self._fslineno
|
|
|
|
except AttributeError:
|
|
|
|
pass
|
2008-11-26 03:15:01 +08:00
|
|
|
obj = self.obj
|
2009-05-12 19:39:09 +08:00
|
|
|
# xxx let decorators etc specify a sane ordering
|
2008-11-26 03:15:01 +08:00
|
|
|
if hasattr(obj, 'place_as'):
|
|
|
|
obj = obj.place_as
|
2008-08-16 23:26:59 +08:00
|
|
|
|
2009-05-12 19:39:09 +08:00
|
|
|
self._fslineno = py.code.getfslineno(obj)
|
|
|
|
return self._fslineno
|
2008-08-16 23:26:59 +08:00
|
|
|
|
2009-05-12 23:02:22 +08:00
|
|
|
def reportinfo(self):
|
2009-05-12 19:39:09 +08:00
|
|
|
fspath, lineno = self._getfslineno()
|
2008-08-16 23:26:59 +08:00
|
|
|
modpath = self.getmodpath()
|
2009-05-06 05:52:25 +08:00
|
|
|
return fspath, lineno, modpath
|
2008-08-16 23:26:59 +08:00
|
|
|
|
2008-09-02 20:24:15 +08:00
|
|
|
class PyCollectorMixin(PyobjMixin, py.test.collect.Collector):
|
2008-08-16 23:26:59 +08:00
|
|
|
Class = configproperty('Class')
|
|
|
|
Instance = configproperty('Instance')
|
|
|
|
Function = configproperty('Function')
|
|
|
|
Generator = configproperty('Generator')
|
|
|
|
|
|
|
|
def funcnamefilter(self, name):
|
|
|
|
return name.startswith('test')
|
|
|
|
def classnamefilter(self, name):
|
|
|
|
return name.startswith('Test')
|
|
|
|
|
2008-09-02 16:58:14 +08:00
|
|
|
def collect(self):
|
|
|
|
l = self._deprecated_collect()
|
|
|
|
if l is not None:
|
|
|
|
return l
|
2008-08-16 23:26:59 +08:00
|
|
|
# NB. we avoid random getattrs and peek in the __dict__ instead
|
|
|
|
dicts = [getattr(self.obj, '__dict__', {})]
|
2009-09-01 22:10:21 +08:00
|
|
|
for basecls in inspect.getmro(self.obj.__class__):
|
2008-08-16 23:26:59 +08:00
|
|
|
dicts.append(basecls.__dict__)
|
|
|
|
seen = {}
|
2010-01-16 00:38:09 +08:00
|
|
|
l = []
|
2008-08-16 23:26:59 +08:00
|
|
|
for dic in dicts:
|
|
|
|
for name, obj in dic.items():
|
|
|
|
if name in seen:
|
|
|
|
continue
|
|
|
|
seen[name] = True
|
2009-10-22 00:44:12 +08:00
|
|
|
if name[0] != "_":
|
|
|
|
res = self.makeitem(name, obj)
|
2010-01-16 00:50:02 +08:00
|
|
|
if res is None:
|
|
|
|
continue
|
|
|
|
if not isinstance(res, list):
|
|
|
|
res = [res]
|
|
|
|
l.extend(res)
|
2010-01-16 00:38:09 +08:00
|
|
|
l.sort(key=lambda item: item.reportinfo()[:2])
|
|
|
|
return l
|
2008-08-16 23:26:59 +08:00
|
|
|
|
2008-09-02 16:58:14 +08:00
|
|
|
def _deprecated_join(self, name):
|
|
|
|
if self.__class__.join != py.test.collect.Collector.join:
|
|
|
|
warnoldcollect()
|
|
|
|
return self.join(name)
|
|
|
|
|
2009-02-27 18:18:27 +08:00
|
|
|
def makeitem(self, name, obj):
|
2009-12-30 09:36:58 +08:00
|
|
|
return self.ihook.pytest_pycollect_makeitem(
|
2009-05-08 05:12:17 +08:00
|
|
|
collector=self, name=name, obj=obj)
|
2009-05-12 01:23:57 +08:00
|
|
|
|
2009-08-07 00:15:21 +08:00
|
|
|
def _istestclasscandidate(self, name, obj):
|
|
|
|
if self.classnamefilter(name) and \
|
2009-09-01 22:10:21 +08:00
|
|
|
inspect.isclass(obj):
|
2009-08-07 00:15:21 +08:00
|
|
|
if hasinit(obj):
|
|
|
|
# XXX WARN
|
|
|
|
return False
|
|
|
|
return True
|
|
|
|
|
2009-05-12 01:23:57 +08:00
|
|
|
def _genfunctions(self, name, funcobj):
|
2009-05-20 00:13:33 +08:00
|
|
|
module = self.getparent(Module).obj
|
|
|
|
clscol = self.getparent(Class)
|
2009-05-12 01:23:57 +08:00
|
|
|
cls = clscol and clscol.obj or None
|
2009-08-07 00:15:21 +08:00
|
|
|
metafunc = funcargs.Metafunc(funcobj, config=self.config,
|
|
|
|
cls=cls, module=module)
|
2009-12-30 09:36:58 +08:00
|
|
|
gentesthook = self.config.hook.pytest_generate_tests
|
2009-12-30 21:05:41 +08:00
|
|
|
plugins = funcargs.getplugins(self, withpy=True)
|
|
|
|
gentesthook.pcall(plugins, metafunc=metafunc)
|
2009-05-13 05:32:19 +08:00
|
|
|
if not metafunc._calls:
|
2009-05-12 01:23:57 +08:00
|
|
|
return self.Function(name, parent=self)
|
2010-01-16 00:50:02 +08:00
|
|
|
l = []
|
|
|
|
for callspec in metafunc._calls:
|
|
|
|
subname = "%s[%s]" %(name, callspec.id)
|
|
|
|
function = self.Function(name=subname, parent=self,
|
|
|
|
callspec=callspec, callobj=funcobj)
|
|
|
|
l.append(function)
|
|
|
|
return l
|
2009-05-12 01:23:57 +08:00
|
|
|
|
2008-09-02 20:24:15 +08:00
|
|
|
class Module(py.test.collect.File, PyCollectorMixin):
|
2008-08-16 23:26:59 +08:00
|
|
|
def _getobj(self):
|
2009-02-27 18:18:27 +08:00
|
|
|
return self._memoizedcall('_obj', self._importtestmodule)
|
|
|
|
|
|
|
|
def _importtestmodule(self):
|
|
|
|
# we assume we are only called once per module
|
|
|
|
mod = self.fspath.pyimport()
|
|
|
|
#print "imported test module", mod
|
2009-04-09 22:03:09 +08:00
|
|
|
self.config.pluginmanager.consider_module(mod)
|
2009-02-27 18:18:27 +08:00
|
|
|
return mod
|
2008-08-16 23:26:59 +08:00
|
|
|
|
|
|
|
def setup(self):
|
2009-03-19 01:54:45 +08:00
|
|
|
if getattr(self.obj, 'disabled', 0):
|
2009-12-30 19:13:38 +08:00
|
|
|
py.log._apiwarn(">1.1.1", "%r uses 'disabled' which is deprecated, "
|
|
|
|
"use pytestmark=..., see pytest_skipping plugin" % (self.obj,))
|
2009-03-19 01:54:45 +08:00
|
|
|
py.test.skip("%r is disabled" %(self.obj,))
|
2009-10-23 22:17:06 +08:00
|
|
|
if hasattr(self.obj, 'setup_module'):
|
|
|
|
#XXX: nose compat hack, move to nose plugin
|
|
|
|
# if it takes a positional arg, its probably a py.test style one
|
|
|
|
# so we pass the current module object
|
|
|
|
if inspect.getargspec(self.obj.setup_module)[0]:
|
|
|
|
self.obj.setup_module(self.obj)
|
|
|
|
else:
|
|
|
|
self.obj.setup_module()
|
2008-08-16 23:26:59 +08:00
|
|
|
|
|
|
|
def teardown(self):
|
|
|
|
if hasattr(self.obj, 'teardown_module'):
|
2009-10-23 22:17:06 +08:00
|
|
|
#XXX: nose compat hack, move to nose plugin
|
|
|
|
# if it takes a positional arg, its probably a py.test style one
|
|
|
|
# so we pass the current module object
|
|
|
|
if inspect.getargspec(self.obj.teardown_module)[0]:
|
|
|
|
self.obj.teardown_module(self.obj)
|
|
|
|
else:
|
|
|
|
self.obj.teardown_module()
|
2008-08-16 23:26:59 +08:00
|
|
|
|
2008-09-02 20:24:15 +08:00
|
|
|
class Class(PyCollectorMixin, py.test.collect.Collector):
|
2008-08-16 23:26:59 +08:00
|
|
|
|
2008-09-02 16:58:14 +08:00
|
|
|
def collect(self):
|
|
|
|
l = self._deprecated_collect()
|
|
|
|
if l is not None:
|
|
|
|
return l
|
|
|
|
return [self.Instance(name="()", parent=self)]
|
2008-08-16 23:26:59 +08:00
|
|
|
|
|
|
|
def setup(self):
|
2009-03-19 01:54:45 +08:00
|
|
|
if getattr(self.obj, 'disabled', 0):
|
2009-12-30 19:13:38 +08:00
|
|
|
py.log._apiwarn(">1.1.1", "%r uses 'disabled' which is deprecated, "
|
|
|
|
"use pytestmark=..., see pytest_skipping plugin" % (self.obj,))
|
2009-03-19 01:54:45 +08:00
|
|
|
py.test.skip("%r is disabled" %(self.obj,))
|
2008-08-16 23:26:59 +08:00
|
|
|
setup_class = getattr(self.obj, 'setup_class', None)
|
|
|
|
if setup_class is not None:
|
|
|
|
setup_class = getattr(setup_class, 'im_func', setup_class)
|
|
|
|
setup_class(self.obj)
|
|
|
|
|
|
|
|
def teardown(self):
|
|
|
|
teardown_class = getattr(self.obj, 'teardown_class', None)
|
|
|
|
if teardown_class is not None:
|
|
|
|
teardown_class = getattr(teardown_class, 'im_func', teardown_class)
|
|
|
|
teardown_class(self.obj)
|
|
|
|
|
2008-09-02 20:24:15 +08:00
|
|
|
class Instance(PyCollectorMixin, py.test.collect.Collector):
|
2008-08-16 23:26:59 +08:00
|
|
|
def _getobj(self):
|
|
|
|
return self.parent.obj()
|
|
|
|
def Function(self):
|
|
|
|
return getattr(self.obj, 'Function',
|
|
|
|
PyCollectorMixin.Function.__get__(self)) # XXX for python 2.2
|
|
|
|
def _keywords(self):
|
|
|
|
return []
|
|
|
|
Function = property(Function)
|
|
|
|
|
2008-09-02 16:58:14 +08:00
|
|
|
#def __repr__(self):
|
|
|
|
# return "<%s of '%s'>" %(self.__class__.__name__,
|
|
|
|
# self.parent.obj.__name__)
|
|
|
|
|
2008-08-16 23:26:59 +08:00
|
|
|
def newinstance(self):
|
|
|
|
self.obj = self._getobj()
|
|
|
|
return self.obj
|
|
|
|
|
|
|
|
class FunctionMixin(PyobjMixin):
|
|
|
|
""" mixin for the code common to Function and Generator.
|
|
|
|
"""
|
2009-05-06 05:52:25 +08:00
|
|
|
|
2008-08-16 23:26:59 +08:00
|
|
|
def setup(self):
|
|
|
|
""" perform setup for this test function. """
|
2009-09-01 22:10:21 +08:00
|
|
|
if inspect.ismethod(self.obj):
|
2008-08-16 23:26:59 +08:00
|
|
|
name = 'setup_method'
|
|
|
|
else:
|
|
|
|
name = 'setup_function'
|
|
|
|
if isinstance(self.parent, Instance):
|
|
|
|
obj = self.parent.newinstance()
|
|
|
|
self.obj = self._getobj()
|
|
|
|
else:
|
|
|
|
obj = self.parent.obj
|
|
|
|
setup_func_or_method = getattr(obj, name, None)
|
|
|
|
if setup_func_or_method is not None:
|
2009-05-06 14:38:42 +08:00
|
|
|
setup_func_or_method(self.obj)
|
2008-08-16 23:26:59 +08:00
|
|
|
|
|
|
|
def teardown(self):
|
|
|
|
""" perform teardown for this test function. """
|
2009-09-01 22:10:21 +08:00
|
|
|
if inspect.ismethod(self.obj):
|
2008-08-16 23:26:59 +08:00
|
|
|
name = 'teardown_method'
|
|
|
|
else:
|
|
|
|
name = 'teardown_function'
|
|
|
|
obj = self.parent.obj
|
|
|
|
teardown_func_or_meth = getattr(obj, name, None)
|
|
|
|
if teardown_func_or_meth is not None:
|
|
|
|
teardown_func_or_meth(self.obj)
|
|
|
|
|
|
|
|
def _prunetraceback(self, traceback):
|
2009-03-19 03:23:38 +08:00
|
|
|
if hasattr(self, '_obj') and not self.config.option.fulltrace:
|
2008-08-16 23:26:59 +08:00
|
|
|
code = py.code.Code(self.obj)
|
|
|
|
path, firstlineno = code.path, code.firstlineno
|
|
|
|
ntraceback = traceback.cut(path=path, firstlineno=firstlineno)
|
|
|
|
if ntraceback == traceback:
|
|
|
|
ntraceback = ntraceback.cut(path=path)
|
2009-03-01 19:24:52 +08:00
|
|
|
if ntraceback == traceback:
|
2010-01-11 21:30:50 +08:00
|
|
|
ntraceback = ntraceback.cut(excludepath=py._pydir)
|
2008-08-16 23:26:59 +08:00
|
|
|
traceback = ntraceback.filter()
|
|
|
|
return traceback
|
|
|
|
|
2010-02-04 23:01:02 +08:00
|
|
|
def _repr_failure_py(self, excinfo):
|
|
|
|
if excinfo.errisinstance(funcargs.FuncargRequest.LookupError):
|
|
|
|
fspath, lineno, msg = self.reportinfo()
|
|
|
|
lines, _ = inspect.getsourcelines(self.obj)
|
|
|
|
for i, line in enumerate(lines):
|
|
|
|
if line.strip().startswith('def'):
|
|
|
|
return FuncargLookupErrorRepr(fspath, lineno,
|
|
|
|
lines[:i+1], str(excinfo.value))
|
|
|
|
return super(FunctionMixin, self)._repr_failure_py(excinfo)
|
|
|
|
|
2009-07-26 00:09:01 +08:00
|
|
|
def repr_failure(self, excinfo, outerr=None):
|
|
|
|
assert outerr is None, "XXX outerr usage is deprecated"
|
|
|
|
return self._repr_failure_py(excinfo)
|
2008-08-16 23:26:59 +08:00
|
|
|
|
|
|
|
shortfailurerepr = "F"
|
|
|
|
|
2010-02-04 23:01:02 +08:00
|
|
|
class FuncargLookupErrorRepr(TerminalRepr):
|
|
|
|
def __init__(self, filename, firstlineno, deflines, errorstring):
|
|
|
|
self.deflines = deflines
|
|
|
|
self.errorstring = errorstring
|
|
|
|
self.filename = filename
|
|
|
|
self.firstlineno = firstlineno
|
|
|
|
|
|
|
|
def toterminal(self, tw):
|
|
|
|
tw.line()
|
|
|
|
for line in self.deflines:
|
|
|
|
tw.line(" " + line.strip())
|
|
|
|
for line in self.errorstring.split("\n"):
|
|
|
|
tw.line(" " + line.strip(), red=True)
|
|
|
|
tw.line()
|
|
|
|
tw.line("%s:%d" % (self.filename, self.firstlineno+1))
|
|
|
|
|
2008-09-02 20:24:15 +08:00
|
|
|
class Generator(FunctionMixin, PyCollectorMixin, py.test.collect.Collector):
|
2008-09-02 16:58:14 +08:00
|
|
|
def collect(self):
|
2009-05-07 21:44:56 +08:00
|
|
|
# test generators are seen as collectors but they also
|
|
|
|
# invoke setup/teardown on popular request
|
|
|
|
# (induced by the common "test_*" naming shared with normal tests)
|
2009-03-18 07:48:07 +08:00
|
|
|
self.config._setupstate.prepare(self)
|
2008-09-02 16:58:14 +08:00
|
|
|
l = []
|
2009-03-19 22:34:33 +08:00
|
|
|
seen = {}
|
2009-08-28 22:25:29 +08:00
|
|
|
for i, x in enumerate(self.obj()):
|
2008-11-26 00:10:16 +08:00
|
|
|
name, call, args = self.getcallargs(x)
|
2009-08-30 05:00:24 +08:00
|
|
|
if not py.builtin.callable(call):
|
2008-08-16 23:26:59 +08:00
|
|
|
raise TypeError("%r yielded non callable test %r" %(self.obj, call,))
|
2008-11-26 00:10:16 +08:00
|
|
|
if name is None:
|
|
|
|
name = "[%d]" % i
|
|
|
|
else:
|
|
|
|
name = "['%s']" % name
|
2009-03-19 22:34:33 +08:00
|
|
|
if name in seen:
|
|
|
|
raise ValueError("%r generated tests with non-unique name %r" %(self, name))
|
|
|
|
seen[name] = True
|
2008-09-02 16:58:14 +08:00
|
|
|
l.append(self.Function(name, self, args=args, callobj=call))
|
|
|
|
return l
|
2008-08-16 23:26:59 +08:00
|
|
|
|
|
|
|
def getcallargs(self, obj):
|
2008-11-26 00:10:16 +08:00
|
|
|
if not isinstance(obj, (tuple, list)):
|
|
|
|
obj = (obj,)
|
|
|
|
# explict naming
|
2009-08-29 22:40:03 +08:00
|
|
|
if isinstance(obj[0], py.builtin._basestring):
|
2008-11-26 00:10:16 +08:00
|
|
|
name = obj[0]
|
|
|
|
obj = obj[1:]
|
2008-08-16 23:26:59 +08:00
|
|
|
else:
|
2008-11-26 00:10:16 +08:00
|
|
|
name = None
|
|
|
|
call, args = obj[0], obj[1:]
|
|
|
|
return name, call, args
|
2009-05-06 05:52:25 +08:00
|
|
|
|
2008-08-16 23:26:59 +08:00
|
|
|
|
|
|
|
#
|
|
|
|
# Test Items
|
|
|
|
#
|
|
|
|
_dummy = object()
|
2008-09-02 20:24:15 +08:00
|
|
|
class Function(FunctionMixin, py.test.collect.Item):
|
2008-08-16 23:26:59 +08:00
|
|
|
""" a Function Item is responsible for setting up
|
|
|
|
and executing a Python callable test object.
|
|
|
|
"""
|
2009-05-25 16:46:04 +08:00
|
|
|
_genid = None
|
2009-12-30 23:18:59 +08:00
|
|
|
def __init__(self, name, parent=None, args=None, config=None,
|
2009-05-13 09:01:02 +08:00
|
|
|
callspec=None, callobj=_dummy):
|
2009-12-30 23:18:59 +08:00
|
|
|
super(Function, self).__init__(name, parent, config=config)
|
2009-05-13 05:32:19 +08:00
|
|
|
self._args = args
|
2009-06-15 21:15:40 +08:00
|
|
|
if self._isyieldedfunction():
|
2009-05-13 09:01:02 +08:00
|
|
|
assert not callspec, "yielded functions (deprecated) cannot have funcargs"
|
|
|
|
else:
|
2009-05-25 16:46:04 +08:00
|
|
|
if callspec is not None:
|
|
|
|
self.funcargs = callspec.funcargs or {}
|
|
|
|
self._genid = callspec.id
|
|
|
|
if hasattr(callspec, "param"):
|
|
|
|
self._requestparam = callspec.param
|
|
|
|
else:
|
|
|
|
self.funcargs = {}
|
2008-08-16 23:26:59 +08:00
|
|
|
if callobj is not _dummy:
|
|
|
|
self._obj = callobj
|
2009-12-30 17:42:01 +08:00
|
|
|
self.function = getattr(self.obj, 'im_func', self.obj)
|
2008-08-16 23:26:59 +08:00
|
|
|
|
2010-01-16 00:50:02 +08:00
|
|
|
def _getobj(self):
|
|
|
|
name = self.name
|
|
|
|
i = name.find("[") # parametrization
|
|
|
|
if i != -1:
|
|
|
|
name = name[:i]
|
|
|
|
return getattr(self.parent.obj, name)
|
|
|
|
|
2009-06-15 21:15:40 +08:00
|
|
|
def _isyieldedfunction(self):
|
|
|
|
return self._args is not None
|
|
|
|
|
2009-02-27 18:18:27 +08:00
|
|
|
def readkeywords(self):
|
|
|
|
d = super(Function, self).readkeywords()
|
2009-09-04 22:32:49 +08:00
|
|
|
d.update(py.builtin._getfuncdict(self.obj))
|
2009-02-27 18:18:27 +08:00
|
|
|
return d
|
|
|
|
|
2008-09-02 16:58:14 +08:00
|
|
|
def runtest(self):
|
2009-06-09 00:31:10 +08:00
|
|
|
""" execute the underlying test function. """
|
2009-12-30 09:36:58 +08:00
|
|
|
self.ihook.pytest_pyfunc_call(pyfuncitem=self)
|
2009-02-27 18:18:27 +08:00
|
|
|
|
2009-05-06 14:38:42 +08:00
|
|
|
def setup(self):
|
|
|
|
super(Function, self).setup()
|
2009-05-13 05:32:19 +08:00
|
|
|
if hasattr(self, 'funcargs'):
|
|
|
|
funcargs.fillfuncargs(self)
|
2008-08-16 23:26:59 +08:00
|
|
|
|
|
|
|
def __eq__(self, other):
|
|
|
|
try:
|
|
|
|
return (self.name == other.name and
|
|
|
|
self._args == other._args and
|
|
|
|
self.parent == other.parent and
|
2009-05-19 01:06:16 +08:00
|
|
|
self.obj == other.obj and
|
2009-05-25 16:46:04 +08:00
|
|
|
getattr(self, '_genid', None) ==
|
|
|
|
getattr(other, '_genid', None)
|
2009-05-19 01:06:16 +08:00
|
|
|
)
|
2008-08-16 23:26:59 +08:00
|
|
|
except AttributeError:
|
|
|
|
pass
|
|
|
|
return False
|
2009-05-12 01:23:57 +08:00
|
|
|
|
2008-08-16 23:26:59 +08:00
|
|
|
def __ne__(self, other):
|
|
|
|
return not self == other
|
2009-08-29 01:16:15 +08:00
|
|
|
|
|
|
|
def __hash__(self):
|
|
|
|
return hash((self.parent, self.name))
|
2009-08-07 00:15:21 +08:00
|
|
|
|
|
|
|
def hasinit(obj):
|
|
|
|
init = getattr(obj, '__init__', None)
|
|
|
|
if init:
|
|
|
|
if not isinstance(init, type(object.__init__)):
|
|
|
|
return True
|