(self)
| 323 | |
| 324 | @override_settings(LOCALE_PATHS=extended_locale_paths) |
| 325 | def test_ngettext_lazy_format_style(self): |
| 326 | simple_with_format = ngettext_lazy("{} good result", "{} good results") |
| 327 | simple_context_with_format = npgettext_lazy( |
| 328 | "Exclamation", "{} good result", "{} good results" |
| 329 | ) |
| 330 | |
| 331 | with translation.override("de"): |
| 332 | self.assertEqual(simple_with_format.format(1), "1 gutes Resultat") |
| 333 | self.assertEqual(simple_with_format.format(4), "4 guten Resultate") |
| 334 | self.assertEqual(simple_context_with_format.format(1), "1 gutes Resultat!") |
| 335 | self.assertEqual(simple_context_with_format.format(4), "4 guten Resultate!") |
| 336 | |
| 337 | complex_nonlazy = ngettext_lazy( |
| 338 | "Hi {name}, {num} good result", "Hi {name}, {num} good results", 4 |
| 339 | ) |
| 340 | complex_deferred = ngettext_lazy( |
| 341 | "Hi {name}, {num} good result", "Hi {name}, {num} good results", "num" |
| 342 | ) |
| 343 | complex_context_nonlazy = npgettext_lazy( |
| 344 | "Greeting", |
| 345 | "Hi {name}, {num} good result", |
| 346 | "Hi {name}, {num} good results", |
| 347 | 4, |
| 348 | ) |
| 349 | complex_context_deferred = npgettext_lazy( |
| 350 | "Greeting", |
| 351 | "Hi {name}, {num} good result", |
| 352 | "Hi {name}, {num} good results", |
| 353 | "num", |
| 354 | ) |
| 355 | with translation.override("de"): |
| 356 | self.assertEqual( |
| 357 | complex_nonlazy.format(num=4, name="Jim"), |
| 358 | "Hallo Jim, 4 guten Resultate", |
| 359 | ) |
| 360 | self.assertEqual( |
| 361 | complex_deferred.format(name="Jim", num=1), |
| 362 | "Hallo Jim, 1 gutes Resultat", |
| 363 | ) |
| 364 | self.assertEqual( |
| 365 | complex_deferred.format(name="Jim", num=5), |
| 366 | "Hallo Jim, 5 guten Resultate", |
| 367 | ) |
| 368 | with self.assertRaisesMessage(KeyError, "Your dictionary lacks key"): |
| 369 | complex_deferred.format(name="Jim") |
| 370 | self.assertEqual( |
| 371 | complex_context_nonlazy.format(num=4, name="Jim"), |
| 372 | "Willkommen Jim, 4 guten Resultate", |
| 373 | ) |
| 374 | self.assertEqual( |
| 375 | complex_context_deferred.format(name="Jim", num=1), |
| 376 | "Willkommen Jim, 1 gutes Resultat", |
| 377 | ) |
| 378 | self.assertEqual( |
| 379 | complex_context_deferred.format(name="Jim", num=5), |
| 380 | "Willkommen Jim, 5 guten Resultate", |
| 381 | ) |
| 382 | with self.assertRaisesMessage(KeyError, "Your dictionary lacks key"): |
nothing calls this directly
no test coverage detected