コード例 #1
0
ファイル: test_core.py プロジェクト: ProProgrammer/pytest
    def test_firstresult_definition(self):
        pm = PluginManager()
        class Api:
            def hello(self, arg):
                "api hook 1"
            hello.firstresult = True

        mcm = HookRelay(hookspecs=Api, pm=pm, prefix="he")
        class Plugin:
            def hello(self, arg):
                return arg + 1
        pm.register(Plugin())
        res = mcm.hello(arg=3)
        assert res == 4
コード例 #2
0
ファイル: test_core.py プロジェクト: ProProgrammer/pytest
    def test_happypath(self):
        pm = PluginManager()
        class Api:
            def hello(self, arg):
                "api hook 1"

        mcm = HookRelay(hookspecs=Api, pm=pm, prefix="he")
        assert hasattr(mcm, 'hello')
        assert repr(mcm.hello).find("hello") != -1
        class Plugin:
            def hello(self, arg):
                return arg + 1
        pm.register(Plugin())
        l = mcm.hello(arg=3)
        assert l == [4]
        assert not hasattr(mcm, 'world')
コード例 #3
0
ファイル: test_core.py プロジェクト: jeppeter/pytest
    def test_firstresult_definition(self):
        pm = PluginManager()

        class Api:
            def hello(self, arg):
                "api hook 1"

            hello.firstresult = True

        mcm = HookRelay(hookspecs=Api, pm=pm, prefix="he")

        class Plugin:
            def hello(self, arg):
                return arg + 1

        pm.register(Plugin())
        res = mcm.hello(arg=3)
        assert res == 4
コード例 #4
0
ファイル: test_core.py プロジェクト: jeppeter/pytest
    def test_only_kwargs(self):
        pm = PluginManager()

        class Api:
            def hello(self, arg):
                "api hook 1"

        mcm = HookRelay(hookspecs=Api, pm=pm, prefix="he")
        pytest.raises(TypeError, "mcm.hello(3)")
コード例 #5
0
ファイル: test_core.py プロジェクト: jeppeter/pytest
    def test_happypath(self):
        pm = PluginManager()

        class Api:
            def hello(self, arg):
                "api hook 1"

        mcm = HookRelay(hookspecs=Api, pm=pm, prefix="he")
        assert hasattr(mcm, 'hello')
        assert repr(mcm.hello).find("hello") != -1

        class Plugin:
            def hello(self, arg):
                return arg + 1

        pm.register(Plugin())
        l = mcm.hello(arg=3)
        assert l == [4]
        assert not hasattr(mcm, 'world')
コード例 #6
0
ファイル: pytester.py プロジェクト: chetan51/nupic-darwin64
 def start_recording(self, hookspecs):
     if not isinstance(hookspecs, (list, tuple)):
         hookspecs = [hookspecs]
     for hookspec in hookspecs:
         assert hookspec not in self._recorders
         class RecordCalls:
             _recorder = self
         for name, method in vars(hookspec).items():
             if name[0] != "_":
                 setattr(RecordCalls, name, self._makecallparser(method))
         recorder = RecordCalls()
         self._recorders[hookspec] = recorder
         self._pluginmanager.register(recorder)
     self.hook = HookRelay(hookspecs, pm=self._pluginmanager,
         prefix="pytest_")