# Path: lib/util/fs.py
# def get_common_ancestor(paths, default=None):
#     common_path = default
#     try:
#         # common_path = os.path.commonpath(paths)
#         common_path = _commonpath_polyfill(paths)
#     except ValueError as e:
#         logger.debug(
#             'invalid paths, cannot get common ancenstor: %s, %r',
#             paths, e,
#         )
# 
#     return common_path
# 
# Path: tests/lib/decorator.py
# def log_function(desc=None, logger=None,
#                  include_args=False, include_kwargs=False,
#                  include_return=False):
#     '''
#     Decorator for a function call.
#     Generates log messages when executing the underlying function. Attaches a
#     specialized filter to the logger to prepend the description to all log
#     messages while executing the function.
#     If `desc` is provided, it is used in the log message prefix. If omitted,
#     the function name will be used.
#     If `logger` is provided, a handler is attached to it during the execution
#     of the test function, and restored afterwards. Log statements will then
#     include a prefix of `desc` in the messages. If `logger` is omitted, the
#     root logger is used.
#     If `include_args` is true, then positional arguments are logged prior to
#     running the function.
#     If `include_kwargs` is true, then keyword-arguments are logged prior to
#     running the function.
#     If `include_return` is true, then the return value is logged after running
#     the function.
#     '''
# 
#     # pylint: disable=redefined-outer-name
#     if desc:
#         def get_desc(fn):
#             # pylint: disable=unused-argument
#             return desc
#     else:
#         def get_desc(fn):
#             if hasattr(fn, '__name__'):
#                 return getattr(fn, '__name__')
#             return '?'
# 
#     if logger is None:
#         logger = logging.getLogger('sublime-ycmd')
# 
#     def log_function_runner(fn):
#         ''' Base decorator. Decorates the underlying function. '''
# 
#         desc = get_desc(fn)
# 
#         @functools.wraps(fn)
#         def log_function_run(*args, **kwargs):
#             with LoggingContext(logger=logger, desc=desc):
#                 if include_args and include_kwargs:
#                     logger.debug('args, kwargs: %r, %r', args, kwargs)
#                 elif include_args:
#                     logger.debug('args: %r', args)
#                 elif include_kwargs:
#                     logger.debug('kwargs: %r', kwargs)
# 
#                 result = fn(*args, **kwargs)
# 
#                 if include_return:
#                     logger.debug('return: %r', result)
# 
#                 return result
# 
#         return log_function_run
# 
#     return log_function_runner
# 
# Path: tests/lib/subtest.py
# def map_test_function(test_instance, test_function, test_cases):
#     assert isinstance(test_instance, unittest.TestCase), \
#         'test instance must be a unittest.TestCase: %r' % (test_instance)
#     assert callable(test_function), \
#         'test function must be callable: %r' % (test_function)
#     assert hasattr(test_cases, '__iter__'), \
#         'test cases must be iterable: %r' % (test_cases)
# 
#     for test_index, test_case in enumerate(test_cases, start=1):
#         is_args_kwargs = _is_args_kwargs(test_case)
#         is_kwargs = isinstance(test_case, dict)
#         is_args = not (is_args_kwargs or is_kwargs)
# 
#         if is_args_kwargs:
#             test_args, test_kwargs = test_case
#         elif is_kwargs:
#             test_args = tuple()
#             test_kwargs = test_case
#         elif is_args:
#             test_args = test_case
#             test_kwargs = dict()
# 
#         log_args = is_args_kwargs or is_args
#         log_kwargs = is_args_kwargs or is_kwargs
# 
#         wrapped_test_function = log_function(
#             desc='[%d]' % (test_index),
#             include_args=log_args, include_kwargs=log_kwargs,
#         )(test_function)
# 
#         with test_instance.subTest(num=test_index,
#                                    args=test_args, kwargs=test_kwargs):
#             wrapped_test_function(*test_args, **test_kwargs)


import logging
import os
import unittest
from lib.util.fs import get_common_ancestor
from tests.lib.decorator import log_function
from tests.lib.subtest import map_test_function
            self, test_gca_single_one, single_path_args,
        )

    @log_function('[ancestor : similar]')
    def test_gca_mostly_similar(self):
        '''
        Ensures that the common path can be found for many paths, with a long
        common prefix component.
        '''
        mostly_similar_path_args = [
            ([
                FS_ROOT + 'usr/local/lib/mypackage/bin',
                FS_ROOT + 'usr/local/lib/mypackage/lib'
            ], {
                'expected': os.path.join(
                    FS_ROOT, 'usr', 'local', 'lib', 'mypackage',
                ),
            }),

            ([
                FS_ROOT + 'var/log/mypackage/auth.log',
                FS_ROOT + 'var/log/mypackage/client1/'
            ], {
                'expected': os.path.join(
                    FS_ROOT, 'var', 'log', 'mypackage',
                ),
            }),
        ]

        def test_gca_mostly_similar_one(*paths, expected=''):

# Path: lib/util/fs.py
# def get_common_ancestor(paths, default=None):
#     common_path = default
#     try:
#         # common_path = os.path.commonpath(paths)
#         common_path = _commonpath_polyfill(paths)
#     except ValueError as e:
#         logger.debug(
#             'invalid paths, cannot get common ancenstor: %s, %r',
#             paths, e,
#         )
# 
#     return common_path
# 
# Path: tests/lib/decorator.py
# def log_function(desc=None, logger=None,
#                  include_args=False, include_kwargs=False,
#                  include_return=False):
#     '''
#     Decorator for a function call.
#     Generates log messages when executing the underlying function. Attaches a
#     specialized filter to the logger to prepend the description to all log
#     messages while executing the function.
#     If `desc` is provided, it is used in the log message prefix. If omitted,
#     the function name will be used.
#     If `logger` is provided, a handler is attached to it during the execution
#     of the test function, and restored afterwards. Log statements will then
#     include a prefix of `desc` in the messages. If `logger` is omitted, the
#     root logger is used.
#     If `include_args` is true, then positional arguments are logged prior to
#     running the function.
#     If `include_kwargs` is true, then keyword-arguments are logged prior to
#     running the function.
#     If `include_return` is true, then the return value is logged after running
#     the function.
#     '''
# 
#     # pylint: disable=redefined-outer-name
#     if desc:
#         def get_desc(fn):
#             # pylint: disable=unused-argument
#             return desc
#     else:
#         def get_desc(fn):
#             if hasattr(fn, '__name__'):
#                 return getattr(fn, '__name__')
#             return '?'
# 
#     if logger is None:
#         logger = logging.getLogger('sublime-ycmd')
# 
#     def log_function_runner(fn):
#         ''' Base decorator. Decorates the underlying function. '''
# 
#         desc = get_desc(fn)
# 
#         @functools.wraps(fn)
#         def log_function_run(*args, **kwargs):
#             with LoggingContext(logger=logger, desc=desc):
#                 if include_args and include_kwargs:
#                     logger.debug('args, kwargs: %r, %r', args, kwargs)
#                 elif include_args:
#                     logger.debug('args: %r', args)
#                 elif include_kwargs:
#                     logger.debug('kwargs: %r', kwargs)
# 
#                 result = fn(*args, **kwargs)
# 
#                 if include_return:
#                     logger.debug('return: %r', result)
# 
#                 return result
# 
#         return log_function_run
# 
#     return log_function_runner
# 
# Path: tests/lib/subtest.py
# def map_test_function(test_instance, test_function, test_cases):
#     assert isinstance(test_instance, unittest.TestCase), \
#         'test instance must be a unittest.TestCase: %r' % (test_instance)
#     assert callable(test_function), \
#         'test function must be callable: %r' % (test_function)
#     assert hasattr(test_cases, '__iter__'), \
#         'test cases must be iterable: %r' % (test_cases)
# 
#     for test_index, test_case in enumerate(test_cases, start=1):
#         is_args_kwargs = _is_args_kwargs(test_case)
#         is_kwargs = isinstance(test_case, dict)
#         is_args = not (is_args_kwargs or is_kwargs)
# 
#         if is_args_kwargs:
#             test_args, test_kwargs = test_case
#         elif is_kwargs:
#             test_args = tuple()
#             test_kwargs = test_case
#         elif is_args:
#             test_args = test_case
#             test_kwargs = dict()
# 
#         log_args = is_args_kwargs or is_args
#         log_kwargs = is_args_kwargs or is_kwargs
# 
#         wrapped_test_function = log_function(
#             desc='[%d]' % (test_index),
#             include_args=log_args, include_kwargs=log_kwargs,
#         )(test_function)
# 
#         with test_instance.subTest(num=test_index,
#                                    args=test_args, kwargs=test_kwargs):
#             wrapped_test_function(*test_args, **test_kwargs)


# Path: tests/util/fs.py
import logging
import os
import unittest
from lib.util.fs import get_common_ancestor
from tests.lib.decorator import log_function
from tests.lib.subtest import map_test_function

            self, test_gca_single_one, single_path_args,
        )

    @log_function('[ancestor : similar]')
    def test_gca_mostly_similar(self):
        '''
        Ensures that the common path can be found for many paths, with a long
        common prefix component.
        '''
        mostly_similar_path_args = [
            ([
                FS_ROOT + 'usr/local/lib/mypackage/bin',
                FS_ROOT + 'usr/local/lib/mypackage/lib'
            ], {
                'expected': os.path.join(
                    FS_ROOT, 'usr', 'local', 'lib', 'mypackage',
                ),
            }),

            ([
                FS_ROOT + 'var/log/mypackage/auth.log',
                FS_ROOT + 'var/log/mypackage/client1/'
            ], {
                'expected': os.path.join(
                    FS_ROOT, 'var', 'log', 'mypackage',
                ),
            }),
        ]

        def test_gca_mostly_similar_one(*paths, expected=''):

            result = get_common_ancestor(paths)