# 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
#!/usr/bin/env python
# coding=utf-8

# Copyright [2017] [B2W Digital]
#
# Licensed under the Apache License, Version 2.0 (the 'License');
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an 'AS IS' BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# from click.testing import CliRunner

try:
except ImportError:



@mock.patch('marvin_python_toolbox.management.pkg.open')
@mock.patch('marvin_python_toolbox.management.pkg.os.path.join')
@mock.patch('marvin_python_toolbox.management.pkg.os.path.curdir')
def test_get_repos_from_requirements(curdir_mocked, join_mocked, open_mocked):
    join_mocked.return_value = '/tmp'


# 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

#!/usr/bin/env python
# coding=utf-8

# Copyright [2017] [B2W Digital]
#
# Licensed under the Apache License, Version 2.0 (the 'License');
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an 'AS IS' BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# from click.testing import CliRunner

try:
except ImportError:



@mock.patch('marvin_python_toolbox.management.pkg.open')
@mock.patch('marvin_python_toolbox.management.pkg.os.path.join')
@mock.patch('marvin_python_toolbox.management.pkg.os.path.curdir')
def test_get_repos_from_requirements(curdir_mocked, join_mocked, open_mocked):
    join_mocked.return_value = '/tmp'


    get_repos_from_requirements(path=None)