Mock client that simulates degraded provider responses. mode: - "empty_choices": response with an empty choices list - "none_content": a choice whose message.content is None - "length": a choice truncated with finish_reason == "length"
| 49 | |
| 50 | |
| 51 | class MockBadClient: |
| 52 | """Mock client that simulates degraded provider responses. |
| 53 | |
| 54 | mode: |
| 55 | - "empty_choices": response with an empty choices list |
| 56 | - "none_content": a choice whose message.content is None |
| 57 | - "length": a choice truncated with finish_reason == "length" |
| 58 | """ |
| 59 | def __init__(self, mode): |
| 60 | self.chat = self.Chat(mode) |
| 61 | |
| 62 | class Chat: |
| 63 | def __init__(self, mode): |
| 64 | self.completions = self.Completions(mode) |
| 65 | |
| 66 | class Completions: |
| 67 | def __init__(self, mode): |
| 68 | self.mode = mode |
| 69 | |
| 70 | def create(self, **kwargs): |
| 71 | mode = self.mode |
| 72 | |
| 73 | class MockUsage: |
| 74 | completion_tokens = 0 |
| 75 | total_tokens = 0 |
| 76 | |
| 77 | if mode == "empty_choices": |
| 78 | class MockResponse: |
| 79 | choices = [] |
| 80 | usage = MockUsage() |
| 81 | return MockResponse() |
| 82 | |
| 83 | class MockMessage: |
| 84 | content = None if mode == "none_content" else "partial output" |
| 85 | |
| 86 | class MockChoice: |
| 87 | message = MockMessage() |
| 88 | finish_reason = "length" if mode == "length" else "stop" |
| 89 | |
| 90 | class MockResponse: |
| 91 | choices = [MockChoice()] |
| 92 | usage = MockUsage() |
| 93 | |
| 94 | return MockResponse() |
| 95 | |
| 96 | |
| 97 | def test_approach_imports(): |
no outgoing calls