Skip to content

Commit

Permalink
Ensure tests are runnable when standalone (#552)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
markmcd authored Sep 12, 2024
1 parent c039446 commit 4f42118
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
6 changes: 5 additions & 1 deletion tests/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
# 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.
import pathlib
import copy
import collections
from typing import Union

from absl.testing import absltest
from absl.testing import parameterized

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

self.assertEqual(self.observed_timeout[0], expected_timeout)
self.assertEqual(str(self.observed_retry[0]), str(expected_retry))


if __name__ == "__main__":
absltest.main()
5 changes: 5 additions & 0 deletions tests/test_protos.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import pathlib
import re

from absl.testing import absltest
from absl.testing import parameterized

ROOT = pathlib.Path(__file__).parent.parent
Expand All @@ -32,3 +33,7 @@ def test_check_glm_imports(self):
match,
msg=f"Bad `glm.` usage, use `genai.protos` instead,\n in {fpath}",
)


if __name__ == "__main__":
absltest.main()
7 changes: 5 additions & 2 deletions tests/test_responder.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
from absl.testing import parameterized
from google.generativeai import protos
from google.generativeai import responder
import IPython.display
import PIL.Image


HERE = pathlib.Path(__file__).parent
TEST_PNG_PATH = HERE / "test_img.png"
Expand Down Expand Up @@ -250,3 +249,7 @@ def fun(a: annotation):
cfd = responder.FunctionDeclaration.from_function(fun)
got = cfd.parameters.properties["a"]
self.assertEqual(got, expected)


if __name__ == "__main__":
absltest.main()

0 comments on commit 4f42118

Please sign in to comment.