# Path: catkin_tools/common.py
# class FakeLock(asyncio.locks.Lock):
#     def locked(self):
#     async def acquire(self):
#     def release(self):
# def getcwd(symlinks=True):
# def format_time_delta(delta):
# def format_time_delta_short(delta):
# def get_cached_recursive_build_depends_in_workspace(package, workspace_packages):
# def get_recursive_depends_in_workspace(
#         packages,
#         ordered_packages,
#         include_function,
#         exclude_function):
# def get_recursive_build_depends_in_workspace(package, ordered_packages):
# def get_recursive_run_depends_in_workspace(packages, ordered_packages):
# def get_recursive_build_dependents_in_workspace(package_name, ordered_packages):
# def get_recursive_run_dependents_in_workspace(package_name, ordered_packages):
# def is_tty(stream):
# def log(*args, **kwargs):
# def terminal_width():
# def remove_ansi_escape(string):
# def slice_to_printed_length(string, length):
# def printed_fill(string, length):
# def __wide_log(msg, **kwargs):
# def disable_wide_log():
#     def disabled_wide_log(msg, **kwargs):
# def wide_log(msg, **kwargs):
# def find_enclosing_package(search_start_path=None, ws_path=None, warnings=None, symlinks=True):
# def version_tuple(v):
# def mkdir_p(path):
# def format_env_dict(environ, human_readable=True):
# def parse_env_str(environ_str):
# def expand_glob_package(pattern, all_workspace_packages):


import mock
from catkin_tools import common


def test_get_recursive_build_depends_in_workspace_with_condition():
    pkg = MockPackage('pkg')
    cond_false_pkg = MockPackage('cond_false_pkg')
    cond_false_pkg.evaluated_condition = False
    cond_true_pkg = MockPackage('cond_true_pkg')
    pkg.build_depends = [cond_true_pkg, cond_false_pkg]

    ordered_packages = [
        ('/path/to/pkg', pkg),
        ('/path/to/cond_false_pkg', cond_false_pkg),
        ('/path/to/cond_true_pkg', cond_true_pkg),
    ]

    r = common.get_recursive_build_depends_in_workspace(pkg, ordered_packages)
    assert r == ordered_packages[2:], r


def test_get_recursive_build_depends_in_workspace_circular_run_depend():
    pkg1 = MockPackage('pkg1')
    pkg2 = MockPackage('pkg2')
    pkg1.run_depends.append(pkg2)
    pkg2.run_depends.append(pkg1)

    ordered_packages = [
        ('/path/to/pkg1', pkg1),
        ('/path/to/pkg2', pkg2),
    ]


# Path: catkin_tools/common.py
# class FakeLock(asyncio.locks.Lock):
#     def locked(self):
#     async def acquire(self):
#     def release(self):
# def getcwd(symlinks=True):
# def format_time_delta(delta):
# def format_time_delta_short(delta):
# def get_cached_recursive_build_depends_in_workspace(package, workspace_packages):
# def get_recursive_depends_in_workspace(
#         packages,
#         ordered_packages,
#         include_function,
#         exclude_function):
# def get_recursive_build_depends_in_workspace(package, ordered_packages):
# def get_recursive_run_depends_in_workspace(packages, ordered_packages):
# def get_recursive_build_dependents_in_workspace(package_name, ordered_packages):
# def get_recursive_run_dependents_in_workspace(package_name, ordered_packages):
# def is_tty(stream):
# def log(*args, **kwargs):
# def terminal_width():
# def remove_ansi_escape(string):
# def slice_to_printed_length(string, length):
# def printed_fill(string, length):
# def __wide_log(msg, **kwargs):
# def disable_wide_log():
#     def disabled_wide_log(msg, **kwargs):
# def wide_log(msg, **kwargs):
# def find_enclosing_package(search_start_path=None, ws_path=None, warnings=None, symlinks=True):
# def version_tuple(v):
# def mkdir_p(path):
# def format_env_dict(environ, human_readable=True):
# def parse_env_str(environ_str):
# def expand_glob_package(pattern, all_workspace_packages):


# Path: tests/unit/test_common.py
import mock
from catkin_tools import common



def test_get_recursive_build_depends_in_workspace_with_condition():
    pkg = MockPackage('pkg')
    cond_false_pkg = MockPackage('cond_false_pkg')
    cond_false_pkg.evaluated_condition = False
    cond_true_pkg = MockPackage('cond_true_pkg')
    pkg.build_depends = [cond_true_pkg, cond_false_pkg]

    ordered_packages = [
        ('/path/to/pkg', pkg),
        ('/path/to/cond_false_pkg', cond_false_pkg),
        ('/path/to/cond_true_pkg', cond_true_pkg),
    ]

    r = common.get_recursive_build_depends_in_workspace(pkg, ordered_packages)
    assert r == ordered_packages[2:], r


def test_get_recursive_build_depends_in_workspace_circular_run_depend():
    pkg1 = MockPackage('pkg1')
    pkg2 = MockPackage('pkg2')
    pkg1.run_depends.append(pkg2)
    pkg2.run_depends.append(pkg1)

    ordered_packages = [
        ('/path/to/pkg1', pkg1),
        ('/path/to/pkg2', pkg2),
    ]


    r = common.get_recursive_build_depends_in_workspace(pkg1, ordered_packages)