# Path: artman/tasks/python_grpc_tasks.py
# class PythonChangePackageTask(task_base.TaskBase):
# class PythonMoveProtosTask(task_base.TaskBase):
#     _IDENTIFIER = '[A-Za-z_][A-Za-z_0-9]*'
#     _BASE_PROTO_REGEX = (
#         '(?P<prefix>{prefix})' +
#         '(?P<package>' + _IDENTIFIER +
#         '({separator}' + _IDENTIFIER + ')*{package_suffix})'
#         '(?P<suffix>{suffix})')
#     _PACKAGE_REGEX = re.compile(_BASE_PROTO_REGEX.format(
#         prefix='^package ',
#         separator='\\.',
#         package_suffix='',
#         suffix=''))
#     _IMPORT_REGEX = re.compile(_BASE_PROTO_REGEX.format(
#         prefix='^import (?:public )?"',
#         separator='/',
#         package_suffix='\\.proto',
#         suffix='";'))
#     def execute(self, src_proto_path, import_proto_path,
#                 organization_name):
#     def _extract_base_dirs(self, proto_file):
#     def _transform(self, pkg, sep, common_protos):
#     def _copy_proto(self, src, dest, common_protos):
#     def _copy_and_transform_directories(
#             self, src_directories, destination_directory, common_protos,
#             paths=None):
#     def execute(self, grpc_code_dir, gapic_code_dir):
#     def _get_gapic_subdir_path(self, haystack):
#     def _get_proto_path(self, grpc_path):


import os
import mock
import pytest
from artman.tasks import python_grpc_tasks
    task = python_grpc_tasks.PythonMoveProtosTask()
    with mock.patch.object(os, 'listdir') as listdir:
        listdir.return_value = ['docs', 'tests', 'other', 'project']
        with mock.patch.object(os, 'walk') as walk:
            walk.side_effect = lambda x: {
                os.path.join('.', 'other'):
                    (('other', [], []),),
                os.path.join('.', 'project'):(
                    ('project', ['v1'], []),
                    ('project/v1', ['gapic'], []),
                    ('project/v1/gapic', [], ['__init__.py']),)
            }[x]
            assert task._get_gapic_subdir_path('.') == 'project/v1'
            # 'tests' and 'docs' directories are skipped.
            assert walk.call_count == 2
            assert walk.mock_calls[0][1] == (os.path.join('.', 'other'),)
            assert walk.mock_calls[1][1] == (os.path.join('.', 'project'),)


def test__get_gapic_subdir_path_not_found():
    task = python_grpc_tasks.PythonMoveProtosTask()
    with mock.patch.object(os, 'walk') as walk:
        walk.return_value = (
            ('foo', ['bar'], []),
        )
        with pytest.raises(RuntimeError):
            task._get_gapic_subdir_path('.')


def test_move_protos():

# Path: artman/tasks/python_grpc_tasks.py
# class PythonChangePackageTask(task_base.TaskBase):
# class PythonMoveProtosTask(task_base.TaskBase):
#     _IDENTIFIER = '[A-Za-z_][A-Za-z_0-9]*'
#     _BASE_PROTO_REGEX = (
#         '(?P<prefix>{prefix})' +
#         '(?P<package>' + _IDENTIFIER +
#         '({separator}' + _IDENTIFIER + ')*{package_suffix})'
#         '(?P<suffix>{suffix})')
#     _PACKAGE_REGEX = re.compile(_BASE_PROTO_REGEX.format(
#         prefix='^package ',
#         separator='\\.',
#         package_suffix='',
#         suffix=''))
#     _IMPORT_REGEX = re.compile(_BASE_PROTO_REGEX.format(
#         prefix='^import (?:public )?"',
#         separator='/',
#         package_suffix='\\.proto',
#         suffix='";'))
#     def execute(self, src_proto_path, import_proto_path,
#                 organization_name):
#     def _extract_base_dirs(self, proto_file):
#     def _transform(self, pkg, sep, common_protos):
#     def _copy_proto(self, src, dest, common_protos):
#     def _copy_and_transform_directories(
#             self, src_directories, destination_directory, common_protos,
#             paths=None):
#     def execute(self, grpc_code_dir, gapic_code_dir):
#     def _get_gapic_subdir_path(self, haystack):
#     def _get_proto_path(self, grpc_path):


# Path: test/tasks/test_python_grpc.py
import os
import mock
import pytest
from artman.tasks import python_grpc_tasks

    task = python_grpc_tasks.PythonMoveProtosTask()
    with mock.patch.object(os, 'listdir') as listdir:
        listdir.return_value = ['docs', 'tests', 'other', 'project']
        with mock.patch.object(os, 'walk') as walk:
            walk.side_effect = lambda x: {
                os.path.join('.', 'other'):
                    (('other', [], []),),
                os.path.join('.', 'project'):(
                    ('project', ['v1'], []),
                    ('project/v1', ['gapic'], []),
                    ('project/v1/gapic', [], ['__init__.py']),)
            }[x]
            assert task._get_gapic_subdir_path('.') == 'project/v1'
            # 'tests' and 'docs' directories are skipped.
            assert walk.call_count == 2
            assert walk.mock_calls[0][1] == (os.path.join('.', 'other'),)
            assert walk.mock_calls[1][1] == (os.path.join('.', 'project'),)


def test__get_gapic_subdir_path_not_found():
    task = python_grpc_tasks.PythonMoveProtosTask()
    with mock.patch.object(os, 'walk') as walk:
        walk.return_value = (
            ('foo', ['bar'], []),
        )
        with pytest.raises(RuntimeError):
            task._get_gapic_subdir_path('.')


def test_move_protos():

    task = python_grpc_tasks.PythonMoveProtosTask()