# Copyright 2020 The Cirq Developers
#
# 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
#
#     https://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.
"""Tests for EngineClient."""
import datetime
from unittest import mock
import pytest
from google.api_core import exceptions
from google.protobuf.field_mask_pb2 import FieldMask
from google.protobuf.timestamp_pb2 import Timestamp
from cirq.google.engine.engine_client import EngineClient, EngineException
from cirq.google.engine.client import quantum
from cirq.google.engine.client.quantum_v1alpha1 import enums as qenums
from cirq.google.engine.client.quantum_v1alpha1 import types as qtypes


def setup_mock_(client_constructor):
    grpc_client = mock.Mock()
    client_constructor.return_value = grpc_client
    return grpc_client


@mock.patch.object(quantum, 'QuantumEngineServiceClient', autospec=True)
def test_create_program(client_constructor):
    grpc_client = setup_mock_(client_constructor)

    result = qtypes.QuantumProgram(name='projects/proj/programs/prog')
    grpc_client.create_quantum_program.return_value = result

    code = qtypes.any_pb2.Any()
    labels = {'hello': 'world'}
    client = EngineClient()
    assert client.create_program('proj', 'prog', code, 'A program',
                                 labels) == ('prog', result)
    assert grpc_client.create_quantum_program.call_args[0] == (
        'projects/proj',
        qtypes.QuantumProgram(name='projects/proj/programs/prog',
                              code=code,
                              description='A program',
                              labels=labels), False)

    assert client.create_program('proj', 'prog', code,
                                 'A program') == ('prog', result)
    assert grpc_client.create_quantum_program.call_args[0] == (
        'projects/proj',
        qtypes.QuantumProgram(name='projects/proj/programs/prog',
                              code=code,
                              description='A program'), False)

    assert client.create_program('proj', 'prog', code,
                                 labels=labels) == ('prog', result)
    assert grpc_client.create_quantum_program.call_args[0] == (
        'projects/proj',
        qtypes.QuantumProgram(name='projects/proj/programs/prog',
                              code=code,
                              labels=labels), False)

    assert client.create_program('proj', 'prog', code) == ('prog', result)
    assert grpc_client.create_quantum_program.call_args[0] == (
        'projects/proj',
        qtypes.QuantumProgram(name='projects/proj/programs/prog',
                              code=code), False)

    assert client.create_program('proj', program_id=None,
                                 code=code) == ('prog', result)
    assert grpc_client.create_quantum_program.call_args[0] == (
        'projects/proj', qtypes.QuantumProgram(code=code), False)


@mock.patch.object(quantum, 'QuantumEngineServiceClient', autospec=True)
def test_get_program(client_constructor):
    grpc_client = setup_mock_(client_constructor)

    result = qtypes.QuantumProgram(name='projects/proj/programs/prog')
    grpc_client.get_quantum_program.return_value = result

    client = EngineClient()
    assert client.get_program('proj', 'prog', False) == result
    assert grpc_client.get_quantum_program.call_args[0] == (
        'projects/proj/programs/prog', False)

    assert client.get_program('proj', 'prog', True) == result
    assert grpc_client.get_quantum_program.call_args[0] == (
        'projects/proj/programs/prog', True)


@mock.patch.object(quantum, 'QuantumEngineServiceClient', autospec=True)
def test_list_program(client_constructor):
    grpc_client = setup_mock_(client_constructor)

    results = [
        qtypes.QuantumProgram(name='projects/proj/programs/prog1'),
        qtypes.QuantumProgram(name='projects/proj/programs/prog2')
    ]
    grpc_client.list_quantum_programs.return_value = results

    client = EngineClient()
    assert client.list_programs(project_id='proj') == results
    assert grpc_client.list_quantum_programs.call_args[0] == ('projects/proj',)
    assert grpc_client.list_quantum_programs.call_args[1] == {
        'filter_': '',
    }


# yapf: disable
@pytest.mark.parametrize(
    'expected_filter, created_after, created_before, labels',
    [
        ('',
            None,
            None,
            None),
        ('create_time >= 2020-09-01',
            datetime.date(2020, 9, 1),
            None,
            None),
        ('create_time >= 1598918400',
            datetime.datetime(2020, 9, 1, 0, 0, 0,
                              tzinfo=datetime.timezone.utc),
            None,
            None),
        ('create_time <= 2020-10-01',
            None,
            datetime.date(2020, 10, 1),
            None),
        ('create_time >= 2020-09-01 AND create_time <= 1598918410',
            datetime.date(2020, 9, 1),
            datetime.datetime(2020, 9, 1, 0, 0, 10,
                            tzinfo=datetime.timezone.utc),
            None),
        ('labels.color:red AND labels.shape:*',
            None,
            None,
            {
            'color': 'red',
            'shape': '*'
            },
        ),
        ('create_time >= 2020-08-01 AND '
         'create_time <= 1598918400 AND '
         'labels.color:red AND labels.shape:*',
            datetime.date(2020, 8, 1),
            datetime.datetime(2020, 9, 1, tzinfo=datetime.timezone.utc),
            {
            'color': 'red',
            'shape': '*'
            },
        ),
    ])
# yapf: enable
@mock.patch.object(quantum, 'QuantumEngineServiceClient', autospec=True)
def test_list_program_filters(client_constructor, expected_filter,
                              created_before, created_after, labels):
    grpc_client = setup_mock_(client_constructor)
    client = EngineClient()
    client.list_programs(project_id='proj',
                         created_before=created_before,
                         created_after=created_after,
                         has_labels=labels)
    assert grpc_client.list_quantum_programs.call_args[1] == {
        'filter_': expected_filter,
    }


@mock.patch.object(quantum, 'QuantumEngineServiceClient', autospec=True)
def test_list_program_filters_invalid_type(client_constructor):
    with pytest.raises(ValueError, match=""):
        EngineClient().list_programs(project_id='proj',
                                     created_before="Unsupported date/time")


@mock.patch.object(quantum, 'QuantumEngineServiceClient', autospec=True)
def test_set_program_description(client_constructor):
    grpc_client = setup_mock_(client_constructor)

    result = qtypes.QuantumProgram(name='projects/proj/programs/prog')
    grpc_client.update_quantum_program.return_value = result

    client = EngineClient()
    assert client.set_program_description('proj', 'prog', 'A program') == result
    assert grpc_client.update_quantum_program.call_args[0] == (
        'projects/proj/programs/prog',
        qtypes.QuantumProgram(name='projects/proj/programs/prog',
                              description='A program'),
        qtypes.field_mask_pb2.FieldMask(paths=['description']))

    assert client.set_program_description('proj', 'prog', '') == result
    assert grpc_client.update_quantum_program.call_args[0] == (
        'projects/proj/programs/prog',
        qtypes.QuantumProgram(name='projects/proj/programs/prog'),
        qtypes.field_mask_pb2.FieldMask(paths=['description']))


@mock.patch.object(quantum, 'QuantumEngineServiceClient', autospec=True)
def test_set_program_labels(client_constructor):
    grpc_client = setup_mock_(client_constructor)

    grpc_client.get_quantum_program.return_value = qtypes.QuantumProgram(
        labels={
            'color': 'red',
            'weather': 'sun',
            'run': '1'
        },
        label_fingerprint='hash')
    result = qtypes.QuantumProgram(name='projects/proj/programs/prog')
    grpc_client.update_quantum_program.return_value = result

    client = EngineClient()
    labels = {'hello': 'world', 'color': 'blue', 'run': '1'}
    assert client.set_program_labels('proj', 'prog', labels) == result
    assert grpc_client.update_quantum_program.call_args[0] == (
        'projects/proj/programs/prog',
        qtypes.QuantumProgram(name='projects/proj/programs/prog',
                              labels=labels,
                              label_fingerprint='hash'),
        qtypes.field_mask_pb2.FieldMask(paths=['labels']))

    assert client.set_program_labels('proj', 'prog', {}) == result
    assert grpc_client.update_quantum_program.call_args[0] == (
        'projects/proj/programs/prog',
        qtypes.QuantumProgram(name='projects/proj/programs/prog',
                              label_fingerprint='hash'),
        qtypes.field_mask_pb2.FieldMask(paths=['labels']))


@mock.patch.object(quantum, 'QuantumEngineServiceClient', autospec=True)
def test_add_program_labels(client_constructor):
    grpc_client = setup_mock_(client_constructor)

    existing = qtypes.QuantumProgram(labels={
        'color': 'red',
        'weather': 'sun',
        'run': '1'
    },
                                     label_fingerprint='hash')
    grpc_client.get_quantum_program.return_value = existing
    result = qtypes.QuantumProgram(name='projects/proj/programs/prog')
    grpc_client.update_quantum_program.return_value = result

    client = EngineClient()
    assert client.add_program_labels('proj', 'prog',
                                     {'color': 'red'}) == existing
    assert grpc_client.update_quantum_program.call_count == 0

    assert client.add_program_labels('proj', 'prog',
                                     {'hello': 'world'}) == result
    assert grpc_client.update_quantum_program.call_args[0] == (
        'projects/proj/programs/prog',
        qtypes.QuantumProgram(name='projects/proj/programs/prog',
                              labels={
                                  'color': 'red',
                                  'weather': 'sun',
                                  'run': '1',
                                  'hello': 'world'
                              },
                              label_fingerprint='hash'),
        qtypes.field_mask_pb2.FieldMask(paths=['labels']))

    assert client.add_program_labels('proj', 'prog', {
        'hello': 'world',
        'color': 'blue'
    }) == result
    assert grpc_client.update_quantum_program.call_args[0] == (
        'projects/proj/programs/prog',
        qtypes.QuantumProgram(name='projects/proj/programs/prog',
                              labels={
                                  'color': 'blue',
                                  'weather': 'sun',
                                  'run': '1',
                                  'hello': 'world'
                              },
                              label_fingerprint='hash'),
        qtypes.field_mask_pb2.FieldMask(paths=['labels']))


@mock.patch.object(quantum, 'QuantumEngineServiceClient', autospec=True)
def test_remove_program_labels(client_constructor):
    grpc_client = setup_mock_(client_constructor)

    existing = qtypes.QuantumProgram(labels={
        'color': 'red',
        'weather': 'sun',
        'run': '1'
    },
                                     label_fingerprint='hash')
    grpc_client.get_quantum_program.return_value = existing
    result = qtypes.QuantumProgram(name='projects/proj/programs/prog')
    grpc_client.update_quantum_program.return_value = result

    client = EngineClient()
    assert client.remove_program_labels('proj', 'prog', ['other']) == existing
    assert grpc_client.update_quantum_program.call_count == 0

    assert client.remove_program_labels('proj', 'prog',
                                        ['hello', 'weather']) == result
    assert grpc_client.update_quantum_program.call_args[0] == (
        'projects/proj/programs/prog',
        qtypes.QuantumProgram(name='projects/proj/programs/prog',
                              labels={
                                  'color': 'red',
                                  'run': '1',
                              },
                              label_fingerprint='hash'),
        qtypes.field_mask_pb2.FieldMask(paths=['labels']))

    assert client.remove_program_labels('proj', 'prog',
                                        ['color', 'weather', 'run']) == result
    assert grpc_client.update_quantum_program.call_args[0] == (
        'projects/proj/programs/prog',
        qtypes.QuantumProgram(name='projects/proj/programs/prog',
                              label_fingerprint='hash'),
        qtypes.field_mask_pb2.FieldMask(paths=['labels']))


@mock.patch.object(quantum, 'QuantumEngineServiceClient', autospec=True)
def test_delete_program(client_constructor):
    grpc_client = setup_mock_(client_constructor)

    client = EngineClient()
    assert not client.delete_program('proj', 'prog')
    assert grpc_client.delete_quantum_program.call_args[0] == (
        'projects/proj/programs/prog', False)

    assert not client.delete_program('proj', 'prog', delete_jobs=True)
    assert grpc_client.delete_quantum_program.call_args[0] == (
        'projects/proj/programs/prog', True)


@mock.patch.object(quantum, 'QuantumEngineServiceClient', autospec=True)
def test_create_job(client_constructor):
    grpc_client = setup_mock_(client_constructor)

    result = qtypes.QuantumJob(name='projects/proj/programs/prog/jobs/job0')
    grpc_client.create_quantum_job.return_value = result

    run_context = qtypes.any_pb2.Any()
    labels = {'hello': 'world'}
    client = EngineClient()
    assert client.create_job('proj', 'prog', 'job0', ['processor0'],
                             run_context, 10, 'A job',
                             labels) == ('job0', result)
    assert grpc_client.create_quantum_job.call_args[0] == (
        'projects/proj/programs/prog',
        qtypes.QuantumJob(
            name='projects/proj/programs/prog/jobs/job0',
            run_context=run_context,
            scheduling_config=qtypes.SchedulingConfig(
                priority=10,
                processor_selector=qtypes.SchedulingConfig.ProcessorSelector(
                    processor_names=['projects/proj/processors/processor0'])),
            description='A job',
            labels=labels), False)

    assert client.create_job(
        'proj',
        'prog',
        'job0',
        ['processor0'],
        run_context,
        10,
        'A job',
    ) == ('job0', result)
    assert grpc_client.create_quantum_job.call_args[0] == (
        'projects/proj/programs/prog',
        qtypes.QuantumJob(
            name='projects/proj/programs/prog/jobs/job0',
            run_context=run_context,
            scheduling_config=qtypes.SchedulingConfig(
                priority=10,
                processor_selector=qtypes.SchedulingConfig.ProcessorSelector(
                    processor_names=['projects/proj/processors/processor0'])),
            description='A job'), False)

    assert client.create_job('proj',
                             'prog',
                             'job0', ['processor0'],
                             run_context,
                             10,
                             labels=labels) == ('job0', result)
    assert grpc_client.create_quantum_job.call_args[0] == (
        'projects/proj/programs/prog',
        qtypes.QuantumJob(
            name='projects/proj/programs/prog/jobs/job0',
            run_context=run_context,
            scheduling_config=qtypes.SchedulingConfig(
                priority=10,
                processor_selector=qtypes.SchedulingConfig.ProcessorSelector(
                    processor_names=['projects/proj/processors/processor0'])),
            labels=labels), False)

    assert client.create_job('proj', 'prog', 'job0', ['processor0'],
                             run_context, 10) == ('job0', result)
    assert grpc_client.create_quantum_job.call_args[0] == (
        'projects/proj/programs/prog',
        qtypes.QuantumJob(
            name='projects/proj/programs/prog/jobs/job0',
            run_context=run_context,
            scheduling_config=qtypes.SchedulingConfig(
                priority=10,
                processor_selector=qtypes.SchedulingConfig.ProcessorSelector(
                    processor_names=['projects/proj/processors/processor0'])),
        ), False)

    assert client.create_job('proj',
                             'prog',
                             job_id=None,
                             processor_ids=['processor0'],
                             run_context=run_context,
                             priority=10) == ('job0', result)
    assert grpc_client.create_quantum_job.call_args[0] == (
        'projects/proj/programs/prog',
        qtypes.QuantumJob(
            run_context=run_context,
            scheduling_config=qtypes.SchedulingConfig(
                priority=10,
                processor_selector=qtypes.SchedulingConfig.ProcessorSelector(
                    processor_names=['projects/proj/processors/processor0'])),
        ), False)

    with pytest.raises(ValueError, match='priority must be between 0 and 1000'):
        client.create_job('proj',
                          'prog',
                          job_id=None,
                          processor_ids=['processor0'],
                          run_context=run_context,
                          priority=5000)


@mock.patch.object(quantum, 'QuantumEngineServiceClient', autospec=True)
def test_get_job(client_constructor):
    grpc_client = setup_mock_(client_constructor)

    result = qtypes.QuantumJob(name='projects/proj/programs/prog/jobs/job0')
    grpc_client.get_quantum_job.return_value = result

    client = EngineClient()
    assert client.get_job('proj', 'prog', 'job0', False) == result
    assert grpc_client.get_quantum_job.call_args[0] == (
        'projects/proj/programs/prog/jobs/job0', False)

    assert client.get_job('proj', 'prog', 'job0', True) == result
    assert grpc_client.get_quantum_job.call_args[0] == (
        'projects/proj/programs/prog/jobs/job0', True)


@mock.patch.object(quantum, 'QuantumEngineServiceClient', autospec=True)
def test_set_job_description(client_constructor):
    grpc_client = setup_mock_(client_constructor)

    result = qtypes.QuantumJob(name='projects/proj/programs/prog/jobs/job0')
    grpc_client.update_quantum_job.return_value = result

    client = EngineClient()
    assert client.set_job_description('proj', 'prog', 'job0', 'A job') == result
    assert grpc_client.update_quantum_job.call_args[0] == (
        'projects/proj/programs/prog/jobs/job0',
        qtypes.QuantumJob(name='projects/proj/programs/prog/jobs/job0',
                          description='A job'),
        qtypes.field_mask_pb2.FieldMask(paths=['description']))

    assert client.set_job_description('proj', 'prog', 'job0', '') == result
    assert grpc_client.update_quantum_job.call_args[0] == (
        'projects/proj/programs/prog/jobs/job0',
        qtypes.QuantumJob(name='projects/proj/programs/prog/jobs/job0'),
        qtypes.field_mask_pb2.FieldMask(paths=['description']))


@mock.patch.object(quantum, 'QuantumEngineServiceClient', autospec=True)
def test_set_job_labels(client_constructor):
    grpc_client = setup_mock_(client_constructor)

    grpc_client.get_quantum_job.return_value = qtypes.QuantumJob(
        labels={
            'color': 'red',
            'weather': 'sun',
            'run': '1'
        },
        label_fingerprint='hash')
    result = qtypes.QuantumJob(name='projects/proj/programs/prog/jobs/job0')
    grpc_client.update_quantum_job.return_value = result

    client = EngineClient()
    labels = {'hello': 'world', 'color': 'blue', 'run': '1'}
    assert client.set_job_labels('proj', 'prog', 'job0', labels) == result
    assert grpc_client.update_quantum_job.call_args[0] == (
        'projects/proj/programs/prog/jobs/job0',
        qtypes.QuantumJob(name='projects/proj/programs/prog/jobs/job0',
                          labels=labels,
                          label_fingerprint='hash'),
        qtypes.field_mask_pb2.FieldMask(paths=['labels']))

    assert client.set_job_labels('proj', 'prog', 'job0', {}) == result
    assert grpc_client.update_quantum_job.call_args[0] == (
        'projects/proj/programs/prog/jobs/job0',
        qtypes.QuantumJob(name='projects/proj/programs/prog/jobs/job0',
                          label_fingerprint='hash'),
        qtypes.field_mask_pb2.FieldMask(paths=['labels']))


@mock.patch.object(quantum, 'QuantumEngineServiceClient', autospec=True)
def test_add_job_labels(client_constructor):
    grpc_client = setup_mock_(client_constructor)

    existing = qtypes.QuantumJob(labels={
        'color': 'red',
        'weather': 'sun',
        'run': '1'
    },
                                 label_fingerprint='hash')
    grpc_client.get_quantum_job.return_value = existing
    result = qtypes.QuantumJob(name='projects/proj/programs/prog/jobs/job0')
    grpc_client.update_quantum_job.return_value = result

    client = EngineClient()
    assert client.add_job_labels('proj', 'prog', 'job0',
                                 {'color': 'red'}) == existing
    assert grpc_client.update_quantum_job.call_count == 0

    assert client.add_job_labels('proj', 'prog', 'job0',
                                 {'hello': 'world'}) == result
    assert grpc_client.update_quantum_job.call_args[0] == (
        'projects/proj/programs/prog/jobs/job0',
        qtypes.QuantumJob(name='projects/proj/programs/prog/jobs/job0',
                          labels={
                              'color': 'red',
                              'weather': 'sun',
                              'run': '1',
                              'hello': 'world'
                          },
                          label_fingerprint='hash'),
        qtypes.field_mask_pb2.FieldMask(paths=['labels']))

    assert client.add_job_labels('proj', 'prog', 'job0', {
        'hello': 'world',
        'color': 'blue'
    }) == result
    assert grpc_client.update_quantum_job.call_args[0] == (
        'projects/proj/programs/prog/jobs/job0',
        qtypes.QuantumJob(name='projects/proj/programs/prog/jobs/job0',
                          labels={
                              'color': 'blue',
                              'weather': 'sun',
                              'run': '1',
                              'hello': 'world'
                          },
                          label_fingerprint='hash'),
        qtypes.field_mask_pb2.FieldMask(paths=['labels']))


@mock.patch.object(quantum, 'QuantumEngineServiceClient', autospec=True)
def test_remove_job_labels(client_constructor):
    grpc_client = setup_mock_(client_constructor)

    existing = qtypes.QuantumJob(labels={
        'color': 'red',
        'weather': 'sun',
        'run': '1'
    },
                                 label_fingerprint='hash')
    grpc_client.get_quantum_job.return_value = existing
    result = qtypes.QuantumJob(name='projects/proj/programs/prog/jobs/job0')
    grpc_client.update_quantum_job.return_value = result

    client = EngineClient()
    assert client.remove_job_labels('proj', 'prog', 'job0',
                                    ['other']) == existing
    assert grpc_client.update_quantum_program.call_count == 0

    assert client.remove_job_labels('proj', 'prog', 'job0',
                                    ['hello', 'weather']) == result
    assert grpc_client.update_quantum_job.call_args[0] == (
        'projects/proj/programs/prog/jobs/job0',
        qtypes.QuantumJob(name='projects/proj/programs/prog/jobs/job0',
                          labels={
                              'color': 'red',
                              'run': '1',
                          },
                          label_fingerprint='hash'),
        qtypes.field_mask_pb2.FieldMask(paths=['labels']))

    assert client.remove_job_labels('proj', 'prog', 'job0',
                                    ['color', 'weather', 'run']) == result
    assert grpc_client.update_quantum_job.call_args[0] == (
        'projects/proj/programs/prog/jobs/job0',
        qtypes.QuantumJob(name='projects/proj/programs/prog/jobs/job0',
                          label_fingerprint='hash'),
        qtypes.field_mask_pb2.FieldMask(paths=['labels']))


@mock.patch.object(quantum, 'QuantumEngineServiceClient', autospec=True)
def test_delete_job(client_constructor):
    grpc_client = setup_mock_(client_constructor)

    client = EngineClient()
    assert not client.delete_job('proj', 'prog', 'job0')
    assert grpc_client.delete_quantum_job.call_args[0] == (
        'projects/proj/programs/prog/jobs/job0',)


@mock.patch.object(quantum, 'QuantumEngineServiceClient', autospec=True)
def test_cancel_job(client_constructor):
    grpc_client = setup_mock_(client_constructor)

    client = EngineClient()
    assert not client.cancel_job('proj', 'prog', 'job0')
    assert grpc_client.cancel_quantum_job.call_args[0] == (
        'projects/proj/programs/prog/jobs/job0',)


@mock.patch.object(quantum, 'QuantumEngineServiceClient', autospec=True)
def test_job_results(client_constructor):
    grpc_client = setup_mock_(client_constructor)

    result = qtypes.QuantumResult(
        parent='projects/proj/programs/prog/jobs/job0')
    grpc_client.get_quantum_result.return_value = result

    client = EngineClient()
    assert client.get_job_results('proj', 'prog', 'job0') == result
    assert grpc_client.get_quantum_result.call_args[0] == (
        'projects/proj/programs/prog/jobs/job0',)


@mock.patch.object(quantum, 'QuantumEngineServiceClient', autospec=True)
def test_list_jobs(client_constructor):
    grpc_client = setup_mock_(client_constructor)

    results = [
        qtypes.QuantumJob(name='projects/proj/programs/prog1/jobs/job1'),
        qtypes.QuantumJob(name='projects/proj/programs/prog1/jobs/job2')
    ]
    grpc_client.list_quantum_jobs.return_value = results

    client = EngineClient()
    assert client.list_jobs(project_id='proj', program_id='prog1') == results
    assert grpc_client.list_quantum_jobs.call_args[0] == (
        'projects/proj/programs/prog1',)
    assert grpc_client.list_quantum_jobs.call_args[1] == {
        'filter_': '',
    }

    assert client.list_jobs(project_id='proj') == results
    assert grpc_client.list_quantum_jobs.call_args[0] == (
        'projects/proj/programs/-',)
    assert grpc_client.list_quantum_jobs.call_args[1] == {
        'filter_': '',
    }


# yapf: disable
@pytest.mark.parametrize(
    'expected_filter, '
        'created_after, '
        'created_before, '
        'labels, '
        'execution_states',
    [
        ('',
            None,
            None,
            None,
            None),
        ('create_time >= 2020-09-01',
            datetime.date(2020, 9, 1),
            None,
            None,
            None),
        ('create_time >= 1598918400',
            datetime.datetime(2020, 9, 1, 0, 0, 0,
                              tzinfo=datetime.timezone.utc),
            None,
            None,
            None),
        ('create_time <= 2020-10-01',
            None,
            datetime.date(2020, 10, 1),
            None,
            None),
        ('create_time >= 2020-09-01 AND create_time <= 1598918410',
            datetime.date(2020, 9, 1),
            datetime.datetime(2020, 9, 1, 0, 0, 10,
                            tzinfo=datetime.timezone.utc),
            None,
            None),
        ('labels.color:red AND labels.shape:*',
            None,
            None,
            {
            'color': 'red',
            'shape': '*'
            },
            None
        ),
        ('(execution_status.state = FAILURE OR '
         'execution_status.state = CANCELLED)',
            None,
            None,
            None,
            [quantum.enums.ExecutionStatus.State.FAILURE,
             quantum.enums.ExecutionStatus.State.CANCELLED,]
        ),
        ('create_time >= 2020-08-01 AND '
         'create_time <= 1598918400 AND '
         'labels.color:red AND labels.shape:* AND '
         '(execution_status.state = SUCCESS)',
            datetime.date(2020, 8, 1),
            datetime.datetime(2020, 9, 1, tzinfo=datetime.timezone.utc),
            {
            'color': 'red',
            'shape': '*'
            },
            [quantum.enums.ExecutionStatus.State.SUCCESS,],
        ),
    ])
# yapf: enable
@mock.patch.object(quantum, 'QuantumEngineServiceClient', autospec=True)
def test_list_jobs_filters(client_constructor, expected_filter, created_before,
                           created_after, labels, execution_states):
    grpc_client = setup_mock_(client_constructor)
    client = EngineClient()
    client.list_jobs(project_id='proj',
                     program_id='prog',
                     created_before=created_before,
                     created_after=created_after,
                     has_labels=labels,
                     execution_states=execution_states)
    assert grpc_client.list_quantum_jobs.call_args[1] == {
        'filter_': expected_filter,
    }


@mock.patch.object(quantum, 'QuantumEngineServiceClient', autospec=True)
def test_list_processors(client_constructor):
    grpc_client = setup_mock_(client_constructor)

    results = [
        qtypes.QuantumProcessor(name='projects/proj/processor/processor0'),
        qtypes.QuantumProcessor(name='projects/proj/processor/processor1')
    ]
    grpc_client.list_quantum_processors.return_value = results

    client = EngineClient()
    assert client.list_processors('proj') == results
    assert grpc_client.list_quantum_processors.call_args[0] == (
        'projects/proj',)
    assert grpc_client.list_quantum_processors.call_args[1] == {
        'filter_': '',
    }


@mock.patch.object(quantum, 'QuantumEngineServiceClient', autospec=True)
def test_get_processor(client_constructor):
    grpc_client = setup_mock_(client_constructor)

    result = qtypes.QuantumProcessor(name='projects/proj/processors/processor0')
    grpc_client.get_quantum_processor.return_value = result

    client = EngineClient()
    assert client.get_processor('proj', 'processor0') == result
    assert grpc_client.get_quantum_processor.call_args[0] == (
        'projects/proj/processors/processor0',)


@mock.patch.object(quantum, 'QuantumEngineServiceClient', autospec=True)
def test_list_calibrations(client_constructor):
    grpc_client = setup_mock_(client_constructor)

    results = [
        qtypes.QuantumCalibration(
            name='projects/proj/processor/processor0/calibrations/123456'),
        qtypes.QuantumCalibration(
            name='projects/proj/processor/processor1/calibrations/224466')
    ]
    grpc_client.list_quantum_calibrations.return_value = results

    client = EngineClient()
    assert client.list_calibrations('proj', 'processor0') == results
    assert grpc_client.list_quantum_calibrations.call_args[0] == (
        'projects/proj/processors/processor0',)


@mock.patch.object(quantum, 'QuantumEngineServiceClient', autospec=True)
def test_get_calibration(client_constructor):
    grpc_client = setup_mock_(client_constructor)

    result = qtypes.QuantumCalibration(
        name='projects/proj/processors/processor0/calibrations/123456')
    grpc_client.get_quantum_calibration.return_value = result

    client = EngineClient()
    assert client.get_calibration('proj', 'processor0', 123456) == result
    assert grpc_client.get_quantum_calibration.call_args[0] == (
        'projects/proj/processors/processor0/calibrations/123456',)


@mock.patch.object(quantum, 'QuantumEngineServiceClient', autospec=True)
def test_get_current_calibration(client_constructor):
    grpc_client = setup_mock_(client_constructor)

    result = qtypes.QuantumCalibration(
        name='projects/proj/processors/processor0/calibrations/123456')
    grpc_client.get_quantum_calibration.return_value = result

    client = EngineClient()
    assert client.get_current_calibration('proj', 'processor0') == result
    assert grpc_client.get_quantum_calibration.call_args[0] == (
        'projects/proj/processors/processor0/calibrations/current',)


@mock.patch.object(quantum, 'QuantumEngineServiceClient', autospec=True)
def test_get_current_calibration_does_not_exist(client_constructor):
    grpc_client = setup_mock_(client_constructor)

    grpc_client.get_quantum_calibration.side_effect = exceptions.NotFound(
        'not found')

    client = EngineClient()
    assert client.get_current_calibration('proj', 'processor0') is None
    assert grpc_client.get_quantum_calibration.call_args[0] == (
        'projects/proj/processors/processor0/calibrations/current',)


@mock.patch.object(quantum, 'QuantumEngineServiceClient', autospec=True)
def test_get_current_calibration_error(client_constructor):
    grpc_client = setup_mock_(client_constructor)

    grpc_client.get_quantum_calibration.side_effect = exceptions.BadRequest(
        'boom')

    client = EngineClient()
    with pytest.raises(EngineException, match='boom'):
        client.get_current_calibration('proj', 'processor0')


@mock.patch.object(quantum, 'QuantumEngineServiceClient', autospec=True)
def test_api_doesnt_retry_not_found_errors(client_constructor):
    grpc_client = setup_mock_(client_constructor)
    grpc_client.get_quantum_program.side_effect = exceptions.NotFound(
        'not found')

    client = EngineClient()
    with pytest.raises(EngineException, match='not found'):
        client.get_program('proj', 'prog', False)
    assert grpc_client.get_quantum_program.call_count == 1


@mock.patch.object(quantum, 'QuantumEngineServiceClient', autospec=True)
def test_api_retry_5xx_errors(client_constructor):
    grpc_client = setup_mock_(client_constructor)
    grpc_client.get_quantum_program.side_effect = exceptions.ServiceUnavailable(
        'internal error')

    client = EngineClient(max_retry_delay_seconds=1)
    with pytest.raises(TimeoutError,
                       match='Reached max retry attempts.*internal error'):
        client.get_program('proj', 'prog', False)
    assert grpc_client.get_quantum_program.call_count > 1


@mock.patch.object(quantum, 'QuantumEngineServiceClient', autospec=True)
def test_create_reservation(client_constructor):
    grpc_client = setup_mock_(client_constructor)
    start = datetime.datetime.fromtimestamp(1000000000)
    end = datetime.datetime.fromtimestamp(1000003600)
    users = ['jeff@google.com']
    result = qtypes.QuantumReservation(
        name='projects/proj/processors/processor0/reservations/papar-party-44',
        start_time=Timestamp(seconds=1000000000),
        end_time=Timestamp(seconds=1000003600),
        whitelisted_users=users,
    )
    grpc_client.create_quantum_reservation.return_value = result

    client = EngineClient()
    assert client.create_reservation('proj', 'processor0', start, end,
                                     users) == result
    assert grpc_client.create_quantum_reservation.call_count == 1
    kwargs = grpc_client.create_quantum_reservation.call_args[1]
    # The outgoing argument will not have the resource name
    result.name = ''
    assert kwargs == {
        'parent': 'projects/proj/processors/processor0',
        'quantum_reservation': result
    }


@mock.patch.object(quantum, 'QuantumEngineServiceClient', autospec=True)
def test_cancel_reservation(client_constructor):
    grpc_client = setup_mock_(client_constructor)
    name = 'projects/proj/processors/processor0/reservations/papar-party-44'
    result = qtypes.QuantumReservation(
        name=name,
        start_time=Timestamp(seconds=1000000000),
        end_time=Timestamp(seconds=1000002000),
        whitelisted_users=['jeff@google.com'],
    )
    grpc_client.cancel_quantum_reservation.return_value = result

    client = EngineClient()
    assert (client.cancel_reservation('proj', 'processor0',
                                      'papar-party-44') == result)
    kwargs = grpc_client.cancel_quantum_reservation.call_args[1]
    assert kwargs == {
        'name': name,
    }


@mock.patch.object(quantum, 'QuantumEngineServiceClient', autospec=True)
def test_delete_reservation(client_constructor):
    grpc_client = setup_mock_(client_constructor)
    name = 'projects/proj/processors/processor0/reservations/papar-party-44'
    result = qtypes.QuantumReservation(
        name=name,
        start_time=Timestamp(seconds=1000000000),
        end_time=Timestamp(seconds=1000002000),
        whitelisted_users=['jeff@google.com'],
    )
    grpc_client.delete_quantum_reservation.return_value = result

    client = EngineClient()
    assert (client.delete_reservation('proj', 'processor0',
                                      'papar-party-44') == result)
    kwargs = grpc_client.delete_quantum_reservation.call_args[1]
    assert kwargs == {
        'name': name,
    }


@mock.patch.object(quantum, 'QuantumEngineServiceClient', autospec=True)
def test_get_reservation(client_constructor):
    grpc_client = setup_mock_(client_constructor)
    name = 'projects/proj/processors/processor0/reservations/papar-party-44'
    result = qtypes.QuantumReservation(
        name=name,
        start_time=Timestamp(seconds=1000000000),
        end_time=Timestamp(seconds=1000002000),
        whitelisted_users=['jeff@google.com'],
    )
    grpc_client.get_quantum_reservation.return_value = result

    client = EngineClient()
    assert (client.get_reservation('proj', 'processor0',
                                   'papar-party-44') == result)
    kwargs = grpc_client.get_quantum_reservation.call_args[1]
    assert kwargs == {
        'name': name,
    }


@mock.patch.object(quantum, 'QuantumEngineServiceClient', autospec=True)
def test_get_reservation_not_found(client_constructor):
    grpc_client = setup_mock_(client_constructor)
    name = 'projects/proj/processors/processor0/reservations/papar-party-44'
    grpc_client.get_quantum_reservation.side_effect = exceptions.NotFound(
        'not found')

    client = EngineClient()
    assert (client.get_reservation('proj', 'processor0',
                                   'papar-party-44') == None)
    kwargs = grpc_client.get_quantum_reservation.call_args[1]
    assert kwargs == {
        'name': name,
    }


@mock.patch.object(quantum, 'QuantumEngineServiceClient', autospec=True)
def test_get_reservation_exception(client_constructor):
    grpc_client = setup_mock_(client_constructor)
    grpc_client.get_quantum_reservation.side_effect = exceptions.BadRequest(
        'boom')

    client = EngineClient()
    with pytest.raises(EngineException, match='boom'):
        client.get_reservation('proj', 'processor0', 'goog')


@mock.patch.object(quantum, 'QuantumEngineServiceClient', autospec=True)
def test_list_reservation(client_constructor):
    grpc_client = setup_mock_(client_constructor)
    name = 'projects/proj/processors/processor0/reservations/papar-party-44'
    results = [
        qtypes.QuantumReservation(
            name=name,
            start_time=Timestamp(seconds=1000000000),
            end_time=Timestamp(seconds=1000002000),
            whitelisted_users=['jeff@google.com'],
        ),
        qtypes.QuantumReservation(
            name=name,
            start_time=Timestamp(seconds=1200000000),
            end_time=Timestamp(seconds=1200002000),
            whitelisted_users=['dstrain@google.com'],
        ),
    ]
    grpc_client.list_quantum_reservations.return_value = results

    client = EngineClient()
    assert (client.list_reservations('proj', 'processor0') == results)


@mock.patch.object(quantum, 'QuantumEngineServiceClient', autospec=True)
def test_update_reservation(client_constructor):
    grpc_client = setup_mock_(client_constructor)
    name = 'projects/proj/processors/processor0/reservations/papar-party-44'
    result = qtypes.QuantumReservation(
        name=name,
        start_time=Timestamp(seconds=1000001000),
        end_time=Timestamp(seconds=1000002000),
        whitelisted_users=['jeff@google.com'],
    )
    grpc_client.update_quantum_reservation.return_value = result

    client = EngineClient()
    assert (client.update_reservation(
        'proj',
        'processor0',
        'papar-party-44',
        start=datetime.datetime.fromtimestamp(1000001000),
        end=datetime.datetime.fromtimestamp(1000002000),
        whitelisted_users=['jeff@google.com'],
    ) == result)
    kwargs = grpc_client.update_quantum_reservation.call_args[1]
    assert kwargs == {
        'name':
        name,
        'quantum_reservation':
        result,
        'update_mask':
        FieldMask(paths=['start_time', 'end_time', 'whitelisted_users'])
    }


@mock.patch.object(quantum, 'QuantumEngineServiceClient', autospec=True)
def test_update_reservation_remove_all_users(client_constructor):
    grpc_client = setup_mock_(client_constructor)
    name = 'projects/proj/processors/processor0/reservations/papar-party-44'
    result = qtypes.QuantumReservation(
        name=name,
        whitelisted_users=[],
    )
    grpc_client.update_quantum_reservation.return_value = result

    client = EngineClient()
    assert (client.update_reservation(
        'proj',
        'processor0',
        'papar-party-44',
        whitelisted_users=[],
    ) == result)
    kwargs = grpc_client.update_quantum_reservation.call_args[1]
    assert kwargs == {
        'name': name,
        'quantum_reservation': result,
        'update_mask': FieldMask(paths=['whitelisted_users'])
    }


@mock.patch.object(quantum, 'QuantumEngineServiceClient', autospec=True)
def test_list_time_slots(client_constructor):
    grpc_client = setup_mock_(client_constructor)
    results = [
        qtypes.QuantumTimeSlot(
            processor_name='potofgold',
            start_time=Timestamp(seconds=1000020000),
            end_time=Timestamp(seconds=1000040000),
            slot_type=qenums.QuantumTimeSlot.TimeSlotType.MAINTENANCE,
            maintenance_config=qtypes.QuantumTimeSlot.MaintenanceConfig(
                title='Testing',
                description='Testing some new configuration.',
            ),
        ),
        qtypes.QuantumTimeSlot(
            processor_name='potofgold',
            start_time=Timestamp(seconds=1000010000),
            end_time=Timestamp(seconds=1000020000),
            slot_type=qenums.QuantumTimeSlot.TimeSlotType.RESERVATION,
            reservation_config=qtypes.QuantumTimeSlot.ReservationConfig(
                project_id='super_secret_quantum'),
        )
    ]
    grpc_client.list_quantum_time_slots.return_value = results

    client = EngineClient()
    assert (client.list_time_slots('proj', 'processor0') == results)

[(33, 'unittest.mock.patch.object', 'mock.patch.object', (['quantum', '"""QuantumEngineServiceClient"""'], {'autospec': '(True)'}), False, 'from unittest import mock\n'), (80, 'unittest.mock.patch.object', 'mock.patch.object', (['quantum', '"""QuantumEngineServiceClient"""'], {'autospec': '(True)'}), False, 'from unittest import mock\n'), (97, 'unittest.mock.patch.object', 'mock.patch.object', (['quantum', '"""QuantumEngineServiceClient"""'], {'autospec': '(True)'}), False, 'from unittest import mock\n'), (161, 'unittest.mock.patch.object', 'mock.patch.object', (['quantum', '"""QuantumEngineServiceClient"""'], {'autospec': '(True)'}), False, 'from unittest import mock\n'), (175, 'unittest.mock.patch.object', 'mock.patch.object', (['quantum', '"""QuantumEngineServiceClient"""'], {'autospec': '(True)'}), False, 'from unittest import mock\n'), (182, 'unittest.mock.patch.object', 'mock.patch.object', (['quantum', '"""QuantumEngineServiceClient"""'], {'autospec': '(True)'}), False, 'from unittest import mock\n'), (204, 'unittest.mock.patch.object', 'mock.patch.object', (['quantum', '"""QuantumEngineServiceClient"""'], {'autospec': '(True)'}), False, 'from unittest import mock\n'), (236, 'unittest.mock.patch.object', 'mock.patch.object', (['quantum', '"""QuantumEngineServiceClient"""'], {'autospec': '(True)'}), False, 'from unittest import mock\n'), (286, 'unittest.mock.patch.object', 'mock.patch.object', (['quantum', '"""QuantumEngineServiceClient"""'], {'autospec': '(True)'}), False, 'from unittest import mock\n'), (325, 'unittest.mock.patch.object', 'mock.patch.object', (['quantum', '"""QuantumEngineServiceClient"""'], {'autospec': '(True)'}), False, 'from unittest import mock\n'), (339, 'unittest.mock.patch.object', 'mock.patch.object', (['quantum', '"""QuantumEngineServiceClient"""'], {'autospec': '(True)'}), False, 'from unittest import mock\n'), (439, 'unittest.mock.patch.object', 'mock.patch.object', (['quantum', '"""QuantumEngineServiceClient"""'], {'autospec': '(True)'}), False, 'from unittest import mock\n'), (456, 'unittest.mock.patch.object', 'mock.patch.object', (['quantum', '"""QuantumEngineServiceClient"""'], {'autospec': '(True)'}), False, 'from unittest import mock\n'), (478, 'unittest.mock.patch.object', 'mock.patch.object', (['quantum', '"""QuantumEngineServiceClient"""'], {'autospec': '(True)'}), False, 'from unittest import mock\n'), (510, 'unittest.mock.patch.object', 'mock.patch.object', (['quantum', '"""QuantumEngineServiceClient"""'], {'autospec': '(True)'}), False, 'from unittest import mock\n'), (560, 'unittest.mock.patch.object', 'mock.patch.object', (['quantum', '"""QuantumEngineServiceClient"""'], {'autospec': '(True)'}), False, 'from unittest import mock\n'), (600, 'unittest.mock.patch.object', 'mock.patch.object', (['quantum', '"""QuantumEngineServiceClient"""'], {'autospec': '(True)'}), False, 'from unittest import mock\n'), (610, 'unittest.mock.patch.object', 'mock.patch.object', (['quantum', '"""QuantumEngineServiceClient"""'], {'autospec': '(True)'}), False, 'from unittest import mock\n'), (620, 'unittest.mock.patch.object', 'mock.patch.object', (['quantum', '"""QuantumEngineServiceClient"""'], {'autospec': '(True)'}), False, 'from unittest import mock\n'), (634, 'unittest.mock.patch.object', 'mock.patch.object', (['quantum', '"""QuantumEngineServiceClient"""'], {'autospec': '(True)'}), False, 'from unittest import mock\n'), (726, 'unittest.mock.patch.object', 'mock.patch.object', (['quantum', '"""QuantumEngineServiceClient"""'], {'autospec': '(True)'}), False, 'from unittest import mock\n'), (742, 'unittest.mock.patch.object', 'mock.patch.object', (['quantum', '"""QuantumEngineServiceClient"""'], {'autospec': '(True)'}), False, 'from unittest import mock\n'), (761, 'unittest.mock.patch.object', 'mock.patch.object', (['quantum', '"""QuantumEngineServiceClient"""'], {'autospec': '(True)'}), False, 'from unittest import mock\n'), (774, 'unittest.mock.patch.object', 'mock.patch.object', (['quantum', '"""QuantumEngineServiceClient"""'], {'autospec': '(True)'}), False, 'from unittest import mock\n'), (792, 'unittest.mock.patch.object', 'mock.patch.object', (['quantum', '"""QuantumEngineServiceClient"""'], {'autospec': '(True)'}), False, 'from unittest import mock\n'), (806, 'unittest.mock.patch.object', 'mock.patch.object', (['quantum', '"""QuantumEngineServiceClient"""'], {'autospec': '(True)'}), False, 'from unittest import mock\n'), (820, 'unittest.mock.patch.object', 'mock.patch.object', (['quantum', '"""QuantumEngineServiceClient"""'], {'autospec': '(True)'}), False, 'from unittest import mock\n'), (833, 'unittest.mock.patch.object', 'mock.patch.object', (['quantum', '"""QuantumEngineServiceClient"""'], {'autospec': '(True)'}), False, 'from unittest import mock\n'), (845, 'unittest.mock.patch.object', 'mock.patch.object', (['quantum', '"""QuantumEngineServiceClient"""'], {'autospec': '(True)'}), False, 'from unittest import mock\n'), (857, 'unittest.mock.patch.object', 'mock.patch.object', (['quantum', '"""QuantumEngineServiceClient"""'], {'autospec': '(True)'}), False, 'from unittest import mock\n'), (870, 'unittest.mock.patch.object', 'mock.patch.object', (['quantum', '"""QuantumEngineServiceClient"""'], {'autospec': '(True)'}), False, 'from unittest import mock\n'), (897, 'unittest.mock.patch.object', 'mock.patch.object', (['quantum', '"""QuantumEngineServiceClient"""'], {'autospec': '(True)'}), False, 'from unittest import mock\n'), (918, 'unittest.mock.patch.object', 'mock.patch.object', (['quantum', '"""QuantumEngineServiceClient"""'], {'autospec': '(True)'}), False, 'from unittest import mock\n'), (939, 'unittest.mock.patch.object', 'mock.patch.object', (['quantum', '"""QuantumEngineServiceClient"""'], {'autospec': '(True)'}), False, 'from unittest import mock\n'), (960, 'unittest.mock.patch.object', 'mock.patch.object', (['quantum', '"""QuantumEngineServiceClient"""'], {'autospec': '(True)'}), False, 'from unittest import mock\n'), (976, 'unittest.mock.patch.object', 'mock.patch.object', (['quantum', '"""QuantumEngineServiceClient"""'], {'autospec': '(True)'}), False, 'from unittest import mock\n'), (987, 'unittest.mock.patch.object', 'mock.patch.object', (['quantum', '"""QuantumEngineServiceClient"""'], {'autospec': '(True)'}), False, 'from unittest import mock\n'), (1011, 'unittest.mock.patch.object', 'mock.patch.object', (['quantum', '"""QuantumEngineServiceClient"""'], {'autospec': '(True)'}), False, 'from unittest import mock\n'), (1043, 'unittest.mock.patch.object', 'mock.patch.object', (['quantum', '"""QuantumEngineServiceClient"""'], {'autospec': '(True)'}), False, 'from unittest import mock\n'), (1068, 'unittest.mock.patch.object', 'mock.patch.object', (['quantum', '"""QuantumEngineServiceClient"""'], {'autospec': '(True)'}), False, 'from unittest import mock\n'), (28, 'unittest.mock.Mock', 'mock.Mock', ([], {}), False, 'from unittest import mock\n'), (37, 'cirq.google.engine.client.quantum_v1alpha1.types.QuantumProgram', 'qtypes.QuantumProgram', ([], {'name': '"""projects/proj/programs/prog"""'}), True, 'from cirq.google.engine.client.quantum_v1alpha1 import types as qtypes\n'), (40, 'cirq.google.engine.client.quantum_v1alpha1.types.any_pb2.Any', 'qtypes.any_pb2.Any', ([], {}), True, 'from cirq.google.engine.client.quantum_v1alpha1 import types as qtypes\n'), (42, 'cirq.google.engine.engine_client.EngineClient', 'EngineClient', ([], {}), False, 'from cirq.google.engine.engine_client import EngineClient, EngineException\n'), (84, 'cirq.google.engine.client.quantum_v1alpha1.types.QuantumProgram', 'qtypes.QuantumProgram', ([], {'name': '"""projects/proj/programs/prog"""'}), True, 'from cirq.google.engine.client.quantum_v1alpha1 import types as qtypes\n'), (87, 'cirq.google.engine.engine_client.EngineClient', 'EngineClient', ([], {}), False, 'from cirq.google.engine.engine_client import EngineClient, EngineException\n'), (107, 'cirq.google.engine.engine_client.EngineClient', 'EngineClient', ([], {}), False, 'from cirq.google.engine.engine_client import EngineClient, EngineException\n'), (165, 'cirq.google.engine.engine_client.EngineClient', 'EngineClient', ([], {}), False, 'from cirq.google.engine.engine_client import EngineClient, EngineException\n'), (186, 'cirq.google.engine.client.quantum_v1alpha1.types.QuantumProgram', 'qtypes.QuantumProgram', ([], {'name': '"""projects/proj/programs/prog"""'}), True, 'from cirq.google.engine.client.quantum_v1alpha1 import types as qtypes\n'), (189, 'cirq.google.engine.engine_client.EngineClient', 'EngineClient', ([], {}), False, 'from cirq.google.engine.engine_client import EngineClient, EngineException\n'), (208, 'cirq.google.engine.client.quantum_v1alpha1.types.QuantumProgram', 'qtypes.QuantumProgram', ([], {'labels': "{'color': 'red', 'weather': 'sun', 'run': '1'}", 'label_fingerprint': '"""hash"""'}), True, 'from cirq.google.engine.client.quantum_v1alpha1 import types as qtypes\n'), (215, 'cirq.google.engine.client.quantum_v1alpha1.types.QuantumProgram', 'qtypes.QuantumProgram', ([], {'name': '"""projects/proj/programs/prog"""'}), True, 'from cirq.google.engine.client.quantum_v1alpha1 import types as qtypes\n'), (218, 'cirq.google.engine.engine_client.EngineClient', 'EngineClient', ([], {}), False, 'from cirq.google.engine.engine_client import EngineClient, EngineException\n'), (240, 'cirq.google.engine.client.quantum_v1alpha1.types.QuantumProgram', 'qtypes.QuantumProgram', ([], {'labels': "{'color': 'red', 'weather': 'sun', 'run': '1'}", 'label_fingerprint': '"""hash"""'}), True, 'from cirq.google.engine.client.quantum_v1alpha1 import types as qtypes\n'), (247, 'cirq.google.engine.client.quantum_v1alpha1.types.QuantumProgram', 'qtypes.QuantumProgram', ([], {'name': '"""projects/proj/programs/prog"""'}), True, 'from cirq.google.engine.client.quantum_v1alpha1 import types as qtypes\n'), (250, 'cirq.google.engine.engine_client.EngineClient', 'EngineClient', ([], {}), False, 'from cirq.google.engine.engine_client import EngineClient, EngineException\n'), (290, 'cirq.google.engine.client.quantum_v1alpha1.types.QuantumProgram', 'qtypes.QuantumProgram', ([], {'labels': "{'color': 'red', 'weather': 'sun', 'run': '1'}", 'label_fingerprint': '"""hash"""'}), True, 'from cirq.google.engine.client.quantum_v1alpha1 import types as qtypes\n'), (297, 'cirq.google.engine.client.quantum_v1alpha1.types.QuantumProgram', 'qtypes.QuantumProgram', ([], {'name': '"""projects/proj/programs/prog"""'}), True, 'from cirq.google.engine.client.quantum_v1alpha1 import types as qtypes\n'), (300, 'cirq.google.engine.engine_client.EngineClient', 'EngineClient', ([], {}), False, 'from cirq.google.engine.engine_client import EngineClient, EngineException\n'), (329, 'cirq.google.engine.engine_client.EngineClient', 'EngineClient', ([], {}), False, 'from cirq.google.engine.engine_client import EngineClient, EngineException\n'), (343, 'cirq.google.engine.client.quantum_v1alpha1.types.QuantumJob', 'qtypes.QuantumJob', ([], {'name': '"""projects/proj/programs/prog/jobs/job0"""'}), True, 'from cirq.google.engine.client.quantum_v1alpha1 import types as qtypes\n'), (346, 'cirq.google.engine.client.quantum_v1alpha1.types.any_pb2.Any', 'qtypes.any_pb2.Any', ([], {}), True, 'from cirq.google.engine.client.quantum_v1alpha1 import types as qtypes\n'), (348, 'cirq.google.engine.engine_client.EngineClient', 'EngineClient', ([], {}), False, 'from cirq.google.engine.engine_client import EngineClient, EngineException\n'), (443, 'cirq.google.engine.client.quantum_v1alpha1.types.QuantumJob', 'qtypes.QuantumJob', ([], {'name': '"""projects/proj/programs/prog/jobs/job0"""'}), True, 'from cirq.google.engine.client.quantum_v1alpha1 import types as qtypes\n'), (446, 'cirq.google.engine.engine_client.EngineClient', 'EngineClient', ([], {}), False, 'from cirq.google.engine.engine_client import EngineClient, EngineException\n'), (460, 'cirq.google.engine.client.quantum_v1alpha1.types.QuantumJob', 'qtypes.QuantumJob', ([], {'name': '"""projects/proj/programs/prog/jobs/job0"""'}), True, 'from cirq.google.engine.client.quantum_v1alpha1 import types as qtypes\n'), (463, 'cirq.google.engine.engine_client.EngineClient', 'EngineClient', ([], {}), False, 'from cirq.google.engine.engine_client import EngineClient, EngineException\n'), (482, 'cirq.google.engine.client.quantum_v1alpha1.types.QuantumJob', 'qtypes.QuantumJob', ([], {'labels': "{'color': 'red', 'weather': 'sun', 'run': '1'}", 'label_fingerprint': '"""hash"""'}), True, 'from cirq.google.engine.client.quantum_v1alpha1 import types as qtypes\n'), (489, 'cirq.google.engine.client.quantum_v1alpha1.types.QuantumJob', 'qtypes.QuantumJob', ([], {'name': '"""projects/proj/programs/prog/jobs/job0"""'}), True, 'from cirq.google.engine.client.quantum_v1alpha1 import types as qtypes\n'), (492, 'cirq.google.engine.engine_client.EngineClient', 'EngineClient', ([], {}), False, 'from cirq.google.engine.engine_client import EngineClient, EngineException\n'), (514, 'cirq.google.engine.client.quantum_v1alpha1.types.QuantumJob', 'qtypes.QuantumJob', ([], {'labels': "{'color': 'red', 'weather': 'sun', 'run': '1'}", 'label_fingerprint': '"""hash"""'}), True, 'from cirq.google.engine.client.quantum_v1alpha1 import types as qtypes\n'), (521, 'cirq.google.engine.client.quantum_v1alpha1.types.QuantumJob', 'qtypes.QuantumJob', ([], {'name': '"""projects/proj/programs/prog/jobs/job0"""'}), True, 'from cirq.google.engine.client.quantum_v1alpha1 import types as qtypes\n'), (524, 'cirq.google.engine.engine_client.EngineClient', 'EngineClient', ([], {}), False, 'from cirq.google.engine.engine_client import EngineClient, EngineException\n'), (564, 'cirq.google.engine.client.quantum_v1alpha1.types.QuantumJob', 'qtypes.QuantumJob', ([], {'labels': "{'color': 'red', 'weather': 'sun', 'run': '1'}", 'label_fingerprint': '"""hash"""'}), True, 'from cirq.google.engine.client.quantum_v1alpha1 import types as qtypes\n'), (571, 'cirq.google.engine.client.quantum_v1alpha1.types.QuantumJob', 'qtypes.QuantumJob', ([], {'name': '"""projects/proj/programs/prog/jobs/job0"""'}), True, 'from cirq.google.engine.client.quantum_v1alpha1 import types as qtypes\n'), (574, 'cirq.google.engine.engine_client.EngineClient', 'EngineClient', ([], {}), False, 'from cirq.google.engine.engine_client import EngineClient, EngineException\n'), (604, 'cirq.google.engine.engine_client.EngineClient', 'EngineClient', ([], {}), False, 'from cirq.google.engine.engine_client import EngineClient, EngineException\n'), (614, 'cirq.google.engine.engine_client.EngineClient', 'EngineClient', ([], {}), False, 'from cirq.google.engine.engine_client import EngineClient, EngineException\n'), (624, 'cirq.google.engine.client.quantum_v1alpha1.types.QuantumResult', 'qtypes.QuantumResult', ([], {'parent': '"""projects/proj/programs/prog/jobs/job0"""'}), True, 'from cirq.google.engine.client.quantum_v1alpha1 import types as qtypes\n'), (628, 'cirq.google.engine.engine_client.EngineClient', 'EngineClient', ([], {}), False, 'from cirq.google.engine.engine_client import EngineClient, EngineException\n'), (644, 'cirq.google.engine.engine_client.EngineClient', 'EngineClient', ([], {}), False, 'from cirq.google.engine.engine_client import EngineClient, EngineException\n'), (730, 'cirq.google.engine.engine_client.EngineClient', 'EngineClient', ([], {}), False, 'from cirq.google.engine.engine_client import EngineClient, EngineException\n'), (752, 'cirq.google.engine.engine_client.EngineClient', 'EngineClient', ([], {}), False, 'from cirq.google.engine.engine_client import EngineClient, EngineException\n'), (765, 'cirq.google.engine.client.quantum_v1alpha1.types.QuantumProcessor', 'qtypes.QuantumProcessor', ([], {'name': '"""projects/proj/processors/processor0"""'}), True, 'from cirq.google.engine.client.quantum_v1alpha1 import types as qtypes\n'), (768, 'cirq.google.engine.engine_client.EngineClient', 'EngineClient', ([], {}), False, 'from cirq.google.engine.engine_client import EngineClient, EngineException\n'), (786, 'cirq.google.engine.engine_client.EngineClient', 'EngineClient', ([], {}), False, 'from cirq.google.engine.engine_client import EngineClient, EngineException\n'), (796, 'cirq.google.engine.client.quantum_v1alpha1.types.QuantumCalibration', 'qtypes.QuantumCalibration', ([], {'name': '"""projects/proj/processors/processor0/calibrations/123456"""'}), True, 'from cirq.google.engine.client.quantum_v1alpha1 import types as qtypes\n'), (800, 'cirq.google.engine.engine_client.EngineClient', 'EngineClient', ([], {}), False, 'from cirq.google.engine.engine_client import EngineClient, EngineException\n'), (810, 'cirq.google.engine.client.quantum_v1alpha1.types.QuantumCalibration', 'qtypes.QuantumCalibration', ([], {'name': '"""projects/proj/processors/processor0/calibrations/123456"""'}), True, 'from cirq.google.engine.client.quantum_v1alpha1 import types as qtypes\n'), (814, 'cirq.google.engine.engine_client.EngineClient', 'EngineClient', ([], {}), False, 'from cirq.google.engine.engine_client import EngineClient, EngineException\n'), (824, 'google.api_core.exceptions.NotFound', 'exceptions.NotFound', (['"""not found"""'], {}), False, 'from google.api_core import exceptions\n'), (827, 'cirq.google.engine.engine_client.EngineClient', 'EngineClient', ([], {}), False, 'from cirq.google.engine.engine_client import EngineClient, EngineException\n'), (837, 'google.api_core.exceptions.BadRequest', 'exceptions.BadRequest', (['"""boom"""'], {}), False, 'from google.api_core import exceptions\n'), (840, 'cirq.google.engine.engine_client.EngineClient', 'EngineClient', ([], {}), False, 'from cirq.google.engine.engine_client import EngineClient, EngineException\n'), (848, 'google.api_core.exceptions.NotFound', 'exceptions.NotFound', (['"""not found"""'], {}), False, 'from google.api_core import exceptions\n'), (851, 'cirq.google.engine.engine_client.EngineClient', 'EngineClient', ([], {}), False, 'from cirq.google.engine.engine_client import EngineClient, EngineException\n'), (860, 'google.api_core.exceptions.ServiceUnavailable', 'exceptions.ServiceUnavailable', (['"""internal error"""'], {}), False, 'from google.api_core import exceptions\n'), (863, 'cirq.google.engine.engine_client.EngineClient', 'EngineClient', ([], {'max_retry_delay_seconds': '(1)'}), False, 'from cirq.google.engine.engine_client import EngineClient, EngineException\n'), (873, 'datetime.datetime.fromtimestamp', 'datetime.datetime.fromtimestamp', (['(1000000000)'], {}), False, 'import datetime\n'), (874, 'datetime.datetime.fromtimestamp', 'datetime.datetime.fromtimestamp', (['(1000003600)'], {}), False, 'import datetime\n'), (884, 'cirq.google.engine.engine_client.EngineClient', 'EngineClient', ([], {}), False, 'from cirq.google.engine.engine_client import EngineClient, EngineException\n'), (909, 'cirq.google.engine.engine_client.EngineClient', 'EngineClient', ([], {}), False, 'from cirq.google.engine.engine_client import EngineClient, EngineException\n'), (930, 'cirq.google.engine.engine_client.EngineClient', 'EngineClient', ([], {}), False, 'from cirq.google.engine.engine_client import EngineClient, EngineException\n'), (951, 'cirq.google.engine.engine_client.EngineClient', 'EngineClient', ([], {}), False, 'from cirq.google.engine.engine_client import EngineClient, EngineException\n'), (964, 'google.api_core.exceptions.NotFound', 'exceptions.NotFound', (['"""not found"""'], {}), False, 'from google.api_core import exceptions\n'), (967, 'cirq.google.engine.engine_client.EngineClient', 'EngineClient', ([], {}), False, 'from cirq.google.engine.engine_client import EngineClient, EngineException\n'), (979, 'google.api_core.exceptions.BadRequest', 'exceptions.BadRequest', (['"""boom"""'], {}), False, 'from google.api_core import exceptions\n'), (982, 'cirq.google.engine.engine_client.EngineClient', 'EngineClient', ([], {}), False, 'from cirq.google.engine.engine_client import EngineClient, EngineException\n'), (1007, 'cirq.google.engine.engine_client.EngineClient', 'EngineClient', ([], {}), False, 'from cirq.google.engine.engine_client import EngineClient, EngineException\n'), (1023, 'cirq.google.engine.engine_client.EngineClient', 'EngineClient', ([], {}), False, 'from cirq.google.engine.engine_client import EngineClient, EngineException\n'), (1047, 'cirq.google.engine.client.quantum_v1alpha1.types.QuantumReservation', 'qtypes.QuantumReservation', ([], {'name': 'name', 'whitelisted_users': '[]'}), True, 'from cirq.google.engine.client.quantum_v1alpha1 import types as qtypes\n'), (1053, 'cirq.google.engine.engine_client.EngineClient', 'EngineClient', ([], {}), False, 'from cirq.google.engine.engine_client import EngineClient, EngineException\n'), (1093, 'cirq.google.engine.engine_client.EngineClient', 'EngineClient', ([], {}), False, 'from cirq.google.engine.engine_client import EngineClient, EngineException\n'), (102, 'cirq.google.engine.client.quantum_v1alpha1.types.QuantumProgram', 'qtypes.QuantumProgram', ([], {'name': '"""projects/proj/programs/prog1"""'}), True, 'from cirq.google.engine.client.quantum_v1alpha1 import types as qtypes\n'), (103, 'cirq.google.engine.client.quantum_v1alpha1.types.QuantumProgram', 'qtypes.QuantumProgram', ([], {'name': '"""projects/proj/programs/prog2"""'}), True, 'from cirq.google.engine.client.quantum_v1alpha1 import types as qtypes\n'), (177, 'pytest.raises', 'pytest.raises', (['ValueError'], {'match': '""""""'}), False, 'import pytest\n'), (430, 'pytest.raises', 'pytest.raises', (['ValueError'], {'match': '"""priority must be between 0 and 1000"""'}), False, 'import pytest\n'), (639, 'cirq.google.engine.client.quantum_v1alpha1.types.QuantumJob', 'qtypes.QuantumJob', ([], {'name': '"""projects/proj/programs/prog1/jobs/job1"""'}), True, 'from cirq.google.engine.client.quantum_v1alpha1 import types as qtypes\n'), (640, 'cirq.google.engine.client.quantum_v1alpha1.types.QuantumJob', 'qtypes.QuantumJob', ([], {'name': '"""projects/proj/programs/prog1/jobs/job2"""'}), True, 'from cirq.google.engine.client.quantum_v1alpha1 import types as qtypes\n'), (747, 'cirq.google.engine.client.quantum_v1alpha1.types.QuantumProcessor', 'qtypes.QuantumProcessor', ([], {'name': '"""projects/proj/processor/processor0"""'}), True, 'from cirq.google.engine.client.quantum_v1alpha1 import types as qtypes\n'), (748, 'cirq.google.engine.client.quantum_v1alpha1.types.QuantumProcessor', 'qtypes.QuantumProcessor', ([], {'name': '"""projects/proj/processor/processor1"""'}), True, 'from cirq.google.engine.client.quantum_v1alpha1 import types as qtypes\n'), (779, 'cirq.google.engine.client.quantum_v1alpha1.types.QuantumCalibration', 'qtypes.QuantumCalibration', ([], {'name': '"""projects/proj/processor/processor0/calibrations/123456"""'}), True, 'from cirq.google.engine.client.quantum_v1alpha1 import types as qtypes\n'), (781, 'cirq.google.engine.client.quantum_v1alpha1.types.QuantumCalibration', 'qtypes.QuantumCalibration', ([], {'name': '"""projects/proj/processor/processor1/calibrations/224466"""'}), True, 'from cirq.google.engine.client.quantum_v1alpha1 import types as qtypes\n'), (841, 'pytest.raises', 'pytest.raises', (['EngineException'], {'match': '"""boom"""'}), False, 'import pytest\n'), (852, 'pytest.raises', 'pytest.raises', (['EngineException'], {'match': '"""not found"""'}), False, 'import pytest\n'), (864, 'pytest.raises', 'pytest.raises', (['TimeoutError'], {'match': '"""Reached max retry attempts.*internal error"""'}), False, 'import pytest\n'), (983, 'pytest.raises', 'pytest.raises', (['EngineException'], {'match': '"""boom"""'}), False, 'import pytest\n'), (47, 'cirq.google.engine.client.quantum_v1alpha1.types.QuantumProgram', 'qtypes.QuantumProgram', ([], {'name': '"""projects/proj/programs/prog"""', 'code': 'code', 'description': '"""A program"""', 'labels': 'labels'}), True, 'from cirq.google.engine.client.quantum_v1alpha1 import types as qtypes\n'), (56, 'cirq.google.engine.client.quantum_v1alpha1.types.QuantumProgram', 'qtypes.QuantumProgram', ([], {'name': '"""projects/proj/programs/prog"""', 'code': 'code', 'description': '"""A program"""'}), True, 'from cirq.google.engine.client.quantum_v1alpha1 import types as qtypes\n'), (64, 'cirq.google.engine.client.quantum_v1alpha1.types.QuantumProgram', 'qtypes.QuantumProgram', ([], {'name': '"""projects/proj/programs/prog"""', 'code': 'code', 'labels': 'labels'}), True, 'from cirq.google.engine.client.quantum_v1alpha1 import types as qtypes\n'), (71, 'cirq.google.engine.client.quantum_v1alpha1.types.QuantumProgram', 'qtypes.QuantumProgram', ([], {'name': '"""projects/proj/programs/prog"""', 'code': 'code'}), True, 'from cirq.google.engine.client.quantum_v1alpha1 import types as qtypes\n'), (77, 'cirq.google.engine.client.quantum_v1alpha1.types.QuantumProgram', 'qtypes.QuantumProgram', ([], {'code': 'code'}), True, 'from cirq.google.engine.client.quantum_v1alpha1 import types as qtypes\n'), (124, 'datetime.date', 'datetime.date', (['(2020)', '(9)', '(1)'], {}), False, 'import datetime\n'), (128, 'datetime.datetime', 'datetime.datetime', (['(2020)', '(9)', '(1)', '(0)', '(0)', '(0)'], {'tzinfo': 'datetime.timezone.utc'}), False, 'import datetime\n'), (134, 'datetime.date', 'datetime.date', (['(2020)', '(10)', '(1)'], {}), False, 'import datetime\n'), (137, 'datetime.date', 'datetime.date', (['(2020)', '(9)', '(1)'], {}), False, 'import datetime\n'), (138, 'datetime.datetime', 'datetime.datetime', (['(2020)', '(9)', '(1)', '(0)', '(0)', '(10)'], {'tzinfo': 'datetime.timezone.utc'}), False, 'import datetime\n'), (152, 'datetime.date', 'datetime.date', (['(2020)', '(8)', '(1)'], {}), False, 'import datetime\n'), (153, 'datetime.datetime', 'datetime.datetime', (['(2020)', '(9)', '(1)'], {'tzinfo': 'datetime.timezone.utc'}), False, 'import datetime\n'), (193, 'cirq.google.engine.client.quantum_v1alpha1.types.QuantumProgram', 'qtypes.QuantumProgram', ([], {'name': '"""projects/proj/programs/prog"""', 'description': '"""A program"""'}), True, 'from cirq.google.engine.client.quantum_v1alpha1 import types as qtypes\n'), (195, 'cirq.google.engine.client.quantum_v1alpha1.types.field_mask_pb2.FieldMask', 'qtypes.field_mask_pb2.FieldMask', ([], {'paths': "['description']"}), True, 'from cirq.google.engine.client.quantum_v1alpha1 import types as qtypes\n'), (200, 'cirq.google.engine.client.quantum_v1alpha1.types.QuantumProgram', 'qtypes.QuantumProgram', ([], {'name': '"""projects/proj/programs/prog"""'}), True, 'from cirq.google.engine.client.quantum_v1alpha1 import types as qtypes\n'), (201, 'cirq.google.engine.client.quantum_v1alpha1.types.field_mask_pb2.FieldMask', 'qtypes.field_mask_pb2.FieldMask', ([], {'paths': "['description']"}), True, 'from cirq.google.engine.client.quantum_v1alpha1 import types as qtypes\n'), (223, 'cirq.google.engine.client.quantum_v1alpha1.types.QuantumProgram', 'qtypes.QuantumProgram', ([], {'name': '"""projects/proj/programs/prog"""', 'labels': 'labels', 'label_fingerprint': '"""hash"""'}), True, 'from cirq.google.engine.client.quantum_v1alpha1 import types as qtypes\n'), (226, 'cirq.google.engine.client.quantum_v1alpha1.types.field_mask_pb2.FieldMask', 'qtypes.field_mask_pb2.FieldMask', ([], {'paths': "['labels']"}), True, 'from cirq.google.engine.client.quantum_v1alpha1 import types as qtypes\n'), (231, 'cirq.google.engine.client.quantum_v1alpha1.types.QuantumProgram', 'qtypes.QuantumProgram', ([], {'name': '"""projects/proj/programs/prog"""', 'label_fingerprint': '"""hash"""'}), True, 'from cirq.google.engine.client.quantum_v1alpha1 import types as qtypes\n'), (233, 'cirq.google.engine.client.quantum_v1alpha1.types.field_mask_pb2.FieldMask', 'qtypes.field_mask_pb2.FieldMask', ([], {'paths': "['labels']"}), True, 'from cirq.google.engine.client.quantum_v1alpha1 import types as qtypes\n'), (259, 'cirq.google.engine.client.quantum_v1alpha1.types.QuantumProgram', 'qtypes.QuantumProgram', ([], {'name': '"""projects/proj/programs/prog"""', 'labels': "{'color': 'red', 'weather': 'sun', 'run': '1', 'hello': 'world'}", 'label_fingerprint': '"""hash"""'}), True, 'from cirq.google.engine.client.quantum_v1alpha1 import types as qtypes\n'), (267, 'cirq.google.engine.client.quantum_v1alpha1.types.field_mask_pb2.FieldMask', 'qtypes.field_mask_pb2.FieldMask', ([], {'paths': "['labels']"}), True, 'from cirq.google.engine.client.quantum_v1alpha1 import types as qtypes\n'), (275, 'cirq.google.engine.client.quantum_v1alpha1.types.QuantumProgram', 'qtypes.QuantumProgram', ([], {'name': '"""projects/proj/programs/prog"""', 'labels': "{'color': 'blue', 'weather': 'sun', 'run': '1', 'hello': 'world'}", 'label_fingerprint': '"""hash"""'}), True, 'from cirq.google.engine.client.quantum_v1alpha1 import types as qtypes\n'), (283, 'cirq.google.engine.client.quantum_v1alpha1.types.field_mask_pb2.FieldMask', 'qtypes.field_mask_pb2.FieldMask', ([], {'paths': "['labels']"}), True, 'from cirq.google.engine.client.quantum_v1alpha1 import types as qtypes\n'), (308, 'cirq.google.engine.client.quantum_v1alpha1.types.QuantumProgram', 'qtypes.QuantumProgram', ([], {'name': '"""projects/proj/programs/prog"""', 'labels': "{'color': 'red', 'run': '1'}", 'label_fingerprint': '"""hash"""'}), True, 'from cirq.google.engine.client.quantum_v1alpha1 import types as qtypes\n'), (314, 'cirq.google.engine.client.quantum_v1alpha1.types.field_mask_pb2.FieldMask', 'qtypes.field_mask_pb2.FieldMask', ([], {'paths': "['labels']"}), True, 'from cirq.google.engine.client.quantum_v1alpha1 import types as qtypes\n'), (320, 'cirq.google.engine.client.quantum_v1alpha1.types.QuantumProgram', 'qtypes.QuantumProgram', ([], {'name': '"""projects/proj/programs/prog"""', 'label_fingerprint': '"""hash"""'}), True, 'from cirq.google.engine.client.quantum_v1alpha1 import types as qtypes\n'), (322, 'cirq.google.engine.client.quantum_v1alpha1.types.field_mask_pb2.FieldMask', 'qtypes.field_mask_pb2.FieldMask', ([], {'paths': "['labels']"}), True, 'from cirq.google.engine.client.quantum_v1alpha1 import types as qtypes\n'), (467, 'cirq.google.engine.client.quantum_v1alpha1.types.QuantumJob', 'qtypes.QuantumJob', ([], {'name': '"""projects/proj/programs/prog/jobs/job0"""', 'description': '"""A job"""'}), True, 'from cirq.google.engine.client.quantum_v1alpha1 import types as qtypes\n'), (469, 'cirq.google.engine.client.quantum_v1alpha1.types.field_mask_pb2.FieldMask', 'qtypes.field_mask_pb2.FieldMask', ([], {'paths': "['description']"}), True, 'from cirq.google.engine.client.quantum_v1alpha1 import types as qtypes\n'), (474, 'cirq.google.engine.client.quantum_v1alpha1.types.QuantumJob', 'qtypes.QuantumJob', ([], {'name': '"""projects/proj/programs/prog/jobs/job0"""'}), True, 'from cirq.google.engine.client.quantum_v1alpha1 import types as qtypes\n'), (475, 'cirq.google.engine.client.quantum_v1alpha1.types.field_mask_pb2.FieldMask', 'qtypes.field_mask_pb2.FieldMask', ([], {'paths': "['description']"}), True, 'from cirq.google.engine.client.quantum_v1alpha1 import types as qtypes\n'), (497, 'cirq.google.engine.client.quantum_v1alpha1.types.QuantumJob', 'qtypes.QuantumJob', ([], {'name': '"""projects/proj/programs/prog/jobs/job0"""', 'labels': 'labels', 'label_fingerprint': '"""hash"""'}), True, 'from cirq.google.engine.client.quantum_v1alpha1 import types as qtypes\n'), (500, 'cirq.google.engine.client.quantum_v1alpha1.types.field_mask_pb2.FieldMask', 'qtypes.field_mask_pb2.FieldMask', ([], {'paths': "['labels']"}), True, 'from cirq.google.engine.client.quantum_v1alpha1 import types as qtypes\n'), (505, 'cirq.google.engine.client.quantum_v1alpha1.types.QuantumJob', 'qtypes.QuantumJob', ([], {'name': '"""projects/proj/programs/prog/jobs/job0"""', 'label_fingerprint': '"""hash"""'}), True, 'from cirq.google.engine.client.quantum_v1alpha1 import types as qtypes\n'), (507, 'cirq.google.engine.client.quantum_v1alpha1.types.field_mask_pb2.FieldMask', 'qtypes.field_mask_pb2.FieldMask', ([], {'paths': "['labels']"}), True, 'from cirq.google.engine.client.quantum_v1alpha1 import types as qtypes\n'), (533, 'cirq.google.engine.client.quantum_v1alpha1.types.QuantumJob', 'qtypes.QuantumJob', ([], {'name': '"""projects/proj/programs/prog/jobs/job0"""', 'labels': "{'color': 'red', 'weather': 'sun', 'run': '1', 'hello': 'world'}", 'label_fingerprint': '"""hash"""'}), True, 'from cirq.google.engine.client.quantum_v1alpha1 import types as qtypes\n'), (541, 'cirq.google.engine.client.quantum_v1alpha1.types.field_mask_pb2.FieldMask', 'qtypes.field_mask_pb2.FieldMask', ([], {'paths': "['labels']"}), True, 'from cirq.google.engine.client.quantum_v1alpha1 import types as qtypes\n'), (549, 'cirq.google.engine.client.quantum_v1alpha1.types.QuantumJob', 'qtypes.QuantumJob', ([], {'name': '"""projects/proj/programs/prog/jobs/job0"""', 'labels': "{'color': 'blue', 'weather': 'sun', 'run': '1', 'hello': 'world'}", 'label_fingerprint': '"""hash"""'}), True, 'from cirq.google.engine.client.quantum_v1alpha1 import types as qtypes\n'), (557, 'cirq.google.engine.client.quantum_v1alpha1.types.field_mask_pb2.FieldMask', 'qtypes.field_mask_pb2.FieldMask', ([], {'paths': "['labels']"}), True, 'from cirq.google.engine.client.quantum_v1alpha1 import types as qtypes\n'), (583, 'cirq.google.engine.client.quantum_v1alpha1.types.QuantumJob', 'qtypes.QuantumJob', ([], {'name': '"""projects/proj/programs/prog/jobs/job0"""', 'labels': "{'color': 'red', 'run': '1'}", 'label_fingerprint': '"""hash"""'}), True, 'from cirq.google.engine.client.quantum_v1alpha1 import types as qtypes\n'), (589, 'cirq.google.engine.client.quantum_v1alpha1.types.field_mask_pb2.FieldMask', 'qtypes.field_mask_pb2.FieldMask', ([], {'paths': "['labels']"}), True, 'from cirq.google.engine.client.quantum_v1alpha1 import types as qtypes\n'), (595, 'cirq.google.engine.client.quantum_v1alpha1.types.QuantumJob', 'qtypes.QuantumJob', ([], {'name': '"""projects/proj/programs/prog/jobs/job0"""', 'label_fingerprint': '"""hash"""'}), True, 'from cirq.google.engine.client.quantum_v1alpha1 import types as qtypes\n'), (597, 'cirq.google.engine.client.quantum_v1alpha1.types.field_mask_pb2.FieldMask', 'qtypes.field_mask_pb2.FieldMask', ([], {'paths': "['labels']"}), True, 'from cirq.google.engine.client.quantum_v1alpha1 import types as qtypes\n'), (674, 'datetime.date', 'datetime.date', (['(2020)', '(9)', '(1)'], {}), False, 'import datetime\n'), (679, 'datetime.datetime', 'datetime.datetime', (['(2020)', '(9)', '(1)', '(0)', '(0)', '(0)'], {'tzinfo': 'datetime.timezone.utc'}), False, 'import datetime\n'), (686, 'datetime.date', 'datetime.date', (['(2020)', '(10)', '(1)'], {}), False, 'import datetime\n'), (690, 'datetime.date', 'datetime.date', (['(2020)', '(9)', '(1)'], {}), False, 'import datetime\n'), (691, 'datetime.datetime', 'datetime.datetime', (['(2020)', '(9)', '(1)', '(0)', '(0)', '(10)'], {'tzinfo': 'datetime.timezone.utc'}), False, 'import datetime\n'), (716, 'datetime.date', 'datetime.date', (['(2020)', '(8)', '(1)'], {}), False, 'import datetime\n'), (717, 'datetime.datetime', 'datetime.datetime', (['(2020)', '(9)', '(1)'], {'tzinfo': 'datetime.timezone.utc'}), False, 'import datetime\n'), (878, 'google.protobuf.timestamp_pb2.Timestamp', 'Timestamp', ([], {'seconds': '(1000000000)'}), False, 'from google.protobuf.timestamp_pb2 import Timestamp\n'), (879, 'google.protobuf.timestamp_pb2.Timestamp', 'Timestamp', ([], {'seconds': '(1000003600)'}), False, 'from google.protobuf.timestamp_pb2 import Timestamp\n'), (903, 'google.protobuf.timestamp_pb2.Timestamp', 'Timestamp', ([], {'seconds': '(1000000000)'}), False, 'from google.protobuf.timestamp_pb2 import Timestamp\n'), (904, 'google.protobuf.timestamp_pb2.Timestamp', 'Timestamp', ([], {'seconds': '(1000002000)'}), False, 'from google.protobuf.timestamp_pb2 import Timestamp\n'), (924, 'google.protobuf.timestamp_pb2.Timestamp', 'Timestamp', ([], {'seconds': '(1000000000)'}), False, 'from google.protobuf.timestamp_pb2 import Timestamp\n'), (925, 'google.protobuf.timestamp_pb2.Timestamp', 'Timestamp', ([], {'seconds': '(1000002000)'}), False, 'from google.protobuf.timestamp_pb2 import Timestamp\n'), (945, 'google.protobuf.timestamp_pb2.Timestamp', 'Timestamp', ([], {'seconds': '(1000000000)'}), False, 'from google.protobuf.timestamp_pb2 import Timestamp\n'), (946, 'google.protobuf.timestamp_pb2.Timestamp', 'Timestamp', ([], {'seconds': '(1000002000)'}), False, 'from google.protobuf.timestamp_pb2 import Timestamp\n'), (1017, 'google.protobuf.timestamp_pb2.Timestamp', 'Timestamp', ([], {'seconds': '(1000001000)'}), False, 'from google.protobuf.timestamp_pb2 import Timestamp\n'), (1018, 'google.protobuf.timestamp_pb2.Timestamp', 'Timestamp', ([], {'seconds': '(1000002000)'}), False, 'from google.protobuf.timestamp_pb2 import Timestamp\n'), (1039, 'google.protobuf.field_mask_pb2.FieldMask', 'FieldMask', ([], {'paths': "['start_time', 'end_time', 'whitelisted_users']"}), False, 'from google.protobuf.field_mask_pb2 import FieldMask\n'), (1064, 'google.protobuf.field_mask_pb2.FieldMask', 'FieldMask', ([], {'paths': "['whitelisted_users']"}), False, 'from google.protobuf.field_mask_pb2 import FieldMask\n'), (178, 'cirq.google.engine.engine_client.EngineClient', 'EngineClient', ([], {}), False, 'from cirq.google.engine.engine_client import EngineClient, EngineException\n'), (994, 'google.protobuf.timestamp_pb2.Timestamp', 'Timestamp', ([], {'seconds': '(1000000000)'}), False, 'from google.protobuf.timestamp_pb2 import Timestamp\n'), (995, 'google.protobuf.timestamp_pb2.Timestamp', 'Timestamp', ([], {'seconds': '(1000002000)'}), False, 'from google.protobuf.timestamp_pb2 import Timestamp\n'), (1000, 'google.protobuf.timestamp_pb2.Timestamp', 'Timestamp', ([], {'seconds': '(1200000000)'}), False, 'from google.protobuf.timestamp_pb2 import Timestamp\n'), (1001, 'google.protobuf.timestamp_pb2.Timestamp', 'Timestamp', ([], {'seconds': '(1200002000)'}), False, 'from google.protobuf.timestamp_pb2 import Timestamp\n'), (1028, 'datetime.datetime.fromtimestamp', 'datetime.datetime.fromtimestamp', (['(1000001000)'], {}), False, 'import datetime\n'), (1029, 'datetime.datetime.fromtimestamp', 'datetime.datetime.fromtimestamp', (['(1000002000)'], {}), False, 'import datetime\n'), (1074, 'google.protobuf.timestamp_pb2.Timestamp', 'Timestamp', ([], {'seconds': '(1000020000)'}), False, 'from google.protobuf.timestamp_pb2 import Timestamp\n'), (1075, 'google.protobuf.timestamp_pb2.Timestamp', 'Timestamp', ([], {'seconds': '(1000040000)'}), False, 'from google.protobuf.timestamp_pb2 import Timestamp\n'), (1077, 'cirq.google.engine.client.quantum_v1alpha1.types.QuantumTimeSlot.MaintenanceConfig', 'qtypes.QuantumTimeSlot.MaintenanceConfig', ([], {'title': '"""Testing"""', 'description': '"""Testing some new configuration."""'}), True, 'from cirq.google.engine.client.quantum_v1alpha1 import types as qtypes\n'), (1084, 'google.protobuf.timestamp_pb2.Timestamp', 'Timestamp', ([], {'seconds': '(1000010000)'}), False, 'from google.protobuf.timestamp_pb2 import Timestamp\n'), (1085, 'google.protobuf.timestamp_pb2.Timestamp', 'Timestamp', ([], {'seconds': '(1000020000)'}), False, 'from google.protobuf.timestamp_pb2 import Timestamp\n'), (1087, 'cirq.google.engine.client.quantum_v1alpha1.types.QuantumTimeSlot.ReservationConfig', 'qtypes.QuantumTimeSlot.ReservationConfig', ([], {'project_id': '"""super_secret_quantum"""'}), True, 'from cirq.google.engine.client.quantum_v1alpha1 import types as qtypes\n'), (359, 'cirq.google.engine.client.quantum_v1alpha1.types.SchedulingConfig.ProcessorSelector', 'qtypes.SchedulingConfig.ProcessorSelector', ([], {'processor_names': "['projects/proj/processors/processor0']"}), True, 'from cirq.google.engine.client.quantum_v1alpha1 import types as qtypes\n'), (380, 'cirq.google.engine.client.quantum_v1alpha1.types.SchedulingConfig.ProcessorSelector', 'qtypes.SchedulingConfig.ProcessorSelector', ([], {'processor_names': "['projects/proj/processors/processor0']"}), True, 'from cirq.google.engine.client.quantum_v1alpha1 import types as qtypes\n'), (397, 'cirq.google.engine.client.quantum_v1alpha1.types.SchedulingConfig.ProcessorSelector', 'qtypes.SchedulingConfig.ProcessorSelector', ([], {'processor_names': "['projects/proj/processors/processor0']"}), True, 'from cirq.google.engine.client.quantum_v1alpha1 import types as qtypes\n'), (410, 'cirq.google.engine.client.quantum_v1alpha1.types.SchedulingConfig.ProcessorSelector', 'qtypes.SchedulingConfig.ProcessorSelector', ([], {'processor_names': "['projects/proj/processors/processor0']"}), True, 'from cirq.google.engine.client.quantum_v1alpha1 import types as qtypes\n'), (426, 'cirq.google.engine.client.quantum_v1alpha1.types.SchedulingConfig.ProcessorSelector', 'qtypes.SchedulingConfig.ProcessorSelector', ([], {'processor_names': "['projects/proj/processors/processor0']"}), True, 'from cirq.google.engine.client.quantum_v1alpha1 import types as qtypes\n')]