Skip to content

Commit 4f42118

Browse files
authored
Ensure tests are runnable when standalone (#552)
When we run tests internally that don't invoke the test class, they pass but don't run the tests. Our GitHub environment tests them fine but this change ensures they run in both environments.
1 parent c039446 commit 4f42118

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

Diff for: tests/test_helpers.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
15-
import pathlib
1615
import copy
1716
import collections
1817
from typing import Union
1918

19+
from absl.testing import absltest
2020
from absl.testing import parameterized
2121

2222
from google.generativeai import protos
@@ -81,3 +81,7 @@ def test_get_model(self, request_options, expected_timeout, expected_retry):
8181

8282
self.assertEqual(self.observed_timeout[0], expected_timeout)
8383
self.assertEqual(str(self.observed_retry[0]), str(expected_retry))
84+
85+
86+
if __name__ == "__main__":
87+
absltest.main()

Diff for: tests/test_protos.py

+5
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import pathlib
1616
import re
1717

18+
from absl.testing import absltest
1819
from absl.testing import parameterized
1920

2021
ROOT = pathlib.Path(__file__).parent.parent
@@ -32,3 +33,7 @@ def test_check_glm_imports(self):
3233
match,
3334
msg=f"Bad `glm.` usage, use `genai.protos` instead,\n in {fpath}",
3435
)
36+
37+
38+
if __name__ == "__main__":
39+
absltest.main()

Diff for: tests/test_responder.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@
1919
from absl.testing import parameterized
2020
from google.generativeai import protos
2121
from google.generativeai import responder
22-
import IPython.display
23-
import PIL.Image
22+
2423

2524
HERE = pathlib.Path(__file__).parent
2625
TEST_PNG_PATH = HERE / "test_img.png"
@@ -250,3 +249,7 @@ def fun(a: annotation):
250249
cfd = responder.FunctionDeclaration.from_function(fun)
251250
got = cfd.parameters.properties["a"]
252251
self.assertEqual(got, expected)
252+
253+
254+
if __name__ == "__main__":
255+
absltest.main()

0 commit comments

Comments
 (0)