Skip to content

Commit

Permalink
Remove duplicate test (#387)
Browse files Browse the repository at this point in the history
* Cover methods like _handle_afc

Change-Id: I0f45cb8566b681f5aaeda1500e74d95eaeab10ef

* Remove duplicate code match test

Change-Id: Ia9b7c3dcb8dd4d6bf163303b483225aa0b00e0e9
  • Loading branch information
mayureshagashe2105 authored Jun 13, 2024
1 parent 8713cfd commit 7313e21
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 51 deletions.
2 changes: 1 addition & 1 deletion tests/test_async_code_match.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def test_code_match_for_async_methods(self):
for node in ast.walk(source_nodes):
if isinstance(
node, (ast.FunctionDef, ast.AsyncFunctionDef)
) and not node.name.startswith("_"):
) and not node.name.startswith("__"):
name = node.name[:-6] if node.name.endswith("_async") else node.name
if name in EXEMPT_FUNCTIONS or self._inspect_decorator_exemption(node, fpath):
continue
Expand Down
50 changes: 0 additions & 50 deletions tests/test_generative_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -847,56 +847,6 @@ def test_count_tokens_smoke(self, kwargs):
{"total_tokens": 7},
)

@parameterized.named_parameters(
[
"GenerateContentResponse",
generation_types.GenerateContentResponse,
generation_types.AsyncGenerateContentResponse,
],
[
"GenerativeModel.generate_response",
generative_models.GenerativeModel.generate_content,
generative_models.GenerativeModel.generate_content_async,
],
[
"GenerativeModel.count_tokens",
generative_models.GenerativeModel.count_tokens,
generative_models.GenerativeModel.count_tokens_async,
],
[
"ChatSession.send_message",
generative_models.ChatSession.send_message,
generative_models.ChatSession.send_message_async,
],
[
"ChatSession._handle_afc",
generative_models.ChatSession._handle_afc,
generative_models.ChatSession._handle_afc_async,
],
)
def test_async_code_match(self, obj, aobj):
import inspect
import re

source = inspect.getsource(obj)
asource = inspect.getsource(aobj)

source = re.sub('""".*"""', "", source, flags=re.DOTALL)
asource = re.sub('""".*"""', "", asource, flags=re.DOTALL)

asource = (
asource.replace("anext", "next")
.replace("aiter", "iter")
.replace("_async", "")
.replace("async ", "")
.replace("await ", "")
.replace("Async", "")
.replace("ASYNC_", "")
)

asource = re.sub(" *?# type: ignore", "", asource)
self.assertEqual(source, asource, f"error in {obj=}")

def test_repr_for_unary_non_streamed_response(self):
model = generative_models.GenerativeModel(model_name="gemini-pro")
self.responses["generate_content"].append(simple_response("world!"))
Expand Down

0 comments on commit 7313e21

Please sign in to comment.