def __new__(meta, name, bases, dict_): """Create the new subclass of :class:`TestCase`.""" super_ = (bases[0] if bases else object).__mro__[0] # for every test stage, gather methods adorned with its decorator, # sort them by definition order and construct final stage method for stage in meta.CLASS_STAGES + meta.INSTANCE_STAGES: stage_method_wrappers = [ mw for mw in dicts.itervalues(dict_) if isinstance(mw, _StageMethod) and mw.stage == stage ] if not stage_method_wrappers: continue # no stage methods, may be custom setUp/tearDown/etc. # if setUp/tearDown/etc. method was defined AND corresponding # decorator used, then it's impossible to resolve proper runtime # order of those two approaches, so we report that as an error if stage in dict_: raise RuntimeError( "ambiguous test stage: either define {stage}() method or " "use @{stage} decorator".format(stage=stage)) stage_method_wrappers.sort(key=attr_func('order')) methods = [mw.method for mw in stage_method_wrappers] dict_[stage] = meta._create_stage_method(stage, methods, super_) return super(TestCaseMetaclass, meta).__new__(meta, name, bases, dict_)
def _resolve(self, items): """Turn textual references to items into actual objects. Must be called on any of the above test data before passing it to the tested :func:`topological_order` function. """ item_dict = dict((item.name, item) for item in items) result = [] for item in dicts.itervalues(item_dict): item.deps = list(map(item_dict.get, item.deps)) result.append(item) return result
def test_dict__normal(self): itervalues = __unit__.itervalues(self.DICT) self._assertNonSequenceItems(self.VALUES, itervalues)
def test_dict__empty(self): self._assertEmptyNonSequence(__unit__.itervalues({}))
def test_some_object(self): with self.assertRaises(TypeError): __unit__.itervalues(object())
def test_none(self): with self.assertRaises(TypeError): __unit__.itervalues(None)