D19: единый язык пользовательских сообщений — русский
Переведены все английские тексты, которые видит пользователь: 13 сообщений исключений (ExcelRepositoryError, CurrencyError, ForecastError, ValueError в domain/ и from_dict) и 7 сообщений pydantic-валидаторов. What-if описание сценария — по-русски. fail_validation() срезает английский префикс pydantic «Value error, » и берёт запасную подпись поля из нового ключа global.value (ключи i18n не переименованы, en.py не тронут). Инвариант tests/test_language.py: словарь ru, тексты raise(...) и прямые строковые литералы console.print не содержат английских маркеров; end-to-end проверки ошибок export/import/валидации.
This commit is contained in:
1 parent
d2d301f8c4
commit
7aed61f21b
16 files changed
+230
-33
No files matched your search
+16
-16
@@ -133,7 +133,7 @@ class TestValidateAssignment:
|
||||
rate = ExchangeRate(from_currency="USD", to_currency="RUB", rate=Decimal("80"))
|
||||
with pytest.raises(ValidationError) as exc_info:
|
||||
rate.rate = Decimal("-5")
|
||||
assert "rate must be positive" in str(exc_info.value)
|
||||
assert "курс должен быть положительным" in str(exc_info.value)
|
||||
# Значение не изменилось — невалидное присваивание отклонено целиком.
|
||||
assert rate.rate == Decimal("80")
|
||||
|
||||
@@ -156,14 +156,14 @@ class TestValidateAssignment:
|
||||
account = Account(name="A", balance=Decimal("100"))
|
||||
with pytest.raises(ValidationError) as exc_info:
|
||||
account.balance = Decimal("-1")
|
||||
assert "balance must be non-negative" in str(exc_info.value)
|
||||
assert "баланс не может быть отрицательным" in str(exc_info.value)
|
||||
assert account.balance == Decimal("100")
|
||||
|
||||
def test_transaction_amount_rejected_on_assignment(self):
|
||||
txn = Transaction(amount=Decimal("100"))
|
||||
with pytest.raises(ValidationError) as exc_info:
|
||||
txn.amount = Decimal("0")
|
||||
assert "amount must be non-zero" in str(exc_info.value)
|
||||
assert "сумма не может быть нулевой" in str(exc_info.value)
|
||||
assert txn.amount == Decimal("100")
|
||||
|
||||
def test_recurring_amount_and_frequency_rejected_on_assignment(self):
|
||||
@@ -277,7 +277,7 @@ class TestPydanticValidators:
|
||||
def test_account_balance_rejects_negative(self):
|
||||
with pytest.raises(ValidationError) as exc_info:
|
||||
Account(balance=Decimal("-1"))
|
||||
assert "balance must be non-negative" in str(exc_info.value)
|
||||
assert "баланс не может быть отрицательным" in str(exc_info.value)
|
||||
|
||||
def test_account_balance_allows_zero(self):
|
||||
assert Account(balance=Decimal("0")).balance == Decimal("0")
|
||||
@@ -285,14 +285,14 @@ class TestPydanticValidators:
|
||||
def test_account_balance_rejects_small_negative(self):
|
||||
with pytest.raises(ValidationError) as exc_info:
|
||||
Account(balance=Decimal("-0.01"))
|
||||
assert "balance must be non-negative" in str(exc_info.value)
|
||||
assert "баланс не может быть отрицательным" in str(exc_info.value)
|
||||
|
||||
# --- 2. Transaction.amount — ненулевой (отрицательные разрешены) ---
|
||||
|
||||
def test_transaction_amount_rejects_zero(self):
|
||||
with pytest.raises(ValidationError) as exc_info:
|
||||
Transaction(amount=Decimal("0"))
|
||||
assert "amount must be non-zero" in str(exc_info.value)
|
||||
assert "сумма не может быть нулевой" in str(exc_info.value)
|
||||
|
||||
def test_transaction_amount_allows_negative(self):
|
||||
# Расходы записываются отрицательными суммами — это валидное значение.
|
||||
@@ -306,19 +306,19 @@ class TestPydanticValidators:
|
||||
def test_recurring_frequency_rejects_unknown_value(self):
|
||||
with pytest.raises(ValidationError) as exc_info:
|
||||
RecurringCashflow(frequency="hourly")
|
||||
assert "unknown frequency: hourly" in str(exc_info.value)
|
||||
assert "неизвестная периодичность: hourly" in str(exc_info.value)
|
||||
|
||||
def test_recurring_frequency_rejects_empty_string(self):
|
||||
with pytest.raises(ValidationError) as exc_info:
|
||||
RecurringCashflow(frequency="")
|
||||
assert "unknown frequency:" in str(exc_info.value)
|
||||
assert "неизвестная периодичность:" in str(exc_info.value)
|
||||
|
||||
# --- 4. RecurringCashflow.amount — ненулевой ---
|
||||
|
||||
def test_recurring_amount_rejects_zero(self):
|
||||
with pytest.raises(ValidationError) as exc_info:
|
||||
RecurringCashflow(amount=Decimal("0"))
|
||||
assert "amount must be non-zero" in str(exc_info.value)
|
||||
assert "сумма не может быть нулевой" in str(exc_info.value)
|
||||
|
||||
def test_recurring_amount_allows_non_zero(self):
|
||||
assert RecurringCashflow(amount=Decimal("1")).amount == Decimal("1")
|
||||
@@ -329,14 +329,14 @@ class TestPydanticValidators:
|
||||
with pytest.raises(ValidationError) as exc_info:
|
||||
Liability(interest=Decimal("-1"))
|
||||
text = str(exc_info.value)
|
||||
assert "must be non-negative" in text
|
||||
assert "значение не может быть отрицательным" in text
|
||||
assert "interest" in text
|
||||
|
||||
def test_liability_payment_rejects_negative(self):
|
||||
with pytest.raises(ValidationError) as exc_info:
|
||||
Liability(payment=Decimal("-1"))
|
||||
text = str(exc_info.value)
|
||||
assert "must be non-negative" in text
|
||||
assert "значение не может быть отрицательным" in text
|
||||
assert "payment" in text
|
||||
|
||||
def test_liability_allows_zero_interest_and_payment(self):
|
||||
@@ -350,21 +350,21 @@ class TestPydanticValidators:
|
||||
with pytest.raises(ValidationError) as exc_info:
|
||||
ForecastScenario(income_multiplier=Decimal("-1"))
|
||||
text = str(exc_info.value)
|
||||
assert "multiplier must be non-negative" in text
|
||||
assert "множитель не может быть отрицательным" in text
|
||||
assert "income_multiplier" in text
|
||||
|
||||
def test_scenario_expense_multiplier_rejects_negative(self):
|
||||
with pytest.raises(ValidationError) as exc_info:
|
||||
ForecastScenario(expense_multiplier=Decimal("-1"))
|
||||
text = str(exc_info.value)
|
||||
assert "multiplier must be non-negative" in text
|
||||
assert "множитель не может быть отрицательным" in text
|
||||
assert "expense_multiplier" in text
|
||||
|
||||
def test_scenario_growth_multiplier_rejects_negative(self):
|
||||
with pytest.raises(ValidationError) as exc_info:
|
||||
ForecastScenario(growth_multiplier=Decimal("-1"))
|
||||
text = str(exc_info.value)
|
||||
assert "multiplier must be non-negative" in text
|
||||
assert "множитель не может быть отрицательным" in text
|
||||
assert "growth_multiplier" in text
|
||||
|
||||
def test_scenario_allows_zero_multipliers(self):
|
||||
@@ -382,12 +382,12 @@ class TestPydanticValidators:
|
||||
def test_exchange_rate_rejects_zero(self):
|
||||
with pytest.raises(ValidationError) as exc_info:
|
||||
ExchangeRate(rate=Decimal("0"))
|
||||
assert "rate must be positive" in str(exc_info.value)
|
||||
assert "курс должен быть положительным" in str(exc_info.value)
|
||||
|
||||
def test_exchange_rate_rejects_negative(self):
|
||||
with pytest.raises(ValidationError) as exc_info:
|
||||
ExchangeRate(rate=Decimal("-1"))
|
||||
assert "rate must be positive" in str(exc_info.value)
|
||||
assert "курс должен быть положительным" in str(exc_info.value)
|
||||
|
||||
def test_exchange_rate_allows_small_positive(self):
|
||||
assert ExchangeRate(rate=Decimal("0.01")).rate == Decimal("0.01")
|
||||
|
||||
Reference in new issue
Block a user