forked from qodo-ai/pr-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_get_max_tokens.py
More file actions
168 lines (135 loc) · 5.26 KB
/
test_get_max_tokens.py
File metadata and controls
168 lines (135 loc) · 5.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
import pytest
import pr_agent.algo.utils as utils
from pr_agent.algo.utils import MAX_TOKENS, get_max_tokens
class TestGetMaxTokens:
# Test if the file is in MAX_TOKENS
def test_model_max_tokens(self, monkeypatch):
fake_settings = type('', (), {
'config': type('', (), {
'custom_model_max_tokens': 0,
'max_model_tokens': 0
})()
})()
monkeypatch.setattr(utils, "get_settings", lambda: fake_settings)
model = "gpt-3.5-turbo"
expected = MAX_TOKENS[model]
assert get_max_tokens(model) == expected
@pytest.mark.parametrize("model", ["gpt-5.4", "gpt-5.4-2026-03-05"])
def test_gpt54_model_max_tokens(self, monkeypatch, model):
fake_settings = type('', (), {
'config': type('', (), {
'custom_model_max_tokens': 0,
'max_model_tokens': 0
})()
})()
monkeypatch.setattr(utils, "get_settings", lambda: fake_settings)
assert get_max_tokens(model) == 272000
# Test situations where the model is not registered and exists as a custom model
def test_model_has_custom(self, monkeypatch):
fake_settings = type('', (), {
'config': type('', (), {
'custom_model_max_tokens': 5000,
'max_model_tokens': 0 # 제한 없음
})()
})()
monkeypatch.setattr(utils, "get_settings", lambda: fake_settings)
model = "custom-model"
expected = 5000
assert get_max_tokens(model) == expected
@pytest.mark.parametrize("model", [
"gpt-5.1-codex",
"gpt-5.2-codex",
"gpt-5.3-codex",
])
def test_gpt_codex_models_max_tokens(self, monkeypatch, model):
fake_settings = type('', (), {
'config': type('', (), {
'custom_model_max_tokens': 0,
'max_model_tokens': 0
})()
})()
monkeypatch.setattr(utils, "get_settings", lambda: fake_settings)
expected = MAX_TOKENS[model]
assert get_max_tokens(model) == expected
def test_model_not_max_tokens_and_not_has_custom(self, monkeypatch):
fake_settings = type('', (), {
'config': type('', (), {
'custom_model_max_tokens': 0,
'max_model_tokens': 0
})()
})()
monkeypatch.setattr(utils, "get_settings", lambda: fake_settings)
model = "custom-model"
with pytest.raises(Exception):
get_max_tokens(model)
def test_model_max_tokens_with__limit(self, monkeypatch):
fake_settings = type('', (), {
'config': type('', (), {
'custom_model_max_tokens': 0,
'max_model_tokens': 10000
})()
})()
monkeypatch.setattr(utils, "get_settings", lambda: fake_settings)
model = "gpt-3.5-turbo" # this model setting is 160000
expected = 10000
assert get_max_tokens(model) == expected
@pytest.mark.parametrize("model", [
"gemini/gemini-3-flash-preview",
"vertex_ai/gemini-3-flash-preview",
"gemini/gemini-3-pro-preview",
"vertex_ai/gemini-3-pro-preview",
"gemini/gemini-3.1-pro-preview",
"vertex_ai/gemini-3.1-pro-preview",
])
def test_gemini_3_and_3_1_pro_preview(self, monkeypatch, model):
fake_settings = type("", (), {
"config": type("", (), {
"custom_model_max_tokens": 0,
"max_model_tokens": 0,
})()
})()
monkeypatch.setattr(utils, "get_settings", lambda: fake_settings)
assert get_max_tokens(model) == 1048576
@pytest.mark.parametrize(
"model",
[
"anthropic/claude-opus-4-6",
"claude-opus-4-6",
"vertex_ai/claude-opus-4-6",
"bedrock/anthropic.claude-opus-4-6-v1:0",
"bedrock/global.anthropic.claude-opus-4-6-v1:0",
"bedrock/us.anthropic.claude-opus-4-6-v1:0",
],
)
def test_claude_opus_4_6_model_max_tokens(self, monkeypatch, model):
fake_settings = type('', (), {
'config': type('', (), {
'custom_model_max_tokens': 0,
'max_model_tokens': 0
})()
})()
monkeypatch.setattr(utils, "get_settings", lambda: fake_settings)
assert get_max_tokens(model) == 200000
@pytest.mark.parametrize(
"model",
[
"anthropic/claude-sonnet-4-6",
"claude-sonnet-4-6",
"vertex_ai/claude-sonnet-4-6",
"bedrock/anthropic.claude-sonnet-4-6",
"bedrock/global.anthropic.claude-sonnet-4-6",
"bedrock/us.anthropic.claude-sonnet-4-6",
"bedrock/au.anthropic.claude-sonnet-4-6",
"bedrock/eu.anthropic.claude-sonnet-4-6",
"bedrock/jp.anthropic.claude-sonnet-4-6",
],
)
def test_claude_sonnet_4_6_model_max_tokens(self, monkeypatch, model):
fake_settings = type('', (), {
'config': type('', (), {
'custom_model_max_tokens': 0,
'max_model_tokens': 0
})()
})()
monkeypatch.setattr(utils, "get_settings", lambda: fake_settings)
assert get_max_tokens(model) == 200000