# Path: shipwright/_lib/dependencies.py
# def eval(build_targets, targets):
# def _find(tree, name):
#     def find_(loc):
# def _make_tree(images):
#         def is_child(target):
# def _replace(node, children):
# def _children(item):
# def _is_branch(item):
# def _make_node(node, children):
# def _breadth_first_iter(loc):
# def _lineage(loc):
# def _split(f, children):
# def _brood(loc):
# def _upto(target, tree):
# def _dependents(target, tree):
# def _exact(target, tree):
# def _exclude(target, tree):
# 
# Path: shipwright/_lib/image.py
# def list_images(namespace, name_map, root_path):
# def image_name(namespace, name_map, root_path, path):
# def build_files(build_root):
# def name(docker_path):
# def sub_if(ex, repl, string, flags):
# def parse_copy(cmd):
# def copy_paths(docker_path):
#     def join(path):
#     def copy_paths_gen():
# def parent(docker_path):
# 
# Path: shipwright/_lib/source_control.py
# def source_control(path, namespace, name_map, mode=None):
#     if mode is None:
#         mode = AUTO
#     assert isinstance(mode, Mode)
#     the_mode = mode if mode is not AUTO else get_mode(path)
#     for cls in SourceControl.__subclasses__():
#         if cls.mode is the_mode:
#             return cls(path, namespace, name_map)


from shipwright._lib import dependencies, image, source_control


def test_breadth_first_iter():
    bt = default_build_targets()
    results = [result.name for result in dependencies.eval(bt, targets)]
    assert results == [
        'shipwright_test/1',
        'shipwright_test/independent',
        'shipwright_test/2',
        'shipwright_test/3',
    ]


def test_make_tree():
    root = dependencies._make_tree(targets)
    assert root.node().name is None

    assert _names(root) == [
        'shipwright_test/1',
        'shipwright_test/independent',
        'shipwright_test/2',
        'shipwright_test/3',
    ]

    sr_test_1 = root.down().node()
    assert sr_test_1.image.name == 'shipwright_test/1'

    assert _names(root.down()) == ['shipwright_test/2', 'shipwright_test/3']

    sr_test_2 = root.down().down().node()

# Path: shipwright/_lib/dependencies.py
# def eval(build_targets, targets):
# def _find(tree, name):
#     def find_(loc):
# def _make_tree(images):
#         def is_child(target):
# def _replace(node, children):
# def _children(item):
# def _is_branch(item):
# def _make_node(node, children):
# def _breadth_first_iter(loc):
# def _lineage(loc):
# def _split(f, children):
# def _brood(loc):
# def _upto(target, tree):
# def _dependents(target, tree):
# def _exact(target, tree):
# def _exclude(target, tree):
# 
# Path: shipwright/_lib/image.py
# def list_images(namespace, name_map, root_path):
# def image_name(namespace, name_map, root_path, path):
# def build_files(build_root):
# def name(docker_path):
# def sub_if(ex, repl, string, flags):
# def parse_copy(cmd):
# def copy_paths(docker_path):
#     def join(path):
#     def copy_paths_gen():
# def parent(docker_path):
# 
# Path: shipwright/_lib/source_control.py
# def source_control(path, namespace, name_map, mode=None):
#     if mode is None:
#         mode = AUTO
#     assert isinstance(mode, Mode)
#     the_mode = mode if mode is not AUTO else get_mode(path)
#     for cls in SourceControl.__subclasses__():
#         if cls.mode is the_mode:
#             return cls(path, namespace, name_map)


# Path: tests/test_dependencies.py
from shipwright._lib import dependencies, image, source_control



def test_breadth_first_iter():
    bt = default_build_targets()
    results = [result.name for result in dependencies.eval(bt, targets)]
    assert results == [
        'shipwright_test/1',
        'shipwright_test/independent',
        'shipwright_test/2',
        'shipwright_test/3',
    ]


def test_make_tree():
    root = dependencies._make_tree(targets)
    assert root.node().name is None

    assert _names(root) == [
        'shipwright_test/1',
        'shipwright_test/independent',
        'shipwright_test/2',
        'shipwright_test/3',
    ]

    sr_test_1 = root.down().node()
    assert sr_test_1.image.name == 'shipwright_test/1'

    assert _names(root.down()) == ['shipwright_test/2', 'shipwright_test/3']

    sr_test_2 = root.down().down().node()

    assert sr_test_2.image.name == 'shipwright_test/2'