|
| 1 | +# Copyright 2026 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 | +# https://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 | +from unittest.mock import MagicMock |
| 16 | +from gapic.codegen.components.package_init import PackageInitGenerator |
| 17 | + |
| 18 | + |
| 19 | +def test_generate_gapic_version(): |
| 20 | + mock_api = MagicMock() |
| 21 | + mock_api.gapic_version = "0.1.0" |
| 22 | + content = PackageInitGenerator.generate_gapic_version(mock_api) |
| 23 | + |
| 24 | + assert "# Copyright 2026 Google LLC" in content |
| 25 | + assert '__version__ = "0.1.0" # {x-release-please-version}' in content |
| 26 | + |
| 27 | + |
| 28 | +def test_generate_py_typed(): |
| 29 | + mock_api = MagicMock() |
| 30 | + mock_api.naming.warehouse_package_name = "google-iam-credentials" |
| 31 | + content = PackageInitGenerator.generate_py_typed(mock_api) |
| 32 | + assert "# Marker file for PEP 561." in content |
| 33 | + assert "google-iam-credentials" in content |
| 34 | + |
| 35 | + |
| 36 | +def test_pure_python_engine_render(): |
| 37 | + from gapic.codegen.engine import PurePythonEngine |
| 38 | + |
| 39 | + assert PurePythonEngine.render("gapic_version.py.j2", {}) is None |
| 40 | + |
| 41 | + mock_api = MagicMock() |
| 42 | + mock_api.gapic_version = "0.1.0" |
| 43 | + mock_api.naming.warehouse_package_name = "google-iam-credentials" |
| 44 | + |
| 45 | + v_out = PurePythonEngine.render("gapic_version.py.j2", {"api": mock_api}) |
| 46 | + assert '__version__ = "0.1.0"' in v_out |
| 47 | + |
| 48 | + t_out = PurePythonEngine.render("py.typed.j2", {"api": mock_api}) |
| 49 | + assert "google-iam-credentials" in t_out |
| 50 | + |
| 51 | + assert PurePythonEngine.render("other_file.py.j2", {"api": mock_api}) is None |
0 commit comments