refactor: consolidate voice formula building into voice_formulas.py

- voice_formulas.py: add pairs_to_formula() as canonical implementation
- webui/routes/utils/voice.py: formula_from_profile() and pairs_to_formula()
  now delegate to voice_formulas.pairs_to_formula()
- pyqt/gui.py: get_voice_formula() now uses voice_formulas.pairs_to_formula()
  instead of inline string formatting
- Eliminates 3 duplicate implementations of voice*weight formula building
- +9 tests
- 1178 tests pass
This commit is contained in:
Artem Akymenko
2026-07-19 10:02:14 +00:00
parent fe62b6b44c
commit a99cf58c79
4 changed files with 80 additions and 28 deletions
+44
View File
@@ -0,0 +1,44 @@
"""Tests for voice_formulas.py — pairs_to_formula."""
from abogen.voice_formulas import pairs_to_formula
class TestPairsToFormula:
def test_basic_pair(self):
result = pairs_to_formula([("A", 1.0), ("B", 1.0)])
assert result == "A*0.5+B*0.5"
def test_unequal_weights(self):
result = pairs_to_formula([("A", 3.0), ("B", 1.0)])
assert result == "A*0.75+B*0.25"
def test_single_voice(self):
result = pairs_to_formula([("A", 1.0)])
assert result == "A*1"
def test_filters_zero_weight(self):
result = pairs_to_formula([("A", 1.0), ("B", 0.0)])
assert result == "A*1"
def test_all_zero_returns_none(self):
result = pairs_to_formula([("A", 0.0), ("B", 0.0)])
assert result is None
def test_empty_returns_none(self):
result = pairs_to_formula([])
assert result is None
def test_none_values_filtered(self):
result = pairs_to_formula([("A", 1.0), ("B", None)])
assert result is not None
def test_weight_normalization(self):
result = pairs_to_formula([("A", 2.0), ("B", 2.0)])
assert result == "A*0.5+B*0.5"
def test_three_voices(self):
result = pairs_to_formula([("A", 1.0), ("B", 1.0), ("C", 1.0)])
assert "A*" in result
assert "B*" in result
assert "C*" in result
assert "+" in result