# Path: yagocd/resources/pipeline.py
# class PipelineManager(BaseManager):
# class PipelineEntity(BaseNode):
# class PipelineInstance(BaseNode):
#     GROUPS_RESOURCE_PATH = '{base_api}/config/pipeline_groups'
#     RESOURCE_PATH = '{base_api}/pipelines/{name}'
#     VSM_RESOURCE_PATH = '{base_api}/pipelines/value_stream_map/{name}'
#     def __iter__(self):
#     def __getitem__(self, name):
#     def list(self):
#     def find(self, name):
#     def history(self, name, offset=0):
#     def full_history(self, name):
#     def last(self, name):
#     def get(self, name, counter):
#     def status(self, name):
#     def pause(self, name, cause):
#     def unpause(self, name):
#     def release_lock(self, name):
#     def schedule(self, name, materials=None, variables=None, secure_variables=None):
#     def schedule_with_instance(
#         self,
#         name,
#         materials=None,
#         variables=None,
#         secure_variables=None,
#         backoff=0.5,
#         max_tries=20
#     ):
#     def value_stream_map(self, name, counter):
#     def __init__(self, session, data, group=None):
#     def __iter__(self):
#     def __getitem__(self, counter):
#     def group(self):
#     def get_url(server_url, pipeline_name):
#     def url(self):
#     def config(self):
#     def history(self, offset=0):
#     def full_history(self):
#     def last(self):
#     def get(self, counter):
#     def status(self):
#     def pause(self, cause):
#     def unpause(self):
#     def release_lock(self):
#     def schedule(self, materials=None, variables=None, secure_variables=None):
#     def schedule_with_instance(
#         self,
#         materials=None,
#         variables=None,
#         secure_variables=None,
#         backoff=0.5,
#         max_tries=20
#     ):
#     def value_stream_map(self, counter):
#     def __init__(self, session, data):
#     def __iter__(self):
#     def __getitem__(self, name):
#     def url(self):
#     def pipeline_url(self):
#     def stages(self):
#     def stage(self, name):
#     def value_stream_map(self):
#     def config(self):
# 
# Path: yagocd/util.py
# class YagocdUtil(object):
# class Since(object):
# class RequireParamMixin(object):
#     def build_graph(nodes, dependencies, compare):
#     def graph_depth_walk(root_nodes, near_nodes):
#     def choose_option(cls, version_to_options, default, server_version):
#     def __init__(self, since_version):
#     def __call__(self, entity):
#         def decorated(*args, **kwargs):
#     def _require_param(self, name, values):
#     ENABLED = True


import pytest
from mock import mock
from yagocd.resources import pipeline
from yagocd.util import since, YagocdUtil
            data={'name': 'child1', 'materials': {}}
        )

        parent_a = pipeline.PipelineEntity(
            session=session_fixture,
            data={'name': 'parent1', 'materials': [{'description': 'child1', 'type': 'Pipeline'}]}
        )

        pipelines = [child_a, parent_a]

        YagocdUtil.build_graph(
            nodes=pipelines,
            dependencies=lambda parent: [material for material in parent.data.materials],
            compare=lambda candidate, child: candidate.description == child.data.name
        )
        assert child_a.descendants == [parent_a]


class TestGraphDepthWalk(object):
    @pytest.mark.parametrize("root, expected", [
        ('a', ['a', 'c']),
        ('b', ['a', 'c', 'b']),
        ('c', ['c']),
        ('d', ['a', 'c', 'd']),
        ('e', ['a', 'c', 'b', 'e']),
    ])
    def test_graph(self, root, expected):
        graph = {'a': ['c'], 'b': ['a'], 'c': [], 'd': ['a'], 'e': ['b', 'a']}

        assert len(YagocdUtil.graph_depth_walk(root, lambda x: graph.get(x))) == len(expected)

# Path: yagocd/resources/pipeline.py
# class PipelineManager(BaseManager):
# class PipelineEntity(BaseNode):
# class PipelineInstance(BaseNode):
#     GROUPS_RESOURCE_PATH = '{base_api}/config/pipeline_groups'
#     RESOURCE_PATH = '{base_api}/pipelines/{name}'
#     VSM_RESOURCE_PATH = '{base_api}/pipelines/value_stream_map/{name}'
#     def __iter__(self):
#     def __getitem__(self, name):
#     def list(self):
#     def find(self, name):
#     def history(self, name, offset=0):
#     def full_history(self, name):
#     def last(self, name):
#     def get(self, name, counter):
#     def status(self, name):
#     def pause(self, name, cause):
#     def unpause(self, name):
#     def release_lock(self, name):
#     def schedule(self, name, materials=None, variables=None, secure_variables=None):
#     def schedule_with_instance(
#         self,
#         name,
#         materials=None,
#         variables=None,
#         secure_variables=None,
#         backoff=0.5,
#         max_tries=20
#     ):
#     def value_stream_map(self, name, counter):
#     def __init__(self, session, data, group=None):
#     def __iter__(self):
#     def __getitem__(self, counter):
#     def group(self):
#     def get_url(server_url, pipeline_name):
#     def url(self):
#     def config(self):
#     def history(self, offset=0):
#     def full_history(self):
#     def last(self):
#     def get(self, counter):
#     def status(self):
#     def pause(self, cause):
#     def unpause(self):
#     def release_lock(self):
#     def schedule(self, materials=None, variables=None, secure_variables=None):
#     def schedule_with_instance(
#         self,
#         materials=None,
#         variables=None,
#         secure_variables=None,
#         backoff=0.5,
#         max_tries=20
#     ):
#     def value_stream_map(self, counter):
#     def __init__(self, session, data):
#     def __iter__(self):
#     def __getitem__(self, name):
#     def url(self):
#     def pipeline_url(self):
#     def stages(self):
#     def stage(self, name):
#     def value_stream_map(self):
#     def config(self):
# 
# Path: yagocd/util.py
# class YagocdUtil(object):
# class Since(object):
# class RequireParamMixin(object):
#     def build_graph(nodes, dependencies, compare):
#     def graph_depth_walk(root_nodes, near_nodes):
#     def choose_option(cls, version_to_options, default, server_version):
#     def __init__(self, since_version):
#     def __call__(self, entity):
#         def decorated(*args, **kwargs):
#     def _require_param(self, name, values):
#     ENABLED = True


# Path: tests/test_util.py
import pytest
from mock import mock
from yagocd.resources import pipeline
from yagocd.util import since, YagocdUtil

            data={'name': 'child1', 'materials': {}}
        )

        parent_a = pipeline.PipelineEntity(
            session=session_fixture,
            data={'name': 'parent1', 'materials': [{'description': 'child1', 'type': 'Pipeline'}]}
        )

        pipelines = [child_a, parent_a]

        YagocdUtil.build_graph(
            nodes=pipelines,
            dependencies=lambda parent: [material for material in parent.data.materials],
            compare=lambda candidate, child: candidate.description == child.data.name
        )
        assert child_a.descendants == [parent_a]


class TestGraphDepthWalk(object):
    @pytest.mark.parametrize("root, expected", [
        ('a', ['a', 'c']),
        ('b', ['a', 'c', 'b']),
        ('c', ['c']),
        ('d', ['a', 'c', 'd']),
        ('e', ['a', 'c', 'b', 'e']),
    ])
    def test_graph(self, root, expected):
        graph = {'a': ['c'], 'b': ['a'], 'c': [], 'd': ['a'], 'e': ['b', 'a']}

        assert len(YagocdUtil.graph_depth_walk(root, lambda x: graph.get(x))) == len(expected)

        assert sorted(YagocdUtil.graph_depth_walk(root, lambda x: graph.get(x))) == sorted(expected)