-
Notifications
You must be signed in to change notification settings - Fork 1.6k
feat: read content of generate request #14113
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
fbb164e
0b2264f
456b3f7
5d48e80
7dfd7bf
ac7f6f2
cca01f6
1130c70
98fb3c9
647d70e
75a0931
f0e8bda
d785d92
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| # Copyright 2025 Google LLC | ||
| # | ||
| # 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 | ||
| # | ||
| # http://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. | ||
|
|
||
| pytest | ||
| pytest-mock |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,7 +12,10 @@ | |
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| from cli import handle_generate, handle_build, handle_configure | ||
| import pytest | ||
| import json | ||
|
|
||
| from cli import _read_json_file, handle_generate, handle_build, handle_configure | ||
|
|
||
|
|
||
| def test_handle_configure_dry_run(): | ||
|
|
@@ -26,3 +29,37 @@ def test_handle_generate_dry_run(): | |
| def test_handle_build_dry_run(): | ||
| # This is a simple test to ensure that the dry run command succeeds. | ||
| handle_build(dry_run=True) | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add a |
||
| def test_read_valid_json(mocker): | ||
| """Tests reading a valid JSON file.""" | ||
| mock_content = '{"key": "value"}' | ||
| mocker.patch("os.path.exists", return_value=True) | ||
ohmayr marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| mocker.patch("builtins.open", mocker.mock_open(read_data=mock_content)) | ||
| result = _read_json_file("fake/path.json") | ||
| assert result == {"key": "value"} | ||
|
|
||
| def test_file_not_found(mocker): | ||
| """Tests behavior when the file does not exist.""" | ||
| mocker.patch("os.path.exists", return_value=False) | ||
|
||
|
|
||
| with pytest.raises(FileNotFoundError): | ||
| _read_json_file("non/existent/path.json") | ||
|
|
||
| def test_invalid_json(mocker): | ||
| """Tests reading a file with malformed JSON.""" | ||
| mock_content = '{"key": "value",}' | ||
| mocker.patch("os.path.exists", return_value=True) | ||
| mocker.patch("builtins.open", mocker.mock_open(read_data=mock_content)) | ||
|
|
||
| with pytest.raises(ValueError, match="Invalid JSON"): | ||
| _read_json_file("fake/path.json") | ||
|
|
||
| def test_io_error_on_read(mocker): | ||
| """Tests for a generic IOError.""" | ||
| mocker.patch("os.path.exists", return_value=True) | ||
| mocked_open = mocker.mock_open() | ||
| mocked_open.side_effect = IOError("Permission denied") | ||
| mocker.patch("builtins.open", mocked_open) | ||
|
|
||
| with pytest.raises(IOError, match="Permission denied"): | ||
| _read_json_file("fake/path.json") | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| { | ||
|
||
| "id": "google-cloud-language", | ||
| "apis": [ | ||
| { | ||
| "path": "google/cloud/language/v1", | ||
| "service_config": "language.yaml" | ||
| } | ||
| ] | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| # Copyright 2025 Google LLC | ||
| # | ||
| # 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 | ||
| # | ||
| # http://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. | ||
|
|
||
| steps: | ||
ohmayr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| # This step builds the Docker image. | ||
| - name: 'gcr.io/cloud-builders/docker' | ||
ohmayr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| args: | ||
| - 'build' | ||
| - '-t' | ||
| - 'gcr.io/$PROJECT_ID/python-librarian-generator:latest' | ||
| - '-f' | ||
| - '.generator/Dockerfile' | ||
ohmayr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| - '.' | ||
|
|
||
| # This section solves the logging error by automatically creating a bucket. | ||
ohmayr marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| options: | ||
| default_logs_bucket_behavior: REGIONAL_USER_OWNED_BUCKET | ||
Uh oh!
There was an error while loading. Please reload this page.