-
Notifications
You must be signed in to change notification settings - Fork 0
Replace assert-based genre validation with ValueError in names.py and voice.py #150
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -2,10 +2,13 @@ | |||||||||||||||||||||||||||
| Tests for novelforge/voice.py — voice seed selection and formatting. | ||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| import importlib | ||||||||||||||||||||||||||||
| import random | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| import pytest | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| import novelforge.validation | ||||||||||||||||||||||||||||
| import novelforge.voice | ||||||||||||||||||||||||||||
| from novelforge.voice import ( | ||||||||||||||||||||||||||||
| _PREMISE_KEYWORD_BOOST, | ||||||||||||||||||||||||||||
| _PREMISE_KEYWORDS, | ||||||||||||||||||||||||||||
|
|
@@ -212,3 +215,23 @@ def test_embeds_seed_content(self): | |||||||||||||||||||||||||||
| assert seed["prose_style"] in prompt | ||||||||||||||||||||||||||||
| assert seed["emotional_register"] in prompt | ||||||||||||||||||||||||||||
| assert seed["sensory_preference"] in prompt | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| # --------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| # Genre coverage validation raises ValueError (not silenced by -O flag) | ||||||||||||||||||||||||||||
| # --------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| class TestVoiceGenreValidation: | ||||||||||||||||||||||||||||
| """voice.py must raise ValueError for missing genre mappings even under -O.""" | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| def test_raises_value_error_when_genre_missing_from_voice_weights(self, monkeypatch): | ||||||||||||||||||||||||||||
| """Reloading voice.py with an extra ALLOWED_GENRES entry raises ValueError.""" | ||||||||||||||||||||||||||||
| extended = novelforge.validation.ALLOWED_GENRES | {"FakeGenreForTest"} | ||||||||||||||||||||||||||||
| monkeypatch.setattr(novelforge.validation, "ALLOWED_GENRES", extended) | ||||||||||||||||||||||||||||
| with pytest.raises(ValueError, match="FakeGenreForTest"): | ||||||||||||||||||||||||||||
|
Comment on lines
+230
to
+232
|
||||||||||||||||||||||||||||
| extended = novelforge.validation.ALLOWED_GENRES | {"FakeGenreForTest"} | |
| monkeypatch.setattr(novelforge.validation, "ALLOWED_GENRES", extended) | |
| with pytest.raises(ValueError, match="FakeGenreForTest"): | |
| original_allowed_genres = novelforge.validation.ALLOWED_GENRES | |
| extended = original_allowed_genres | {"FakeGenreForTest"} | |
| monkeypatch.setattr(novelforge.validation, "ALLOWED_GENRES", extended) | |
| try: | |
| with pytest.raises(ValueError, match="FakeGenreForTest"): | |
| importlib.reload(novelforge.voice) | |
| finally: | |
| monkeypatch.setattr( | |
| novelforge.validation, "ALLOWED_GENRES", original_allowed_genres | |
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The failing
importlib.reload(novelforge.names)leavesnovelforge.namesin a partially re-executed state for the remainder of the test session (reload reuses the existing module dict and does not roll back on exceptions). That can create order-dependent behavior if any later test imports/usesnovelforge.namesexpecting a clean module state. Consider reloading the module back to a known-good state in afinallyblock (after restoringALLOWED_GENRES) or using a fixture that always reloadsnovelforge.nameswith the standardALLOWED_GENRESafter this test.