# 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

def test_move_protos():
    task = python_grpc_tasks.PythonMoveProtosTask()
    with mock.patch.object(task, 'exec_command') as exec_command:
        with mock.patch.object(task, '_get_proto_path') as _gpp:
            _gpp.side_effect = ('grpc_path/foo/bar/proto',)
            with mock.patch.object(task, '_get_gapic_subdir_path') as _gsp:
                _gsp.side_effect = (
                    'gapic_path/foo/bar/',
                )
                assert task.execute('grpc_path', 'gapic_path') == {
                    'grpc_code_dir': None,
                }
                # Inspect the calls to _get_proto_path to make sure we are looking
                # for the paths we expect.
                assert _gpp.call_count == 1
                proto_call = _gpp.mock_calls[0]
                assert proto_call[1] == ('grpc_path',)
                # Inspect the calls to _get_gapic_subdir_path to make sure we are looking
                # for the paths we expect.
                assert _gsp.call_count == 1
                gapic_call = _gsp.mock_calls[0]
                assert gapic_call[1] == ('gapic_path',)

        # Ensure that the correct commands ran.
        assert exec_command.call_count == 3
        mv = exec_command.mock_calls[0]
        touch = exec_command.mock_calls[1]
        rm = exec_command.mock_calls[2]
        assert mv[1] == ([

# 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


def test_move_protos():
    task = python_grpc_tasks.PythonMoveProtosTask()
    with mock.patch.object(task, 'exec_command') as exec_command:
        with mock.patch.object(task, '_get_proto_path') as _gpp:
            _gpp.side_effect = ('grpc_path/foo/bar/proto',)
            with mock.patch.object(task, '_get_gapic_subdir_path') as _gsp:
                _gsp.side_effect = (
                    'gapic_path/foo/bar/',
                )
                assert task.execute('grpc_path', 'gapic_path') == {
                    'grpc_code_dir': None,
                }
                # Inspect the calls to _get_proto_path to make sure we are looking
                # for the paths we expect.
                assert _gpp.call_count == 1
                proto_call = _gpp.mock_calls[0]
                assert proto_call[1] == ('grpc_path',)
                # Inspect the calls to _get_gapic_subdir_path to make sure we are looking
                # for the paths we expect.
                assert _gsp.call_count == 1
                gapic_call = _gsp.mock_calls[0]
                assert gapic_call[1] == ('gapic_path',)

        # Ensure that the correct commands ran.
        assert exec_command.call_count == 3
        mv = exec_command.mock_calls[0]
        touch = exec_command.mock_calls[1]
        rm = exec_command.mock_calls[2]
        assert mv[1] == ([

            'mv',