def test_dynamic_capabilities_uses_original_function_if_not_enabled(
        stub_repo, stub_proto, stub_ui, stub_extensions, patched_capabilities):
    dynamic_capabilities = hgpatches._dynamic_capabilities_wrapper(
        hgcompat.largefiles.proto, stub_extensions)

    caps = dynamic_capabilities(stub_repo, stub_proto)

    stub_extensions.assert_called_once_with(stub_ui)
    assert LARGEFILES_CAPABILITY not in caps
def test_dynamic_capabilities_uses_largefiles_if_enabled(
        stub_repo, stub_proto, stub_ui, stub_extensions, patched_capabilities):
    stub_extensions.return_value = [('largefiles', mock.Mock())]

    dynamic_capabilities = hgpatches._dynamic_capabilities_wrapper(
        hgcompat.largefiles.proto, stub_extensions)

    caps = dynamic_capabilities(stub_repo, stub_proto)

    stub_extensions.assert_called_once_with(stub_ui)
    assert LARGEFILES_CAPABILITY in caps
def test_dynamic_capabilities_ignores_updated_capabilities(
        stub_repo, stub_proto, stub_ui, stub_extensions, patched_capabilities):
    stub_extensions.return_value = [('largefiles', mock.Mock())]
    dynamic_capabilities = hgpatches._dynamic_capabilities_wrapper(
        hgcompat.largefiles.proto, stub_extensions)

    # This happens when the extension is loaded for the first time, important
    # to ensure that an updated function is correctly picked up.
    hgcompat.largefiles.proto.capabilities = mock.Mock(
        side_effect=Exception('Must not be called'))

    dynamic_capabilities(stub_repo, stub_proto)
def test_dynamic_capabilities_uses_updated_capabilitiesorig(
        stub_repo, stub_proto, stub_ui, stub_extensions, patched_capabilities):
    dynamic_capabilities = hgpatches._dynamic_capabilities_wrapper(
        hgcompat.largefiles.proto, stub_extensions)

    # This happens when the extension is loaded for the first time, important
    # to ensure that an updated function is correctly picked up.
    hgcompat.largefiles.proto.capabilitiesorig = mock.Mock(
        return_value='REPLACED')

    caps = dynamic_capabilities(stub_repo, stub_proto)
    assert 'REPLACED' == caps