-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_options.py
More file actions
55 lines (45 loc) · 1.92 KB
/
Copy pathtest_options.py
File metadata and controls
55 lines (45 loc) · 1.92 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
#!/usr/bin/env python3
import unittest
from _common import _parse_option_value, parse_options
from run_bench import option_flags
class TestOptionParsing(unittest.TestCase):
def test_parse_option_value_types(self):
self.assertIs(_parse_option_value("true"), True)
self.assertIs(_parse_option_value("false"), False)
self.assertEqual(_parse_option_value("8192"), 8192)
self.assertEqual(_parse_option_value("1.0"), 1.0)
self.assertEqual(_parse_option_value("abc"), "abc")
def test_parse_options_happy_path(self):
opts = parse_options([
"--option=temperature=1.0",
"--option=top_p=0.95",
"--option=top_k=20",
])
self.assertEqual(opts, {"temperature": 1.0, "top_p": 0.95, "top_k": 20})
def test_parse_options_rejects_malformed(self):
bad_args = [
"--option=temperature",
"--option==1.0",
"--option=temperature=",
"--option=temperatur=1.0",
"--option=num_predict=3000",
"--option=think=true",
]
for arg in bad_args:
with self.subTest(arg=arg):
with self.assertRaises(ValueError):
parse_options([arg])
def test_parse_options_rejects_duplicates(self):
with self.assertRaises(ValueError):
parse_options(["--option=temperature=0.7", "--option=temperature=1.0"])
def test_option_flags_round_trip(self):
cfg = {"think": "high", "num_predict": 6000, "temperature": 1.0, "top_p": 0.95}
self.assertEqual(
parse_options(option_flags(cfg)),
{"temperature": 1.0, "top_p": 0.95},
)
def test_option_flags_rejects_unknown_task_key(self):
with self.assertRaises(ValueError):
option_flags({"think": "false", "num_predict": 3000, "note": "not an Ollama option"})
if __name__ == "__main__":
unittest.main(verbosity=2)