# Path: dockci/util.py
# def add_to_url_path(url, more_path):
#     """ Appends ``more_path`` to ``url`` path, and normalizes the output """
#     url = list(urlparse(url))
#     url[2] = re.sub('//+', '/', ('%s/%s' % (url[2], more_path)))
#     return urlunparse(url)
# 
# def client_kwargs_from_config(host_str):
#     """ Generate Docker Client kwargs from the host string """
#     docker_host, *arg_strings = shlex.split(host_str)
#     docker_client_args = {
#         'base_url': docker_host,
#     }
# 
#     tls_args = {}
#     for arg_string in arg_strings:
#         arg_name, arg_val = arg_string.split('=', 1)
#         if arg_name == 'cert_path':
#             cert_path = py.path.local(arg_val)
#             tls_args['client_cert'] = (
#                 cert_path.join('cert.pem').strpath,
#                 cert_path.join('key.pem').strpath,
#             )
# 
#             # Assign the CA if it exists, and verify isn't overridden
#             ca_path = cert_path.join('ca.pem')
#             if ca_path.check() and tls_args.get('verify', None) != False:
#                 tls_args['verify'] = ca_path.strpath
# 
#         elif arg_name == 'assert_hostname':
#             tls_args[arg_name] = str2bool(arg_val)
# 
#         elif arg_name == 'verify':
#             tls_args[arg_name] = str2bool(arg_val)
# 
#         elif arg_name == 'ssl_version':
#             tls_args['ssl_version'] = getattr(ssl, 'PROTOCOL_%s' % arg_val)
# 
#     if tls_args:
#         docker_client_args['tls'] = docker.tls.TLSConfig(**tls_args)
# 
#     return docker_client_args
# 
# def parse_ref(ref):
#     """
#     Discover what type of ref is passed in, and convert to a short ref name. It
#     is assumed that a ref with no full name is a branch.
# 
#     Returns:
#       tuple(str, str): Ref type, and ref short name
#       tuple(None, str): Ref type was unknown. Ref name is the full ref
#     """
#     for ref_type, func in (
#         ('branch', parse_branch_from_ref),
#         ('tag', parse_tag_from_ref),
#         ('branch', lambda ref: parse_branch_from_ref(ref, relax=True))
#     ):
#         parsed = func(ref)
#         if parsed is not None:
#             return ref_type, parsed
# 
#     return None, ref


import io
import json
import subprocess
import docker
import pytest
from dockci.util import (add_to_url_path,
                         client_kwargs_from_config,
                         parse_ref,
                         )
        """ Test that ``verify=no`` overrides ``cert_path`` """
        tmpdir.join('cert.pem').ensure()
        tmpdir.join('key.pem').ensure()
        tmpdir.join('ca.pem').ensure()

        out = client_kwargs_from_config(
            host_str_fs.format(cert_path=tmpdir.strpath),
        )

        assert out['tls'].cert == (
            tmpdir.join('cert.pem').strpath,
            tmpdir.join('key.pem').strpath,
        )
        assert out['tls'].verify == False

    def test_certs_error(self, tmpdir):
        """ Test raising ``TLSParameterError`` when certs don't exist """
        with pytest.raises(docker.errors.TLSParameterError):
            client_kwargs_from_config(
                'http://l cert_path=%s' % tmpdir.strpath
            )

    def test_no_ca_no_error(self, tmpdir):
        """
        Ensure that when client cert/key exists, but the CA doesn't, cert
        params are set without verify
        """
        tmpdir.join('cert.pem').ensure()
        tmpdir.join('key.pem').ensure()


# Path: dockci/util.py
# def add_to_url_path(url, more_path):
#     """ Appends ``more_path`` to ``url`` path, and normalizes the output """
#     url = list(urlparse(url))
#     url[2] = re.sub('//+', '/', ('%s/%s' % (url[2], more_path)))
#     return urlunparse(url)
# 
# def client_kwargs_from_config(host_str):
#     """ Generate Docker Client kwargs from the host string """
#     docker_host, *arg_strings = shlex.split(host_str)
#     docker_client_args = {
#         'base_url': docker_host,
#     }
# 
#     tls_args = {}
#     for arg_string in arg_strings:
#         arg_name, arg_val = arg_string.split('=', 1)
#         if arg_name == 'cert_path':
#             cert_path = py.path.local(arg_val)
#             tls_args['client_cert'] = (
#                 cert_path.join('cert.pem').strpath,
#                 cert_path.join('key.pem').strpath,
#             )
# 
#             # Assign the CA if it exists, and verify isn't overridden
#             ca_path = cert_path.join('ca.pem')
#             if ca_path.check() and tls_args.get('verify', None) != False:
#                 tls_args['verify'] = ca_path.strpath
# 
#         elif arg_name == 'assert_hostname':
#             tls_args[arg_name] = str2bool(arg_val)
# 
#         elif arg_name == 'verify':
#             tls_args[arg_name] = str2bool(arg_val)
# 
#         elif arg_name == 'ssl_version':
#             tls_args['ssl_version'] = getattr(ssl, 'PROTOCOL_%s' % arg_val)
# 
#     if tls_args:
#         docker_client_args['tls'] = docker.tls.TLSConfig(**tls_args)
# 
#     return docker_client_args
# 
# def parse_ref(ref):
#     """
#     Discover what type of ref is passed in, and convert to a short ref name. It
#     is assumed that a ref with no full name is a branch.
# 
#     Returns:
#       tuple(str, str): Ref type, and ref short name
#       tuple(None, str): Ref type was unknown. Ref name is the full ref
#     """
#     for ref_type, func in (
#         ('branch', parse_branch_from_ref),
#         ('tag', parse_tag_from_ref),
#         ('branch', lambda ref: parse_branch_from_ref(ref, relax=True))
#     ):
#         parsed = func(ref)
#         if parsed is not None:
#             return ref_type, parsed
# 
#     return None, ref


# Path: tests/test_util.py
import io
import json
import subprocess
import docker
import pytest
from dockci.util import (add_to_url_path,
                         client_kwargs_from_config,
                         parse_ref,
                         )

        """ Test that ``verify=no`` overrides ``cert_path`` """
        tmpdir.join('cert.pem').ensure()
        tmpdir.join('key.pem').ensure()
        tmpdir.join('ca.pem').ensure()

        out = client_kwargs_from_config(
            host_str_fs.format(cert_path=tmpdir.strpath),
        )

        assert out['tls'].cert == (
            tmpdir.join('cert.pem').strpath,
            tmpdir.join('key.pem').strpath,
        )
        assert out['tls'].verify == False

    def test_certs_error(self, tmpdir):
        """ Test raising ``TLSParameterError`` when certs don't exist """
        with pytest.raises(docker.errors.TLSParameterError):
            client_kwargs_from_config(
                'http://l cert_path=%s' % tmpdir.strpath
            )

    def test_no_ca_no_error(self, tmpdir):
        """
        Ensure that when client cert/key exists, but the CA doesn't, cert
        params are set without verify
        """
        tmpdir.join('cert.pem').ensure()
        tmpdir.join('key.pem').ensure()


        out = client_kwargs_from_config(