# Path: marvin_python_toolbox/management/pkg.py
# def _clone(repo):
#     return repo, git_clone(repo, checkout=False, depth=1)
# 
# Path: marvin_python_toolbox/management/pkg.py
# def copy(src, dest, ignore=('.git', '.pyc', '__pycache__')):
#     try:
#         shutil.copytree(src, dest, ignore=shutil.ignore_patterns(*ignore))
#     except OSError as e:
#         if e.errno == errno.ENOTDIR:
#             shutil.copy(src, dest)
#         else:
#             print('Directory not copied. Error: %s' % e)
# 
# Path: marvin_python_toolbox/management/pkg.py
# def get_git_branch(path=None):
#     if path is None:
#         path = os.path.curdir
#     command = 'git rev-parse --abbrev-ref HEAD'.split()
#     branch = subprocess.Popen(command, stdout=subprocess.PIPE, cwd=path).stdout.read()
#     return branch.strip().decode('utf-8')
# 
# Path: marvin_python_toolbox/management/pkg.py
# def is_git_clean(path=None):
#     if path is None:
#         path = os.path.curdir
#     command = 'git diff --quiet HEAD'.split()
#     exit_code = subprocess.Popen(command, stdout=subprocess.PIPE, cwd=path).stdout.read()
#     return exit_code
# 
# Path: marvin_python_toolbox/management/pkg.py
# def get_git_tags(path=None):
#     if path is None:
#         path = os.path.curdir
#     command = 'git tag'.split()
#     tags = subprocess.Popen(command, stdout=subprocess.PIPE, cwd=path).stdout.read()
#     return sorted(tags.strip().split('\n'), reverse=True)
# 
# Path: marvin_python_toolbox/management/pkg.py
# def get_git_repository_url(path=None):
#     if path is None:
#         path = os.path.curdir
#     command = 'git config --get remote.origin.url'.split()
#     url = subprocess.Popen(command, stdout=subprocess.PIPE, cwd=path).stdout.read()
#     return url.strip().decode('utf-8')
# 
# Path: marvin_python_toolbox/management/pkg.py
# def get_git_tag(path=None):
#     if path is None:
#         path = os.path.curdir
#     command = 'git rev-list --tags --max-count=1'.split()
#     commit = subprocess.Popen(command, stdout=subprocess.PIPE, cwd=path).stdout.read().decode('utf-8')
#     command = 'git describe --tags {}'.format(commit).split()
#     tag = subprocess.Popen(command, stdout=subprocess.PIPE, cwd=path).stdout.read().decode('utf-8')
#     return tag.strip()
# 
# Path: marvin_python_toolbox/management/pkg.py
# def get_git_commit(path=None, tag=None):
#     if path is None:
#         path = os.path.curdir
#     if tag:
#         command = 'git rev-list -n 1 {tag}'.format(tag=tag).split()
#     else:
#         command = 'git rev-parse HEAD'.split()
#     commit = subprocess.Popen(command, stdout=subprocess.PIPE, cwd=path).stdout.read()
#     return commit.strip().decode('utf-8')
# 
# Path: marvin_python_toolbox/management/pkg.py
# def get_tag_from_repo_url(repos):
#     tags = {}
#     for repo in repos:
#         if '@' in repo:
#             repo_parsed = urlparse(repo)
#             repo_path = repo_parsed.path
#             tags[repo] = repo_path.split('@')[1]
#         else:
#             tags[repo] = None
#     return tags
# 
# Path: marvin_python_toolbox/management/pkg.py
# def get_repos_from_requirements(path):
#     if path is None:
#         path = os.path.curdir
#     with open(os.path.join(path, 'requirements.txt'), 'r') as fp:
#         repos = [line.strip() for line in fp if 'git@' in line and not line.strip().startswith('#')]
#     return repos


    import mock
    import unittest.mock as mock
from marvin_python_toolbox.management.pkg import _clone
from marvin_python_toolbox.management.pkg import copy
from marvin_python_toolbox.management.pkg import get_git_branch
from marvin_python_toolbox.management.pkg import is_git_clean
from marvin_python_toolbox.management.pkg import get_git_tags
from marvin_python_toolbox.management.pkg import get_git_repository_url
from marvin_python_toolbox.management.pkg import get_git_tag
from marvin_python_toolbox.management.pkg import get_git_commit
from marvin_python_toolbox.management.pkg import get_tag_from_repo_url
from marvin_python_toolbox.management.pkg import get_repos_from_requirements

    get_repos_from_requirements(path=None)

    join_mocked.assert_called_with(curdir_mocked, 'requirements.txt')
    open_mocked.assert_called_with('/tmp', 'r')

    get_repos_from_requirements(path='/path')

    join_mocked.assert_called_with('/path', 'requirements.txt')
    open_mocked.assert_called_with('/tmp', 'r')


def test_get_tag_from_repo_url():
    repos = ['http://www.xxx.org:80/tag@/repo.html']

    tags = get_tag_from_repo_url(repos)

    assert tags == {'http://www.xxx.org:80/tag@/repo.html': '/repo.html'}

    repos = ['http://www.xxx.org:80/tag/repo.html']

    tags = get_tag_from_repo_url(repos)

    assert tags == {'http://www.xxx.org:80/tag/repo.html': None}


@mock.patch('marvin_python_toolbox.management.pkg.git_clone')
def test_clone(git_mocked):
    git_mocked.return_value = 1
    repo = 'http://xxx.git'

# Path: marvin_python_toolbox/management/pkg.py
# def _clone(repo):
#     return repo, git_clone(repo, checkout=False, depth=1)
# 
# Path: marvin_python_toolbox/management/pkg.py
# def copy(src, dest, ignore=('.git', '.pyc', '__pycache__')):
#     try:
#         shutil.copytree(src, dest, ignore=shutil.ignore_patterns(*ignore))
#     except OSError as e:
#         if e.errno == errno.ENOTDIR:
#             shutil.copy(src, dest)
#         else:
#             print('Directory not copied. Error: %s' % e)
# 
# Path: marvin_python_toolbox/management/pkg.py
# def get_git_branch(path=None):
#     if path is None:
#         path = os.path.curdir
#     command = 'git rev-parse --abbrev-ref HEAD'.split()
#     branch = subprocess.Popen(command, stdout=subprocess.PIPE, cwd=path).stdout.read()
#     return branch.strip().decode('utf-8')
# 
# Path: marvin_python_toolbox/management/pkg.py
# def is_git_clean(path=None):
#     if path is None:
#         path = os.path.curdir
#     command = 'git diff --quiet HEAD'.split()
#     exit_code = subprocess.Popen(command, stdout=subprocess.PIPE, cwd=path).stdout.read()
#     return exit_code
# 
# Path: marvin_python_toolbox/management/pkg.py
# def get_git_tags(path=None):
#     if path is None:
#         path = os.path.curdir
#     command = 'git tag'.split()
#     tags = subprocess.Popen(command, stdout=subprocess.PIPE, cwd=path).stdout.read()
#     return sorted(tags.strip().split('\n'), reverse=True)
# 
# Path: marvin_python_toolbox/management/pkg.py
# def get_git_repository_url(path=None):
#     if path is None:
#         path = os.path.curdir
#     command = 'git config --get remote.origin.url'.split()
#     url = subprocess.Popen(command, stdout=subprocess.PIPE, cwd=path).stdout.read()
#     return url.strip().decode('utf-8')
# 
# Path: marvin_python_toolbox/management/pkg.py
# def get_git_tag(path=None):
#     if path is None:
#         path = os.path.curdir
#     command = 'git rev-list --tags --max-count=1'.split()
#     commit = subprocess.Popen(command, stdout=subprocess.PIPE, cwd=path).stdout.read().decode('utf-8')
#     command = 'git describe --tags {}'.format(commit).split()
#     tag = subprocess.Popen(command, stdout=subprocess.PIPE, cwd=path).stdout.read().decode('utf-8')
#     return tag.strip()
# 
# Path: marvin_python_toolbox/management/pkg.py
# def get_git_commit(path=None, tag=None):
#     if path is None:
#         path = os.path.curdir
#     if tag:
#         command = 'git rev-list -n 1 {tag}'.format(tag=tag).split()
#     else:
#         command = 'git rev-parse HEAD'.split()
#     commit = subprocess.Popen(command, stdout=subprocess.PIPE, cwd=path).stdout.read()
#     return commit.strip().decode('utf-8')
# 
# Path: marvin_python_toolbox/management/pkg.py
# def get_tag_from_repo_url(repos):
#     tags = {}
#     for repo in repos:
#         if '@' in repo:
#             repo_parsed = urlparse(repo)
#             repo_path = repo_parsed.path
#             tags[repo] = repo_path.split('@')[1]
#         else:
#             tags[repo] = None
#     return tags
# 
# Path: marvin_python_toolbox/management/pkg.py
# def get_repos_from_requirements(path):
#     if path is None:
#         path = os.path.curdir
#     with open(os.path.join(path, 'requirements.txt'), 'r') as fp:
#         repos = [line.strip() for line in fp if 'git@' in line and not line.strip().startswith('#')]
#     return repos


# Path: tests/management/test_pkg.py
    import mock
    import unittest.mock as mock
from marvin_python_toolbox.management.pkg import _clone
from marvin_python_toolbox.management.pkg import copy
from marvin_python_toolbox.management.pkg import get_git_branch
from marvin_python_toolbox.management.pkg import is_git_clean
from marvin_python_toolbox.management.pkg import get_git_tags
from marvin_python_toolbox.management.pkg import get_git_repository_url
from marvin_python_toolbox.management.pkg import get_git_tag
from marvin_python_toolbox.management.pkg import get_git_commit
from marvin_python_toolbox.management.pkg import get_tag_from_repo_url
from marvin_python_toolbox.management.pkg import get_repos_from_requirements


    get_repos_from_requirements(path=None)

    join_mocked.assert_called_with(curdir_mocked, 'requirements.txt')
    open_mocked.assert_called_with('/tmp', 'r')

    get_repos_from_requirements(path='/path')

    join_mocked.assert_called_with('/path', 'requirements.txt')
    open_mocked.assert_called_with('/tmp', 'r')


def test_get_tag_from_repo_url():
    repos = ['http://www.xxx.org:80/tag@/repo.html']

    tags = get_tag_from_repo_url(repos)

    assert tags == {'http://www.xxx.org:80/tag@/repo.html': '/repo.html'}

    repos = ['http://www.xxx.org:80/tag/repo.html']

    tags = get_tag_from_repo_url(repos)

    assert tags == {'http://www.xxx.org:80/tag/repo.html': None}


@mock.patch('marvin_python_toolbox.management.pkg.git_clone')
def test_clone(git_mocked):
    git_mocked.return_value = 1
    repo = 'http://xxx.git'

    result = _clone(repo)