Skip to content

armgit / dspy

Public Imported from GitHub
0

DSPy: The framework for programming—not prompting—language models

Python

Style fixing for tests/ (part 2) (#8226)

Chen Qiana95218b7e6f2
diff --git a/tests/evaluate/test_evaluate.py b/tests/evaluate/test_evaluate.py
index 44e0cec75..6f03fdbbb 100644
--- a/tests/evaluate/test_evaluate.py
+++ b/tests/evaluate/test_evaluate.py
@@ -1,8 +1,8 @@
import signal
import threading
from unittest.mock import patch
-import pandas as pd
+import pandas as pd
import pytest
import dspy
@@ -31,7 +31,7 @@ def test_evaluate_initialization():
assert ev.devset == devset
assert ev.metric == answer_exact_match
assert ev.num_threads is None
- assert ev.display_progress == False
+ assert not ev.display_progress
def test_evaluate_call():
@@ -75,7 +75,7 @@ def test_construct_result_df():
"pred_answer": ["2", "4"],
"answer_exact_match": [100.0, 100.0],
}
- )
+ ),
)
@@ -200,6 +200,7 @@ def test_evaluate_display_table(program_with_example, display_table, is_in_ipyth
example_input = next(iter(example.inputs().values()))
assert example_input in out
+
def test_evaluate_callback():
class TestCallback(BaseCallback):
def __init__(self):
@@ -216,12 +217,12 @@ def test_evaluate_callback():
):
self.start_call_inputs = inputs
self.start_call_count += 1
-
+
def on_evaluate_end(
self,
call_id: str,
outputs,
- exception = None,
+ exception=None,
):
self.end_call_outputs = outputs
self.end_call_count += 1
@@ -234,7 +235,7 @@ def test_evaluate_callback():
"What is 2+2?": {"answer": "4"},
}
),
- callbacks=[callback]
+ callbacks=[callback],
)
devset = [new_example("What is 1+1?", "2"), new_example("What is 2+2?", "4")]
program = Predict("question -> answer")
diff --git a/tests/evaluate/test_metrics.py b/tests/evaluate/test_metrics.py
index f6471b870..9a4464350 100644
--- a/tests/evaluate/test_metrics.py
+++ b/tests/evaluate/test_metrics.py
@@ -4,6 +4,7 @@ import dspy
from dspy.evaluate.metrics import answer_exact_match
from dspy.predict import Predict
+
def test_answer_exact_match_string():
example = dspy.Example(
question="What is 1+1?",
@@ -13,6 +14,7 @@ def test_answer_exact_match_string():
pred.answer = "2"
assert answer_exact_match(example, pred)
+
def test_answer_exact_match_list():
example = dspy.Example(
question="What is 1+1?",
@@ -22,6 +24,7 @@ def test_answer_exact_match_list():
pred.answer = "2"
assert answer_exact_match(example, pred)
+
def test_answer_exact_match_no_match():
example = dspy.Example(
question="What is 1+1?",
@@ -29,4 +32,4 @@ def test_answer_exact_match_no_match():
).with_inputs("question")
pred = Predict("question -> answer")
pred.answer = "3"
- assert not answer_exact_match(example, pred)
\ No newline at end of file
+ assert not answer_exact_match(example, pred)
diff --git a/tests/examples/test_baleen.py b/tests/examples/test_baleen.py
index 4f1a84105..1cc27e8fc 100644
--- a/tests/examples/test_baleen.py
+++ b/tests/examples/test_baleen.py
@@ -1,8 +1,7 @@
-import pytest
-from dspy.dsp.utils import deduplicate
-import dspy.evaluate
import dspy
+import dspy.evaluate
from dspy.datasets import HotPotQA
+from dspy.dsp.utils import deduplicate
from dspy.evaluate.evaluate import Evaluate
from dspy.teleprompt.bootstrap import BootstrapFewShot
@@ -27,9 +26,7 @@ class SimplifiedBaleen(dspy.Module):
def __init__(self, passages_per_hop=3, max_hops=2):
super().__init__()
- self.generate_query = [
- dspy.ChainOfThought(GenerateSearchQuery) for _ in range(max_hops)
- ]
+ self.generate_query = [dspy.ChainOfThought(GenerateSearchQuery) for _ in range(max_hops)]
self.retrieve = dspy.Retrieve(k=passages_per_hop)
self.generate_answer = dspy.ChainOfThought(GenerateAnswer)
self.max_hops = max_hops
@@ -48,9 +45,7 @@ class SimplifiedBaleen(dspy.Module):
def load_hotpotqa():
# Load the dataset.
- dataset = HotPotQA(
- train_seed=1, train_size=20, eval_seed=2023, dev_size=50, test_size=0
- )
+ dataset = HotPotQA(train_seed=1, train_size=20, eval_seed=2023, dev_size=50, test_size=0)
# Tell DSPy that the 'question' field is the input. Any other fields are labels and/or metadata.
trainset = [x.with_inputs("question") for x in dataset.train]
devset = [x.with_inputs("question") for x in dataset.dev]
@@ -80,16 +75,11 @@ def validate_context_and_answer_and_hops(example, pred, trace=None):
if not dspy.evaluate.answer_passage_match(example, pred):
return False
- hops = [example.question] + [
- outputs.query for *_, outputs in trace if "query" in outputs
- ]
+ hops = [example.question] + [outputs.query for *_, outputs in trace if "query" in outputs]
if max([len(h) for h in hops]) > 100:
return False
- if any(
- dspy.evaluate.answer_exact_match_str(hops[idx], hops[:idx], frac=0.8)
- for idx in range(2, len(hops))
- ):
+ if any(dspy.evaluate.answer_exact_match_str(hops[idx], hops[:idx], frac=0.8) for idx in range(2, len(hops))):
return False
return True
@@ -97,9 +87,7 @@ def validate_context_and_answer_and_hops(example, pred, trace=None):
def gold_passages_retrieved(example, pred, trace=None):
gold_titles = set(map(dspy.evaluate.normalize_text, example["gold_titles"]))
- found_titles = set(
- map(dspy.evaluate.normalize_text, [c.split(" | ")[0] for c in pred.context])
- )
+ found_titles = set(map(dspy.evaluate.normalize_text, [c.split(" | ")[0] for c in pred.context]))
return gold_titles.issubset(found_titles)
@@ -121,16 +109,12 @@ def _test_compiled_baleen():
trainset=trainset,
)
- evaluate_on_hotpotqa = Evaluate(
- devset=devset, num_threads=1, display_progress=True, display_table=5
- )
+ evaluate_on_hotpotqa = Evaluate(devset=devset, num_threads=1, display_progress=True, display_table=5)
uncompiled_baleen_retrieval_score = evaluate_on_hotpotqa(
uncompiled_baleen, metric=gold_passages_retrieved, display=False
)
# assert uncompiled_baleen_retrieval_score / 100 == 18 / 50
- compiled_baleen_retrieval_score = evaluate_on_hotpotqa(
- compiled_baleen, metric=gold_passages_retrieved
- )
+ compiled_baleen_retrieval_score = evaluate_on_hotpotqa(compiled_baleen, metric=gold_passages_retrieved)
# assert compiled_baleen_retrieval_score / 100 == 27 / 50
- assert uncompiled_baleen_retrieval_score < compiled_baleen_retrieval_score
\ No newline at end of file
+ assert uncompiled_baleen_retrieval_score < compiled_baleen_retrieval_score
diff --git a/tests/metadata/test_metadata.py b/tests/metadata/test_metadata.py
index 9e6f133d7..e1b29fa27 100644
--- a/tests/metadata/test_metadata.py
+++ b/tests/metadata/test_metadata.py
@@ -1,6 +1,7 @@
-import dspy
import re
+import dspy
+
def test_metadata():
assert dspy.__name__ == "dspy"
diff --git a/tests/predict/test_aggregation.py b/tests/predict/test_aggregation.py
index 9f03c2e3c..1a020ab39 100644
--- a/tests/predict/test_aggregation.py
+++ b/tests/predict/test_aggregation.py
@@ -1,12 +1,10 @@
-from dspy.predict.aggregation import majority
-from dspy.primitives.prediction import Prediction, Completions
from dspy.dsp.utils import normalize_text
+from dspy.predict.aggregation import majority
+from dspy.primitives.prediction import Completions, Prediction
def test_majority_with_prediction():
- prediction = Prediction.from_completions(
- [{"answer": "2"}, {"answer": "2"}, {"answer": "3"}]
- )
+ prediction = Prediction.from_completions([{"answer": "2"}, {"answer": "2"}, {"answer": "3"}])
result = majority(prediction)
assert result.completions[0]["answer"] == "2"
@@ -42,6 +40,4 @@ def test_majority_with_field():
def test_majority_with_no_majority():
completions = [{"answer": "2"}, {"answer": "3"}, {"answer": "4"}]
result = majority(completions)
- assert (
- result.completions[0]["answer"] == "2"
- ) # The first completion is returned in case of a tie
+ assert result.completions[0]["answer"] == "2" # The first completion is returned in case of a tie
diff --git a/tests/predict/test_best_of_n.py b/tests/predict/test_best_of_n.py
index a2f823973..777e99e54 100644
--- a/tests/predict/test_best_of_n.py
+++ b/tests/predict/test_best_of_n.py
@@ -1,14 +1,13 @@
import pytest
import dspy
-from dspy.predict.predict import Predict
from dspy.predict.best_of_n import BestOfN
+from dspy.predict.predict import Predict
from dspy.primitives.prediction import Prediction
from dspy.utils.dummies import DummyLM
class DummyModule(dspy.Module):
-
def __init__(self, signature, forward_fn):
super().__init__()
self.predictor = Predict(signature)
@@ -19,13 +18,7 @@ class DummyModule(dspy.Module):
def test_refine_forward_success_first_attempt():
- lm = DummyLM([{
- "answer": "Brussels"
- }, {
- "answer": "City of Brussels"
- }, {
- "answer": "Brussels"
- }])
+ lm = DummyLM([{"answer": "Brussels"}, {"answer": "City of Brussels"}, {"answer": "Brussels"}])
dspy.settings.configure(lm=lm)
module_call_count = [0]
@@ -42,27 +35,18 @@ def test_refine_forward_success_first_attempt():
predict = DummyModule("question -> answer", count_calls)
- best_of_n = BestOfN(module=predict,
- N=3,
- reward_fn=reward_fn,
- threshold=1.0)
+ best_of_n = BestOfN(module=predict, N=3, reward_fn=reward_fn, threshold=1.0)
result = best_of_n(question="What is the capital of Belgium?")
assert result.answer == "Brussels", "Result should be `Brussels`"
assert reward_call_count[0] > 0, "Reward function should have been called"
assert module_call_count[0] == 3, (
- "Module should have been called exactly 3 times, but was called %d times"
- % module_call_count[0])
+ "Module should have been called exactly 3 times, but was called %d times" % module_call_count[0]
+ )
def test_refine_module_default_fail_count():
- lm = DummyLM([{
- "answer": "Brussels"
- }, {
- "answer": "City of Brussels"
- }, {
- "answer": "Brussels"
- }])
+ lm = DummyLM([{"answer": "Brussels"}, {"answer": "City of Brussels"}, {"answer": "Brussels"}])
dspy.settings.configure(lm=lm)
def always_raise(self, **kwargs):
@@ -70,22 +54,13 @@ def test_refine_module_default_fail_count():
predict = DummyModule("question -> answer", always_raise)
- best_of_n = BestOfN(module=predict,
- N=3,
- reward_fn=lambda _, __: 1.0,
- threshold=0.0)
+ best_of_n = BestOfN(module=predict, N=3, reward_fn=lambda _, __: 1.0, threshold=0.0)
with pytest.raises(ValueError):
best_of_n(question="What is the capital of Belgium?")
def test_refine_module_custom_fail_count():
- lm = DummyLM([{
- "answer": "Brussels"
- }, {
- "answer": "City of Brussels"
- }, {
- "answer": "Brussels"
- }])
+ lm = DummyLM([{"answer": "Brussels"}, {"answer": "City of Brussels"}, {"answer": "Brussels"}])
dspy.settings.configure(lm=lm)
module_call_count = [0]
@@ -97,13 +72,9 @@ def test_refine_module_custom_fail_count():
predict = DummyModule("question -> answer", raise_on_second_call)
- best_of_n = BestOfN(module=predict,
- N=3,
- reward_fn=lambda _, __: 1.0,
- threshold=0.0,
- fail_count=1)
+ best_of_n = BestOfN(module=predict, N=3, reward_fn=lambda _, __: 1.0, threshold=0.0, fail_count=1)
with pytest.raises(ValueError):
best_of_n(question="What is the capital of Belgium?")
assert module_call_count[0] == 2, (
- "Module should have been called exactly 2 times, but was called %d times"
- % module_call_count[0])
+ "Module should have been called exactly 2 times, but was called %d times" % module_call_count[0]
+ )
diff --git a/tests/predict/test_chain_of_thought.py b/tests/predict/test_chain_of_thought.py
index 5b6198368..68f8e4c9b 100644
--- a/tests/predict/test_chain_of_thought.py
+++ b/tests/predict/test_chain_of_thought.py
@@ -1,9 +1,9 @@
+import pytest
+
import dspy
from dspy import ChainOfThought
from dspy.utils import DummyLM
-import pytest
-
def test_initialization_with_string_signature():
lm = DummyLM([{"reasoning": "find the number after 1", "answer": "2"}])
diff --git a/tests/predict/test_parallel.py b/tests/predict/test_parallel.py
index da99e5757..e7f8d41fa 100644
--- a/tests/predict/test_parallel.py
+++ b/tests/predict/test_parallel.py
@@ -1,16 +1,17 @@
import dspy
-
from dspy.utils.dummies import DummyLM
def test_parallel_module():
- lm = DummyLM([
- {"output": "test output 1"},
- {"output": "test output 2"},
- {"output": "test output 3"},
- {"output": "test output 4"},
- {"output": "test output 5"},
- ])
+ lm = DummyLM(
+ [
+ {"output": "test output 1"},
+ {"output": "test output 2"},
+ {"output": "test output 3"},
+ {"output": "test output 4"},
+ {"output": "test output 5"},
+ ]
+ )
dspy.settings.configure(lm=lm)
class MyModule(dspy.Module):
@@ -22,13 +23,15 @@ def test_parallel_module():
self.parallel = dspy.Parallel(num_threads=2)
def forward(self, input):
- return self.parallel([
- (self.predictor, input),
- (self.predictor2, input),
- (self.predictor, input),
- (self.predictor2, input),
- (self.predictor, input),
- ])
+ return self.parallel(
+ [
+ (self.predictor, input),
+ (self.predictor2, input),
+ (self.predictor, input),
+ (self.predictor2, input),
+ (self.predictor, input),
+ ]
+ )
output = MyModule()(dspy.Example(input="test input").with_inputs("input"))
@@ -37,20 +40,24 @@ def test_parallel_module():
def test_batch_module():
- lm = DummyLM([
- {"output": "test output 1"},
- {"output": "test output 2"},
- {"output": "test output 3"},
- {"output": "test output 4"},
- {"output": "test output 5"},
- ])
- res_lm = DummyLM([
- {"output": "test output 1", "reasoning": "test reasoning 1"},
- {"output": "test output 2", "reasoning": "test reasoning 2"},
- {"output": "test output 3", "reasoning": "test reasoning 3"},
- {"output": "test output 4", "reasoning": "test reasoning 4"},
- {"output": "test output 5", "reasoning": "test reasoning 5"},
- ])
+ lm = DummyLM(
+ [
+ {"output": "test output 1"},
+ {"output": "test output 2"},
+ {"output": "test output 3"},
+ {"output": "test output 4"},
+ {"output": "test output 5"},
+ ]
+ )
+ res_lm = DummyLM(
+ [
+ {"output": "test output 1", "reasoning": "test reasoning 1"},
+ {"output": "test output 2", "reasoning": "test reasoning 2"},
+ {"output": "test output 3", "reasoning": "test reasoning 3"},
+ {"output": "test output 4", "reasoning": "test reasoning 4"},
+ {"output": "test output 5", "reasoning": "test reasoning 5"},
+ ]
+ )
class MyModule(dspy.Module):
def __init__(self):
@@ -83,13 +90,15 @@ def test_batch_module():
def test_nested_parallel_module():
- lm = DummyLM([
- {"output": "test output 1"},
- {"output": "test output 2"},
- {"output": "test output 3"},
- {"output": "test output 4"},
- {"output": "test output 5"},
- ])
+ lm = DummyLM(
+ [
+ {"output": "test output 1"},
+ {"output": "test output 2"},
+ {"output": "test output 3"},
+ {"output": "test output 4"},
+ {"output": "test output 5"},
+ ]
+ )
dspy.settings.configure(lm=lm)
class MyModule(dspy.Module):
@@ -101,14 +110,19 @@ def test_nested_parallel_module():
self.parallel = dspy.Parallel(num_threads=2)
def forward(self, input):
- return self.parallel([
- (self.predictor, input),
- (self.predictor2, input),
- (self.parallel, [
- (self.predictor2, input),
+ return self.parallel(
+ [
(self.predictor, input),
- ]),
- ])
+ (self.predictor2, input),
+ (
+ self.parallel,
+ [
+ (self.predictor2, input),
+ (self.predictor, input),
+ ],
+ ),
+ ]
+ )
output = MyModule()(dspy.Example(input="test input").with_inputs("input"))
@@ -120,13 +134,15 @@ def test_nested_parallel_module():
def test_nested_batch_method():
- lm = DummyLM([
- {"output": "test output 1"},
- {"output": "test output 2"},
- {"output": "test output 3"},
- {"output": "test output 4"},
- {"output": "test output 5"},
- ])
+ lm = DummyLM(
+ [
+ {"output": "test output 1"},
+ {"output": "test output 2"},
+ {"output": "test output 3"},
+ {"output": "test output 4"},
+ {"output": "test output 5"},
+ ]
+ )
dspy.settings.configure(lm=lm)
class MyModule(dspy.Module):
@@ -135,11 +151,15 @@ def test_nested_batch_method():
self.predictor = dspy.Predict("input -> output")
def forward(self, input):
- res = self.predictor.batch([dspy.Example(input=input).with_inputs("input")]*2)
+ res = self.predictor.batch([dspy.Example(input=input).with_inputs("input")] * 2)
return res
- result = MyModule().batch([dspy.Example(input="test input").with_inputs("input")]*2)
+ result = MyModule().batch([dspy.Example(input="test input").with_inputs("input")] * 2)
- assert {result[0][0].output, result[0][1].output, result[1][0].output, result[1][1].output} \
- == {"test output 1", "test output 2", "test output 3", "test output 4"}
+ assert {result[0][0].output, result[0][1].output, result[1][0].output, result[1][1].output} == {
+ "test output 1",
+ "test output 2",
+ "test output 3",
+ "test output 4",
+ }
diff --git a/tests/predict/test_predict.py b/tests/predict/test_predict.py
index 685f55826..ba0c47820 100644
--- a/tests/predict/test_predict.py
+++ b/tests/predict/test_predict.py
@@ -1,17 +1,16 @@
import copy
import enum
from datetime import datetime
+from unittest.mock import patch
import pydantic
import pytest
import ujson
-import os
+from litellm import ModelResponse
import dspy
from dspy import Predict, Signature
from dspy.utils.dummies import DummyLM
-from unittest.mock import patch, MagicMock, Mock
-from litellm import ModelResponse
def test_initialization_with_string_signature():
@@ -390,7 +389,7 @@ def test_enum_inputs_and_outputs_with_shared_names_and_values():
def test_auto_valued_enum_inputs_and_outputs():
- Status = enum.Enum("Status", ["PENDING", "IN_PROGRESS", "COMPLETED"])
+ Status = enum.Enum("Status", ["PENDING", "IN_PROGRESS", "COMPLETED"]) # noqa: N806
class StatusSignature(dspy.Signature):
current_status: Status = dspy.InputField()
diff --git a/tests/predict/test_program_of_thought.py b/tests/predict/test_program_of_thought.py
index 493265789..4871afc7f 100644
--- a/tests/predict/test_program_of_thought.py
+++ b/tests/predict/test_program_of_thought.py
@@ -1,6 +1,7 @@
+import shutil
from unittest.mock import patch
+
import pytest
-import shutil
import dspy
from dspy import ProgramOfThought, Signature
diff --git a/tests/predict/test_react.py b/tests/predict/test_react.py
index 680028aad..e3beb300d 100644
--- a/tests/predict/test_react.py
+++ b/tests/predict/test_react.py
@@ -1,11 +1,11 @@
-from pydantic import BaseModel
-
import re
-import dspy
+
import litellm
+import pytest
+from pydantic import BaseModel
+import dspy
from dspy.utils.dummies import DummyLM
-import pytest
def test_tool_calling_with_pydantic_args():
@@ -161,7 +161,7 @@ def test_trajectory_truncation():
def test_error_retry():
# --- a tiny tool that always fails -------------------------------------
- def foo(a, b): # noqa: D401, ANN001
+ def foo(a, b):
raise Exception("tool error")
# --- program under test -------------------------------------------------
@@ -289,7 +289,7 @@ async def test_async_tool_calling_with_pydantic_args():
@pytest.mark.asyncio
async def test_async_error_retry():
# A tiny tool that always fails
- async def foo(a, b): # noqa: D401, ANN001
+ async def foo(a, b):
raise Exception("tool error")
react = dspy.ReAct("a, b -> c:int", tools=[foo])
diff --git a/tests/predict/test_refine.py b/tests/predict/test_refine.py
index e63a484ab..7bff4b2b0 100644
--- a/tests/predict/test_refine.py
+++ b/tests/predict/test_refine.py
@@ -1,5 +1,3 @@
-from unittest.mock import patch
-
import pytest
import dspy
diff --git a/tests/primitives/test_example.py b/tests/primitives/test_example.py
index 9897a2676..e40601713 100644
--- a/tests/primitives/test_example.py
+++ b/tests/primitives/test_example.py
@@ -1,4 +1,5 @@
import pytest
+
import dspy
from dspy import Example
diff --git a/tests/primitives/test_module.py b/tests/primitives/test_module.py
index 886213847..c63105bff 100644
--- a/tests/primitives/test_module.py
+++ b/tests/primitives/test_module.py
@@ -1,10 +1,12 @@
-import dspy
-import threading
-from dspy.utils.dummies import DummyLM
import logging
+import os
+import threading
from unittest.mock import patch
+
import pytest
-import os
+
+import dspy
+from dspy.utils.dummies import DummyLM
def test_deepcopy_basic():
@@ -241,5 +243,5 @@ def test_usage_tracker_in_parallel():
assert results[0].get_lm_usage() is not None
assert results[1].get_lm_usage() is not None
- assert results[0].get_lm_usage().keys() == set(["openai/gpt-4o-mini"])
- assert results[1].get_lm_usage().keys() == set(["openai/gpt-3.5-turbo"])
+ assert results[0].get_lm_usage().keys() == {"openai/gpt-4o-mini"}
+ assert results[1].get_lm_usage().keys() == {"openai/gpt-3.5-turbo"}
diff --git a/tests/primitives/test_program.py b/tests/primitives/test_program.py
index 546fc5971..32a357d17 100644
--- a/tests/primitives/test_program.py
+++ b/tests/primitives/test_program.py
@@ -87,7 +87,7 @@ def test_multiple_sub_modules():
module.sub1 = Module()
module.sub2 = Module()
expected = [("self", module), ("self.sub1", module.sub1), ("self.sub2", module.sub2)]
- assert sorted(list(module.named_sub_modules())) == sorted(expected)
+ assert sorted(module.named_sub_modules()) == sorted(expected)
def test_non_base_module_attributes():
@@ -102,7 +102,6 @@ def test_complex_module_traversal():
root = Module()
root.sub_module = Module()
root.sub_module.nested_list = [Module(), {"key": Module()}]
- same_sub = Module()
root.sub_module.nested_tuple = (Module(), [Module(), Module()])
expected_names = {
"self",
@@ -120,7 +119,7 @@ def test_complex_module_traversal():
), f"Missing or extra modules found. Missing: {expected_names-found_names}, Extra: {found_names-expected_names}"
-def test_complex_module_traversal():
+def test_complex_module_traversal_with_same_module():
root = Module()
root.sub_module = Module()
root.sub_module.nested_list = [Module(), {"key": Module()}]
@@ -133,7 +132,6 @@ def test_complex_module_traversal():
"self.sub_module.nested_list[1][key]", # NOTE: named_sub_modules allows recursive structures
"self.sub_module.nested_tuple[0]",
"self.sub_module.nested_tuple[1][0]", # NEW: named_sub_modules allows recursive structures, but named_parameters does not
- # "self.sub_module.nested_tuple[1][1]", This should not be included, as it's the same module as the previous one
}
found_names = {name for name, _ in root.named_sub_modules()}
diff --git a/tests/primitives/test_python_interpreter.py b/tests/primitives/test_python_interpreter.py
index 8ad606d25..902381ea0 100644
--- a/tests/primitives/test_python_interpreter.py
+++ b/tests/primitives/test_python_interpreter.py
@@ -1,8 +1,7 @@
+import random
import shutil
import pytest
-import random
-
from dspy.primitives.python_interpreter import InterpreterError, PythonInterpreter
diff --git a/tests/primitives/test_tool.py b/tests/primitives/test_tool.py
index 1d1c203f7..06f5b8d58 100644
--- a/tests/primitives/test_tool.py
+++ b/tests/primitives/test_tool.py
@@ -1,8 +1,10 @@
+import asyncio
+from typing import Any, Optional
+
import pytest
from pydantic import BaseModel
+
from dspy.primitives.tool import Tool
-from typing import Any, Optional
-import asyncio
# Test fixtures
@@ -253,7 +255,10 @@ def test_tool_call_kwarg():
def test_tool_str():
tool = Tool(dummy_function)
- assert str(tool) == "dummy_function, whose description is <desc>A dummy function for testing. Args: x: An integer parameter y: A string parameter </desc>. It takes arguments {'x': {'type': 'integer'}, 'y': {'type': 'string', 'default': 'hello'}} in JSON format."
+ assert (
+ str(tool)
+ == "dummy_function, whose description is <desc>A dummy function for testing. Args: x: An integer parameter y: A string parameter </desc>. It takes arguments {'x': {'type': 'integer'}, 'y': {'type': 'string', 'default': 'hello'}} in JSON format."
+ )
@pytest.mark.asyncio
diff --git a/tests/propose/test_grounded_proposer.py b/tests/propose/test_grounded_proposer.py
index ddf041632..517f4e174 100644
--- a/tests/propose/test_grounded_proposer.py
+++ b/tests/propose/test_grounded_proposer.py
@@ -1,7 +1,8 @@
import pytest
+
import dspy
-from dspy.propose.grounded_proposer import GroundedProposer
from dspy.predict import Predict
+from dspy.propose.grounded_proposer import GroundedProposer
from dspy.utils.dummies import DummyLM