# Path: muranoclient/common/utils.py
# LOG = logging.getLogger(__name__)
# def arg(*args, **kwargs):
#     def _decorator(func):
# def json_formatter(js):
# def text_wrap_formatter(d):
# def pretty_choice_list(l):
# def print_list(objs, fields, field_labels, formatters=None, sortby=0):
# def print_dict(d, formatters=None):
# def find_resource(manager, name_or_id, *args, **kwargs):
# def string_to_bool(arg):
# def env(*vars, **kwargs):
# def exit(msg=''):
# def getsockopt(self, *args, **kwargs):
# def exception_to_str(exc):
#     def __init__(self, obj):
#     def close(self):
#     def __getattr__(self, name):
#     def __init__(self, name, binary=True):
#     def open(self):
# def to_url(filename, base_url, version='', path='/', extension=''):
#     def __init__(self, file_wrapper):
#     def file(self):
#     def close(self):
#     def save(self, dst, binary=True):
#     def __del__(self):
#     def from_file(file_obj):
#     def fromFile(file_obj):
#     def from_location(name, base_url='', version='', url='', path=None):
#     def validate(self):
#     def contents(self):
#     def manifest(self):
#     def images(self):
#     def resolvers(self):
#     def classes(self):
#     def ui(self):
#     def logo(self):
#     def _get_package_order(self, packages_graph):
#         def topological_sort(graph, start_node):
#             def dfs(node):
#         def transpose_graph(graph):
#         def top_sort_by_components(graph, component_order):
#             def dfs(node):
#     def requirements(self, base_url, path=None, dep_dict=None):
#     def _get_direct_deps(package, base_url, path):
# def save_image_local(image_spec, base_url, dst):
# def ensure_images(glance_client, image_specs, base_url,
#                   local_path=None,
#                   is_package_public=False):
#     def _image_valid(image, keys):
#     def from_file(file_obj):
#     def fromFile(file_obj):
#     def package_specs(self):
#     def packages(self, base_url='', path=None):
# def yaql_constructor(loader, node):
# def traverse_and_replace(obj,
#                          pattern=re.compile(r'^===id(\d+)===$'),
#                          replacements=None):
#     def _maybe_replace(obj, key, value):
#     def __init__(self, namespaces):
#     def resolve_name(self, name, relative=None):
# class NoCloseProxy(object):
# class File(object):
# class FileWrapperMixin(object):
# class Package(FileWrapperMixin):
# class Bundle(FileWrapperMixin):
# class DummyYaqlYamlLoader(yaml.SafeLoader):
# class YaqlYamlLoader(yaml.SafeLoader):
# class NamespaceResolver(object):


import io
import json
import os.path
import tempfile
import zipfile
import requests
import requests_mock
import testtools
import yaml
from unittest import mock
from muranoclient.common import utils
            'dep_app': None}, })

        m.get(self.base_url + '/apps/main_app.zip', body=pkg1)
        m.get(self.base_url + '/apps/dep_app.zip', body=pkg2)
        m.get(self.base_url + '/apps/dep_of_dep.1.0.zip', body=pkg3)
        app = utils.Package.fromFile(pkg1)
        reqs = app.requirements(base_url=self.base_url)

        self.assertEqual(
            {'main_app': app, 'dep_app': mock.ANY, 'dep_of_dep': mock.ANY},
            reqs)

    @mock.patch('muranoclient.common.utils.Package.from_file')
    def test_requirements_order(self, from_file):
        """Test that dependencies are parsed in correct order."""

        pkg5 = make_pkg({'FullName': 'd4', })
        pkg4 = make_pkg({'FullName': 'd3', 'Require': {'d4': None}, })
        pkg3 = make_pkg({'FullName': 'd2', 'Require': {'d3': None}, })
        pkg2 = make_pkg({'FullName': 'd1', 'Require': {'d3': None}, })
        pkg1 = make_pkg({'FullName': 'M', 'Require': {'d1': None,
                                                      'd2': None,
                                                      'd4': None}, })

        def side_effect(name):
            if 'M' in name:
                return utils.Package(utils.File(pkg1))
            if 'd1' in name:
                return utils.Package(utils.File(pkg2))
            if 'd2' in name:

# Path: muranoclient/common/utils.py
# LOG = logging.getLogger(__name__)
# def arg(*args, **kwargs):
#     def _decorator(func):
# def json_formatter(js):
# def text_wrap_formatter(d):
# def pretty_choice_list(l):
# def print_list(objs, fields, field_labels, formatters=None, sortby=0):
# def print_dict(d, formatters=None):
# def find_resource(manager, name_or_id, *args, **kwargs):
# def string_to_bool(arg):
# def env(*vars, **kwargs):
# def exit(msg=''):
# def getsockopt(self, *args, **kwargs):
# def exception_to_str(exc):
#     def __init__(self, obj):
#     def close(self):
#     def __getattr__(self, name):
#     def __init__(self, name, binary=True):
#     def open(self):
# def to_url(filename, base_url, version='', path='/', extension=''):
#     def __init__(self, file_wrapper):
#     def file(self):
#     def close(self):
#     def save(self, dst, binary=True):
#     def __del__(self):
#     def from_file(file_obj):
#     def fromFile(file_obj):
#     def from_location(name, base_url='', version='', url='', path=None):
#     def validate(self):
#     def contents(self):
#     def manifest(self):
#     def images(self):
#     def resolvers(self):
#     def classes(self):
#     def ui(self):
#     def logo(self):
#     def _get_package_order(self, packages_graph):
#         def topological_sort(graph, start_node):
#             def dfs(node):
#         def transpose_graph(graph):
#         def top_sort_by_components(graph, component_order):
#             def dfs(node):
#     def requirements(self, base_url, path=None, dep_dict=None):
#     def _get_direct_deps(package, base_url, path):
# def save_image_local(image_spec, base_url, dst):
# def ensure_images(glance_client, image_specs, base_url,
#                   local_path=None,
#                   is_package_public=False):
#     def _image_valid(image, keys):
#     def from_file(file_obj):
#     def fromFile(file_obj):
#     def package_specs(self):
#     def packages(self, base_url='', path=None):
# def yaql_constructor(loader, node):
# def traverse_and_replace(obj,
#                          pattern=re.compile(r'^===id(\d+)===$'),
#                          replacements=None):
#     def _maybe_replace(obj, key, value):
#     def __init__(self, namespaces):
#     def resolve_name(self, name, relative=None):
# class NoCloseProxy(object):
# class File(object):
# class FileWrapperMixin(object):
# class Package(FileWrapperMixin):
# class Bundle(FileWrapperMixin):
# class DummyYaqlYamlLoader(yaml.SafeLoader):
# class YaqlYamlLoader(yaml.SafeLoader):
# class NamespaceResolver(object):


# Path: muranoclient/tests/unit/test_utils.py
import io
import json
import os.path
import tempfile
import zipfile
import requests
import requests_mock
import testtools
import yaml
from unittest import mock
from muranoclient.common import utils

            'dep_app': None}, })

        m.get(self.base_url + '/apps/main_app.zip', body=pkg1)
        m.get(self.base_url + '/apps/dep_app.zip', body=pkg2)
        m.get(self.base_url + '/apps/dep_of_dep.1.0.zip', body=pkg3)
        app = utils.Package.fromFile(pkg1)
        reqs = app.requirements(base_url=self.base_url)

        self.assertEqual(
            {'main_app': app, 'dep_app': mock.ANY, 'dep_of_dep': mock.ANY},
            reqs)

    @mock.patch('muranoclient.common.utils.Package.from_file')
    def test_requirements_order(self, from_file):
        """Test that dependencies are parsed in correct order."""

        pkg5 = make_pkg({'FullName': 'd4', })
        pkg4 = make_pkg({'FullName': 'd3', 'Require': {'d4': None}, })
        pkg3 = make_pkg({'FullName': 'd2', 'Require': {'d3': None}, })
        pkg2 = make_pkg({'FullName': 'd1', 'Require': {'d3': None}, })
        pkg1 = make_pkg({'FullName': 'M', 'Require': {'d1': None,
                                                      'd2': None,
                                                      'd4': None}, })

        def side_effect(name):
            if 'M' in name:
                return utils.Package(utils.File(pkg1))
            if 'd1' in name:
                return utils.Package(utils.File(pkg2))
            if 'd2' in name:

                return utils.Package(utils.File(pkg3))