forked from MakazhanAlpamys/Soup
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_code_review_medium_low.py
More file actions
97 lines (68 loc) · 3.15 KB
/
Copy pathtest_code_review_medium_low.py
File metadata and controls
97 lines (68 loc) · 3.15 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
"""Regression tests for the MEDIUM/LOW findings in CODE_REVIEW.md."""
from __future__ import annotations
from pathlib import Path
import soup_cli
def _src(rel: str) -> str:
return (Path(soup_cli.__file__).parent / rel).read_text(encoding="utf-8")
def test_license_matrix_permissive_weak_symmetric():
from soup_cli.utils.license_matrix import (
_PERMISSIVE,
_WEAK_COPYLEFT,
LICENSE_MATRIX,
)
assert _WEAK_COPYLEFT in LICENSE_MATRIX[_PERMISSIVE]
assert _PERMISSIVE in LICENSE_MATRIX[_WEAK_COPYLEFT]
def test_detect_format_prefers_tool_calling_over_audio():
from soup_cli.data.formats import detect_format
row = {
"messages": [{"role": "user", "content": "x"}],
"tools": [{"name": "f"}],
"tool_calls": [{"name": "f", "arguments": "{}"}],
"audio": "a.wav",
}
assert detect_format([row]) == "tool-calling"
def test_converters_reject_null_content():
from soup_cli.data.formats import format_to_messages
# A JSON null in a required content field routes the row to the drop path
# (returns None) instead of producing literal None content.
assert format_to_messages({"instruction": "hi", "output": None}, "alpaca") is None
assert (
format_to_messages(
{"prompt": "p", "chosen": None, "rejected": "r"}, "dpo"
)
is None
)
# A well-formed row still converts.
ok = format_to_messages({"instruction": "hi", "output": "yo"}, "alpaca")
assert ok["messages"][-1]["content"] == "yo"
def test_tool_call_args_subset_penalizes_hallucinated_args():
# The dead ternary `0.5 if not out_args else 0.5` gave hallucinated args
# full credit; the fix scores 0.0 for the args portion in that branch.
src = _src("eval/custom.py")
assert "args_score = 0.5 if not out_args else 0.0" in src
assert "0.5 if not out_args else 0.5" not in src
def test_ema_and_median_use_window_size():
from soup_cli.utils.reward_hack_control import smooth_signal
# Windowed EMA: a longer retained window folds in more history, so the
# result differs from the 1-element (2-tap) case — proving
# reward_hack_smoothing_window now has effect for EMA.
short = smooth_signal(1.0, [0.0], method="ema")
longer = smooth_signal(1.0, [1.0, 0.0, 0.0], method="ema")
assert short != longer
# median genuinely uses the retained window too.
assert smooth_signal(10.0, [1.0, 2.0], method="median") == 2.0
def test_sse_metric_push_preserves_zero():
assert "float(loss) if loss is not None else None" in _src("monitoring/callback.py")
def test_deploy_target_rejects_windows_drive_absolute():
src = _src("cans/schema.py")
assert 'value[1] == ":"' in src # drive-absolute (C:\...) now rejected
def test_diagnose_rejects_non_numeric_score():
src = _src("commands/diagnose.py")
assert "must be a number" in src
def test_generate_partial_save_present():
src = _src("commands/generate.py")
assert "Partial save" in src and "generated before the error" in src
def test_package_docstring_has_no_mojibake():
assert soup_cli.__doc__ is not None
assert "вЂ" not in soup_cli.__doc__
assert "—" in soup_cli.__doc__