Skip to content

Commit d9de675

Browse files
author
Luan Fernandes
committed
poetry lock and simpler approach in test
1 parent 887c451 commit d9de675

File tree

2 files changed

+49
-25
lines changed

2 files changed

+49
-25
lines changed

‎poetry.lock‎

Lines changed: 21 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎tests/test_resolve.py‎

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -77,36 +77,40 @@ def test_resolve_question_dry_run():
7777
assert tokens == 200
7878

7979

80-
@pytest.mark.asyncio
81-
async def test_process_questions(tmp_path, monkeypatch):
82-
# Mock data
83-
question_images = [(1, "encoded_q1"), (2, "encoded_q2")]
84-
conventions_image = "encoded_conventions"
85-
exam_path = str(tmp_path)
86-
87-
# Create fake futures that will be returned by our mock process_question
88-
future1 = asyncio.Future()
89-
future1.set_result((1, 100)) # (question_num, tokens)
80+
def test_process_questions(tmp_path, monkeypatch):
81+
"""Test that process_questions passes the correct parameters to asyncio.run()"""
82+
# Create needed files in the temporary directory
83+
conventions_file = tmp_path / "conventions.jpg"
84+
q1_file = tmp_path / "q1.jpg"
85+
q2_file = tmp_path / "q2.jpg"
86+
87+
# Create empty files
88+
conventions_file.write_bytes(b"test content")
89+
q1_file.write_bytes(b"test content")
90+
q2_file.write_bytes(b"test content")
9091

91-
future2 = asyncio.Future()
92-
future2.set_result((2, 100))
92+
exam_path = str(tmp_path)
9393

94-
# Mock process_question
95-
with mock.patch('gpt_resolve.resolve.process_question') as mock_process:
96-
# Set up the mock to return prepared futures
97-
mock_process.side_effect = [future1, future2]
94+
# Mock necessary functions to avoid real file operations or API calls
95+
with mock.patch('gpt_resolve.resolve.encode_image', return_value="mock_encoded_image"):
96+
with mock.patch('asyncio.run') as mock_async_run:
97+
# Import the function that uses process_questions
98+
from gpt_resolve.resolve import resolve_exam
9899

99-
# Mock asyncio.as_completed to return our futures in a controlled order
100-
with mock.patch('asyncio.as_completed', return_value=[future1, future2]):
101-
# Run the actual function
102-
await process_questions(
103-
questions_images=question_images,
104-
conventions_image=conventions_image,
100+
# Call the function that would use process_questions
101+
resolve_exam(
105102
exam_path=exam_path,
103+
questions_to_solve=[1, 2],
106104
dry_run=True,
107105
max_tokens_output=1000,
108106
model="test-model"
109107
)
110108

111-
# Verify process_question was called for each question
112-
assert mock_process.call_count == 2
109+
# Verify asyncio.run was called
110+
assert mock_async_run.call_count == 1
111+
112+
# Get the arguments passed to asyncio.run
113+
args, _ = mock_async_run.call_args
114+
115+
# Check that the first argument is a coroutine object (process_questions)
116+
assert callable(args[0].__await__)

0 commit comments

Comments
 (0)