mirror of
https://github.com/p-e-w/heretic.git
synced 2026-09-25 21:41:26 -07:00
fix: validate scorer instance names in config (#407)
* fix: validate scorer instance names in config * fix: run scorer config tests in CI * fix: drop redundant UV_PYTHON env and quote unittest pattern * fix: report precise scorer name validation errors
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
# Copyright (C) 2025-2026 Philipp Emanuel Weidmann <pew@worldwidemann.com> + contributors
|
||||
|
||||
import unittest
|
||||
|
||||
from pydantic import ValidationError
|
||||
|
||||
from heretic.config import ScorerConfig
|
||||
|
||||
|
||||
class ScorerConfigTests(unittest.TestCase):
|
||||
def test_accepts_slug_like_instance_name(self) -> None:
|
||||
config = ScorerConfig(
|
||||
plugin="heretic.scorers.keyword_rate.KeywordRate",
|
||||
optimization="minimize",
|
||||
instance_name="small-1",
|
||||
)
|
||||
|
||||
self.assertEqual(config.instance_name, "small-1")
|
||||
|
||||
def test_rejects_empty_instance_name(self) -> None:
|
||||
with self.assertRaises(ValidationError):
|
||||
ScorerConfig(
|
||||
plugin="heretic.scorers.keyword_rate.KeywordRate",
|
||||
optimization="minimize",
|
||||
instance_name=" \t",
|
||||
)
|
||||
|
||||
def test_rejects_whitespace_in_instance_name(self) -> None:
|
||||
for instance_name in ["small name", "small\tname", "small\nname"]:
|
||||
with self.subTest(instance_name=instance_name):
|
||||
with self.assertRaisesRegex(
|
||||
ValidationError, "whitespace is not allowed"
|
||||
):
|
||||
ScorerConfig(
|
||||
plugin="heretic.scorers.keyword_rate.KeywordRate",
|
||||
optimization="minimize",
|
||||
instance_name=instance_name,
|
||||
)
|
||||
|
||||
def test_rejects_dot_in_instance_name(self) -> None:
|
||||
with self.assertRaisesRegex(ValidationError, "'\\.' is not allowed"):
|
||||
ScorerConfig(
|
||||
plugin="heretic.scorers.keyword_rate.KeywordRate",
|
||||
optimization="minimize",
|
||||
instance_name="small.name",
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user