Exemple #1
0
def test_new_instance_function(request):
    logger.info(f'{request._pyfuncitem.name}()')
    cls_name = 'pathlib.Path.cwd'
    kls = new_instance(cls_name)

    path = kls()
    logger.info(path.absolute())
Exemple #2
0
def test_new_instance_default_arg3(request, mocker):
    logger.info(f'{request._pyfuncitem.name}()')
    mock = mocker.spy(PlayerInitDefaultArg, '__init__')

    input = '.'.join([__name__, PlayerInitDefaultArg.__name__])
    player = new_instance(input, last_name='Google')
    assert player.first_name == "John"
Exemple #3
0
def test_new_instance_default_arg1(request, mocker):
    logger.info(f'{request._pyfuncitem.name}()')

    input = '.'.join([__name__, PlayerInitDefaultArg.__name__])
    first_name = 'John'
    player = new_instance(input, first_name)
    assert player.first_name == first_name
Exemple #4
0
def test_new_instance_sneaky(request, mocker):
    logger.info(f'{request._pyfuncitem.name}()')
    mock = mocker.spy(PlayerNewOnlyEmptySneaky, '__init__')

    input = '.'.join([__name__, PlayerNewOnlyEmptySneaky.__name__])
    player = new_instance(input)
    assert not hasattr(player.__init__,
                       'call_count') or player.__init__.call_count == 0
Exemple #5
0
def test_new_instance_abstract_method(request):
    logger.info(f'{request._pyfuncitem.name}()')
    input = '.'.join([__name__, PlayerAbstractWithAbstractMethod.__name__])

    with pytest.raises(TypeError, match='abstract method') as excinfo:
        player = new_instance(input)
    logger.debug(excinfo.value,
                 exc_info=(excinfo.type, excinfo.value, excinfo.tb))
Exemple #6
0
def test_new_instance_init_subclass(request):
    logger.info(f'{request._pyfuncitem.name}()')
    module_name, _ = __name__.rsplit(".", 1)
    input = '.'.join([
        module_name, 'method_overloading_test', 'PlayerAustralianPhilosopher'
    ])

    player = new_instance(input)
    assert player is not None
Exemple #7
0
def test_new_instance_arg(request, mocker):
    logger.info(f'{request._pyfuncitem.name}()')
    mock = mocker.spy(PlayerInitArg, '__init__')

    input = '.'.join([__name__, PlayerInitArg.__name__])
    first_name = 'John'
    player = new_instance(input, first_name)
    assert player.first_name == first_name
    assert player.__init__.call_count == 1
Exemple #8
0
def test_new_instance(request, plcls):
    logger.info(f'{request._pyfuncitem.name}()')

    input = '.'.join([__name__, plcls.__name__])
    player = new_instance(input)
    assert player is not None