403Webshell
Server IP : 162.253.224.18  /  Your IP : 216.73.217.120
Web Server : Apache
System : Linux s18.infinitysrv.com 3.10.0-962.3.2.lve1.5.89.el7.x86_64 #1 SMP Thu Jul 9 15:55:31 UTC 2026 x86_64
User : dejavumk ( 1184)
PHP Version : 7.4.33
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : OFF  |  Pkexec : OFF
Directory :  /opt/alt/python35/lib64/python3.5/site-packages/sklearn/utils/tests/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /opt/alt/python35/lib64/python3.5/site-packages/sklearn/utils/tests/test_metaestimators.py
from sklearn.utils.testing import assert_true, assert_false
from sklearn.utils.metaestimators import if_delegate_has_method


class Prefix(object):
    def func(self):
        pass


class MockMetaEstimator(object):
    """This is a mock meta estimator"""
    a_prefix = Prefix()

    @if_delegate_has_method(delegate="a_prefix")
    def func(self):
        """This is a mock delegated function"""
        pass


def test_delegated_docstring():
    assert_true("This is a mock delegated function"
                in str(MockMetaEstimator.__dict__['func'].__doc__))
    assert_true("This is a mock delegated function"
                in str(MockMetaEstimator.func.__doc__))
    assert_true("This is a mock delegated function"
                in str(MockMetaEstimator().func.__doc__))


class MetaEst(object):
    """A mock meta estimator"""
    def __init__(self, sub_est, better_sub_est=None):
        self.sub_est = sub_est
        self.better_sub_est = better_sub_est

    @if_delegate_has_method(delegate='sub_est')
    def predict(self):
        pass


class MetaEstTestTuple(MetaEst):
    """A mock meta estimator to test passing a tuple of delegates"""

    @if_delegate_has_method(delegate=('sub_est', 'better_sub_est'))
    def predict(self):
        pass


class MetaEstTestList(MetaEst):
    """A mock meta estimator to test passing a list of delegates"""

    @if_delegate_has_method(delegate=['sub_est', 'better_sub_est'])
    def predict(self):
        pass


class HasPredict(object):
    """A mock sub-estimator with predict method"""

    def predict(self):
        pass


class HasNoPredict(object):
    """A mock sub-estimator with no predict method"""
    pass


def test_if_delegate_has_method():
    assert_true(hasattr(MetaEst(HasPredict()), 'predict'))
    assert_false(hasattr(MetaEst(HasNoPredict()), 'predict'))
    assert_false(
        hasattr(MetaEstTestTuple(HasNoPredict(), HasNoPredict()), 'predict'))
    assert_true(
        hasattr(MetaEstTestTuple(HasPredict(), HasNoPredict()), 'predict'))
    assert_false(
        hasattr(MetaEstTestTuple(HasNoPredict(), HasPredict()), 'predict'))
    assert_false(
        hasattr(MetaEstTestList(HasNoPredict(), HasPredict()), 'predict'))
    assert_true(
        hasattr(MetaEstTestList(HasPredict(), HasPredict()), 'predict'))

Youez - 2016 - github.com/yon3zu
LinuXploit