|
| 1 | +# Copyright 2024 Google LLC |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | +# |
| 15 | + |
| 16 | +from inspect import signature |
| 17 | +import unittest |
| 18 | + |
| 19 | +from google.generativeai import GenerativeModel |
| 20 | +from sdk_schema_tests import common_contract |
| 21 | +from sdk_schema_tests import google_ai_only_contract as specific_contract |
| 22 | + |
| 23 | +_SDK_NAME = "GoogleAI" |
| 24 | + |
| 25 | + |
| 26 | +class TestGenerativeModelMethodSignatures(unittest.TestCase): |
| 27 | + def test_generate_content_signature(self): |
| 28 | + generate_content_signature = signature(GenerativeModel.generate_content) |
| 29 | + actual_method_arg_keys = generate_content_signature.parameters.keys() |
| 30 | + actual_return_annotation = generate_content_signature.return_annotation |
| 31 | + |
| 32 | + for expected_key in common_contract.expected_generate_content_common_arg_keys: |
| 33 | + self.assertIn( |
| 34 | + member=expected_key, |
| 35 | + container=actual_method_arg_keys, |
| 36 | + msg=( |
| 37 | + f"[{_SDK_NAME}]: expected common key {expected_key} not found in" |
| 38 | + f" actual keys: {actual_method_arg_keys}" |
| 39 | + ), |
| 40 | + ) |
| 41 | + |
| 42 | + self.assertEqual( |
| 43 | + actual_return_annotation, |
| 44 | + specific_contract.expected_generate_content_return_annotation, |
| 45 | + msg=( |
| 46 | + f"[{_SDK_NAME}]: expected return annotation" |
| 47 | + f" {specific_contract.expected_generate_content_return_annotation}" |
| 48 | + f" not equal to actual return annotation {actual_return_annotation}" |
| 49 | + ), |
| 50 | + ) |
0 commit comments