https://t.me/RX1948
Server : Apache/2.4.18 (Ubuntu)
System : Linux canvaswebdesign 3.13.0-71-generic #114-Ubuntu SMP Tue Dec 1 02:34:22 UTC 2015 x86_64
User : oppastar ( 1041)
PHP Version : 7.0.33-0ubuntu0.16.04.15
Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,
Directory :  /usr/lib/python3/dist-packages/zope/hookable/tests/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //usr/lib/python3/dist-packages/zope/hookable/tests/test_hookable.py
##############################################################################
#
# Copyright (c) 2003 Zope Foundation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Test the hookable support Extension
"""
import unittest

class PyHookableTests(unittest.TestCase):

    def _callFUT(self, *args, **kw):
        from zope.hookable import _py_hookable
        return _py_hookable(*args, **kw)

    def test_before_hook(self):
        def _foo():
            return 'FOO'
        hooked = self._callFUT(_foo)
        self.assertTrue(hooked.original is _foo)
        self.assertTrue(hooked.implementation is _foo)
        self.assertEqual(hooked(), 'FOO')

    def test_after_hook(self):
        def _foo():
            return 'FOO'
        def _bar():
            return 'BAR'
        hooked = self._callFUT(_foo)
        old = hooked.sethook(_bar)
        self.assertTrue(old is _foo)
        self.assertTrue(hooked.original is _foo)
        self.assertTrue(hooked.implementation is _bar)
        self.assertEqual(hooked(), 'BAR')

    def test_after_hook_and_reset(self):
        def _foo():
            return 'FOO'
        def _bar():
            return 'BAR'
        hooked = self._callFUT(_foo)
        old = hooked.sethook(_bar)
        hooked.reset()
        self.assertTrue(old is _foo)
        self.assertTrue(hooked.original is _foo)
        self.assertTrue(hooked.implementation is _foo)
        self.assertEqual(hooked(), 'FOO')

    def test_original_cannot_be_deleted(self):
        def _foo():
            return 'FOO'
        hooked = self._callFUT(_foo)
        def _try():
            del hooked.original
        self.assertRaises((TypeError, AttributeError), _try)

    def test_implementation_cannot_be_deleted(self):
        def _foo():
            return 'FOO'
        hooked = self._callFUT(_foo)
        def _try():
            del hooked.implementation
        self.assertRaises((TypeError, AttributeError), _try)

    def test_no_args(self):
        self.assertRaises(TypeError, self._callFUT)

    def test_too_many_args(self):
        def _foo():
            return 'FOO'
        self.assertRaises(TypeError, self._callFUT, _foo, _foo)

    def test_w_implementation_kwarg(self):
        def _foo():
            return 'FOO'
        hooked = self._callFUT(implementation=_foo)
        self.assertTrue(hooked.original is _foo)
        self.assertTrue(hooked.implementation is _foo)
        self.assertEqual(hooked(), 'FOO')

    def test_w_unknown_kwarg(self):
        def _foo():
            return 'FOO'
        self.assertRaises(TypeError, self._callFUT, nonesuch=_foo)


class HookableTests(PyHookableTests):

    def _callFUT(self, *args, **kw):
        from zope.hookable import hookable
        return hookable(*args, **kw)


def test_suite():
    return unittest.TestSuite((
        unittest.makeSuite(PyHookableTests),
        unittest.makeSuite(HookableTests),
    ))

https://t.me/RX1948 - 2025