コード例 #1
0
ファイル: testcase.py プロジェクト: Xion/taipan
    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_)
コード例 #2
0
    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_)
コード例 #3
0
ファイル: test_algorithms.py プロジェクト: Xion/taipan
    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
コード例 #4
0
    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
コード例 #5
0
 def test_dict__normal(self):
     itervalues = __unit__.itervalues(self.DICT)
     self._assertNonSequenceItems(self.VALUES, itervalues)
コード例 #6
0
 def test_dict__empty(self):
     self._assertEmptyNonSequence(__unit__.itervalues({}))
コード例 #7
0
 def test_some_object(self):
     with self.assertRaises(TypeError):
         __unit__.itervalues(object())
コード例 #8
0
 def test_none(self):
     with self.assertRaises(TypeError):
         __unit__.itervalues(None)
コード例 #9
0
ファイル: test_dicts.py プロジェクト: Xion/taipan
 def test_dict__normal(self):
     itervalues = __unit__.itervalues(self.DICT)
     self._assertNonSequenceItems(self.VALUES, itervalues)
コード例 #10
0
ファイル: test_dicts.py プロジェクト: Xion/taipan
 def test_dict__empty(self):
     self._assertEmptyNonSequence(__unit__.itervalues({}))
コード例 #11
0
ファイル: test_dicts.py プロジェクト: Xion/taipan
 def test_some_object(self):
     with self.assertRaises(TypeError):
         __unit__.itervalues(object())
コード例 #12
0
ファイル: test_dicts.py プロジェクト: Xion/taipan
 def test_none(self):
     with self.assertRaises(TypeError):
         __unit__.itervalues(None)