How to use test_missing_format method in tavern

Best Python code snippet using tavern

test_format_checks.py

Source:test_format_checks.py Github

copy

Full Screen

...75 def test_named_format(self):76 self.assertFalse(77 self.check.check_format("%(name)s string", "%(name)s string", False, None)78 )79 def test_missing_format(self):80 self.assertTrue(self.check.check_format("%s string", "string", False, None))81 def test_missing_named_format(self):82 self.assertTrue(83 self.check.check_format("%(name)s string", "string", False, None)84 )85 def test_missing_named_format_ignore(self):86 self.assertFalse(87 self.check.check_format("%(name)s string", "string", True, None)88 )89 def test_wrong_format(self):90 self.assertTrue(self.check.check_format("%s string", "%c string", False, None))91 def test_reordered_format(self):92 self.assertTrue(93 self.check.check_format("%s %d string", "%d %s string", False, None)94 )95 def test_wrong_named_format(self):96 self.assertTrue(97 self.check.check_format("%(name)s string", "%(jmeno)s string", False, None)98 )99 def test_reordered_named_format(self):100 self.assertFalse(101 self.check.check_format(102 "%(name)s %(foo)s string", "%(foo)s %(name)s string", False, None103 )104 )105 def test_reordered_named_format_long(self):106 self.assertFalse(107 self.check.check_format(108 "%(count)d strings into %(languages)d languages %(percent)d%%",109 "%(languages)d dil içinde %(count)d satır %%%(percent)d",110 False,111 None,112 )113 )114 def test_feedback(self):115 self.assertEqual(116 self.check.check_format("%(count)d", "%(languages)d", False, None),117 {"missing": ["(count)d"], "extra": ["(languages)d"]},118 )119 self.assertEqual(120 self.check.check_format("%(count)d", "count", False, None),121 {"missing": ["(count)d"], "extra": []},122 )123 self.assertEqual(124 self.check.check_format(125 "%(count)d", "%(count)d %(languages)d", False, None126 ),127 {"missing": [], "extra": ["(languages)d"]},128 )129 self.assertEqual(130 self.check.check_format("%d", "%s", False, None),131 {"missing": ["d"], "extra": ["s"]},132 )133 self.assertEqual(134 self.check.check_format("%d", "ds", False, None),135 {"missing": ["d"], "extra": []},136 )137 self.assertEqual(138 self.check.check_format("%d", "%d %s", False, None),139 {"missing": [], "extra": ["s"]},140 )141 self.assertEqual(142 self.check.check_format("%d %d", "%d", False, None),143 {"missing": ["d"], "extra": []},144 )145 def test_description(self):146 unit = Unit(147 source="%(count)d",148 target="%(languages)d",149 extra_flags="python-format",150 )151 check = Check(unit=unit)152 self.assertEqual(153 self.check.get_description(check),154 "Following format strings are missing: %(count)d<br />"155 "Following format strings are extra: %(languages)d",156 )157 def test_description_nolocation(self):158 unit = Unit(159 source="%d %s",160 target="%s %d",161 extra_flags="python-format",162 )163 check = Check(unit=unit)164 self.assertEqual(165 self.check.get_description(check),166 "Following format strings are wrongly ordered: %d, %s",167 )168class PHPFormatCheckTest(CheckTestCase):169 check = PHPFormatCheck()170 def setUp(self):171 super().setUp()172 self.test_highlight = (173 "php-format",174 "%sstring%d",175 [(0, 2, "%s"), (8, 10, "%d")],176 )177 def test_no_format(self):178 self.assertFalse(self.check.check_format("strins", "string", False, None))179 def test_format(self):180 self.assertFalse(self.check.check_format("%s string", "%s string", False, None))181 def test_named_format(self):182 self.assertFalse(183 self.check.check_format("%1$s string", "%1$s string", False, None)184 )185 def test_missing_format(self):186 self.assertTrue(self.check.check_format("%s string", "string", False, None))187 def test_missing_named_format(self):188 self.assertTrue(self.check.check_format("%1$s string", "string", False, None))189 def test_missing_named_format_ignore(self):190 self.assertFalse(self.check.check_format("%1$s string", "string", True, None))191 def test_wrong_format(self):192 self.assertTrue(self.check.check_format("%s string", "%c string", False, None))193 def test_double_format(self):194 self.assertTrue(195 self.check.check_format("%s string", "%s%s string", False, None)196 )197 def test_reorder_format(self):198 self.assertFalse(199 self.check.check_format("%1$s %2$s string", "%2$s %1$s string", False, None)200 )201 def test_wrong_named_format(self):202 self.assertTrue(203 self.check.check_format("%1$s string", "%s string", False, None)204 )205 def test_wrong_percent_format(self):206 self.assertTrue(207 self.check.check_format("%s%% (0.1%%)", "%s%% (0.1%x)", False, None)208 )209 def test_missing_percent_format(self):210 self.assertFalse(211 self.check.check_format("%s%% %%", "%s%% percent", False, None)212 )213 def test_space_format(self):214 self.assertTrue(215 self.check.check_format("%d % string", "%d % other", False, None)216 )217class SchemeFormatCheckTest(CheckTestCase):218 check = SchemeFormatCheck()219 def setUp(self):220 super().setUp()221 self.test_highlight = (222 "scheme-format",223 "~sstring~d",224 [(0, 2, "~s"), (8, 10, "~d")],225 )226 def test_no_format(self):227 self.assertFalse(self.check.check_format("strins", "string", False, None))228 def test_format(self):229 self.assertFalse(self.check.check_format("~s string", "~s string", False, None))230 def test_named_format(self):231 self.assertFalse(232 self.check.check_format("~0@*~s string", "~0@*~s string", False, None)233 )234 def test_missing_format(self):235 self.assertTrue(self.check.check_format("~s string", "string", False, None))236 def test_missing_named_format(self):237 self.assertTrue(self.check.check_format("~1@*~s string", "string", False, None))238 def test_missing_named_format_ignore(self):239 self.assertFalse(self.check.check_format("~1@*~s string", "string", True, None))240 def test_wrong_format(self):241 self.assertTrue(self.check.check_format("~s string", "~c string", False, None))242 def test_double_format(self):243 self.assertTrue(244 self.check.check_format("~s string", "~s~s string", False, None)245 )246 def test_reorder_format(self):247 self.assertFalse(248 self.check.check_format(249 "~1@*~s ~2@*~s string", "~2@*~s ~1@*~s string", False, None250 )251 )252 def test_wrong_named_format(self):253 self.assertTrue(254 self.check.check_format("~1@*~s string", "~s string", False, None)255 )256 def test_wrong_tilde_format(self):257 self.assertTrue(258 self.check.check_format("~s~~ (0.1~~)", "~s~~ (0.1~x)", False, None)259 )260 def test_missing_tilde_format(self):261 self.assertFalse(self.check.check_format("~s~~ ~~", "~s~~ tilde", False, None))262class CFormatCheckTest(CheckTestCase):263 check = CFormatCheck()264 flag = "c-format"265 def setUp(self):266 super().setUp()267 self.test_highlight = (self.flag, "%sstring%d", [(0, 2, "%s"), (8, 10, "%d")])268 def test_no_format(self):269 self.assertFalse(self.check.check_format("strins", "string", False, None))270 def test_format(self):271 self.assertFalse(self.check.check_format("%s string", "%s string", False, None))272 def test_named_format(self):273 self.assertFalse(274 self.check.check_format("%10s string", "%10s string", False, None)275 )276 def test_missing_format(self):277 self.assertTrue(self.check.check_format("%s string", "string", False, None))278 def test_missing_named_format(self):279 self.assertTrue(self.check.check_format("%10s string", "string", False, None))280 def test_missing_named_format_ignore(self):281 self.assertFalse(self.check.check_format("%10s string", "string", True, None))282 def test_wrong_format(self):283 self.assertTrue(self.check.check_format("%s string", "%c string", False, None))284 def test_wrong_named_format(self):285 self.assertTrue(286 self.check.check_format("%10s string", "%20s string", False, None)287 )288 def test_reorder_format(self):289 self.assertFalse(290 self.check.check_format("%1$s %2$s string", "%2$s %1$s string", False, None)291 )292 def test_locale_delimiter(self):293 self.assertFalse(294 self.check.check_format("lines: %6.3f", "radky: %'6.3f", False, None)295 )296 def test_ld_format(self):297 self.assertFalse(298 self.check.check_format(299 "%ld bytes (free %ld bytes, used %ld bytes)",300 "%l octets (%l octets libres, %l octets utilisés)",301 True,302 None,303 )304 )305 def test_parenthesis(self):306 self.assertFalse(self.check.check_format("(%.0lf%%)", "(%%%.0lf)", False, None))307class LuaFormatCheckTest(CFormatCheckTest):308 check = LuaFormatCheck()309 flag = "lua-format"310class ObjectPascalFormatCheckTest(CheckTestCase):311 check = ObjectPascalFormatCheck()312 flag = "object-pascal-format"313 def setUp(self):314 super().setUp()315 self.test_highlight = (316 self.flag,317 "%-9sstring%d",318 [(0, 4, "%-9s"), (10, 12, "%d")],319 )320 def test_no_format(self):321 self.assertFalse(self.check.check_format("strins", "string", False, None))322 def test_format(self):323 self.assertFalse(self.check.check_format("%s string", "%s string", False, None))324 def test_width_format(self):325 self.assertFalse(326 self.check.check_format("%10s string", "%10s string", False, None)327 )328 def test_missing_format(self):329 self.assertTrue(self.check.check_format("%s string", "string", False, None))330 def test_added_format(self):331 self.assertTrue(self.check.check_format("string", "%s string", False, None))332 def test_missing_width_format(self):333 self.assertTrue(self.check.check_format("%10s string", "string", False, None))334 def test_missing_width_format_ignore(self):335 self.assertFalse(self.check.check_format("%10s string", "string", True, None))336 def test_wrong_format(self):337 self.assertTrue(self.check.check_format("%s string", "%d string", False, None))338 def test_invalid_format(self):339 self.assertTrue(self.check.check_format("%d string", "%c string", False, None))340 def test_looks_like_format(self):341 self.assertFalse(self.check.check_format("%c string", "%c string", False, None))342 def test_percent_format(self):343 self.assertFalse(344 self.check.check_format("%6.2f%% string", "%6.2f%% string", False, None)345 )346 def test_wrong_digits(self):347 self.assertTrue(348 self.check.check_format("%6.2f string", "%5.3f string", False, None)349 )350 def test_wrong_wildcard(self):351 self.assertTrue(352 self.check.check_format("%*s string", "%10s string", False, None)353 )354 def test_reorder_format(self):355 self.assertFalse(356 self.check.check_format("%1:s %2:d string", "%2:d %1:s string", False, None)357 )358class PerlFormatCheckTest(CFormatCheckTest):359 check = PerlFormatCheck()360 flag = "perl-format"361class PythonBraceFormatCheckTest(CheckTestCase):362 check = PythonBraceFormatCheck()363 def setUp(self):364 super().setUp()365 self.test_highlight = (366 "python-brace-format",367 "{0}string{1}",368 [(0, 3, "{0}"), (9, 12, "{1}")],369 )370 def test_no_format(self):371 self.assertFalse(self.check.check_format("strins", "string", False, None))372 def test_position_format(self):373 self.assertFalse(374 self.check.check_format("{} string {}", "{} string {}", False, None)375 )376 def test_wrong_position_format(self):377 self.assertTrue(378 self.check.check_format("{} string", "{} string {}", False, None)379 )380 def test_named_format(self):381 self.assertFalse(382 self.check.check_format("{s1} string {s2}", "{s1} string {s2}", False, None)383 )384 def test_missing_format(self):385 self.assertTrue(self.check.check_format("{} string", "string", False, None))386 def test_missing_named_format(self):387 self.assertTrue(self.check.check_format("{s1} string", "string", False, None))388 def test_missing_named_format_ignore(self):389 self.assertFalse(self.check.check_format("{s} string", "string", True, None))390 def test_wrong_format(self):391 self.assertTrue(392 self.check.check_format("{s} string", "{c} string", False, None)393 )394 def test_escaping(self):395 self.assertFalse(self.check.check_format("{{ string }}", "string", False, None))396 def test_attribute_format(self):397 self.assertFalse(398 self.check.check_format("{s.foo} string", "{s.foo} string", False, None)399 )400 def test_wrong_attribute_format(self):401 self.assertTrue(402 self.check.check_format("{s.foo} string", "{s.bar} string", False, None)403 )404class CSharpFormatCheckTest(CheckTestCase):405 check = CSharpFormatCheck()406 def setUp(self):407 super().setUp()408 self.test_highlight = (409 "c-sharp-format",410 "{0}string{1}",411 [(0, 3, "{0}"), (9, 12, "{1}")],412 )413 def test_no_format(self):414 self.assertFalse(self.check.check_format("strins", "string", False, None))415 def test_escaping_no_position(self):416 self.assertFalse(self.check.check_format("{{ string }}", "string", False, None))417 def test_simple_format(self):418 self.assertFalse(419 self.check.check_format("{0} strins", "{0} string", False, None)420 )421 def test_format_with_width(self):422 self.assertFalse(423 self.check.check_format("{0,1} strins", "{0,1} string", False, None)424 )425 def test_format_with_flag(self):426 self.assertFalse(427 self.check.check_format("{0:C2} strins", "{0:C2} string", False, None)428 )429 def test_full_format(self):430 self.assertFalse(431 self.check.check_format("{0,1:N0} strins", "{0,1:N0} string", False, None)432 )433 def test_missing_format(self):434 self.assertTrue(self.check.check_format("{0} strins", "string", False, None))435 def test_missing_width_format(self):436 self.assertTrue(self.check.check_format("{0,1} strins", "string", False, None))437 def test_missing_flag_format(self):438 self.assertTrue(self.check.check_format("{0:C1} strins", "string", False, None))439 def test_missing_full_format(self):440 self.assertTrue(441 self.check.check_format("{0,1:C3} strins", "string", False, None)442 )443 def test_wrong_format(self):444 self.assertTrue(445 self.check.check_format("{0} string", "{1} string", False, None)446 )447 def test_missing_named_format_ignore(self):448 self.assertFalse(self.check.check_format("{0} string", "string", True, None))449 def test_escaping_with_position(self):450 self.assertFalse(self.check.check_format("{{ 0 }}", "string", False, None))451 def test_wrong_attribute_format(self):452 self.assertTrue(453 self.check.check_format("{0} string", "{1} string", False, None)454 )455 def test_reordered_format(self):456 self.assertFalse(457 self.check.check_format("{0} string {1}", "{1} string {0}", False, None)458 )459class JavaFormatCheckTest(CheckTestCase):460 check = JavaFormatCheck()461 def setUp(self):462 super().setUp()463 self.test_highlight = (464 "java-format",465 "%1s string %2s",466 [(0, 3, "%1s"), (11, 14, "%2s")],467 )468 def test_no_format(self):469 self.assertFalse(self.check.check_format("strins", "string", False, None))470 def test_escaping(self):471 self.assertFalse(self.check.check_format("%% s %%", "string", False, None))472 def test_format(self):473 self.assertFalse(self.check.check_format("%s string", "%s string", False, None))474 def test_time_format(self):475 self.assertFalse(476 self.check.check_format("%1$tH strins", "%1$tH string", False, None)477 )478 def test_wrong_position_format(self):479 self.assertTrue(480 self.check.check_format("%s string", "%s string %s", False, None)481 )482 def test_named_format(self):483 self.assertFalse(484 self.check.check_format("%1s string %2s", "%1s string %2s", False, None)485 )486 def test_missing_format(self):487 self.assertTrue(self.check.check_format("%1s string", "string", False, None))488 def test_missing_named_format(self):489 self.assertTrue(self.check.check_format("%1$05d string", "string", False, None))490 def test_wrong_argument_format(self):491 self.assertTrue(492 self.check.check_format("%1s string", "%2s string", False, None)493 )494 def test_wrong_format(self):495 self.assertTrue(self.check.check_format("%s strins", "%d string", False, None))496 def test_missing_named_format_ignore(self):497 self.assertFalse(self.check.check_format("%1s string", "string", True, None))498 def test_reordered_format(self):499 self.assertTrue(500 self.check.check_format("%1s string %2d", "%2d string %1s", False, None)501 )502class JavaMessageFormatCheckTest(CheckTestCase):503 check = JavaMessageFormatCheck()504 def setUp(self):505 super().setUp()506 self.test_highlight = (507 "java-messageformat",508 "{0}string{1}",509 [(0, 3, "{0}"), (9, 12, "{1}")],510 )511 self.unit = MockUnit(source="source")512 def test_no_format(self):513 self.assertFalse(self.check.check_format("strins", "string", False, self.unit))514 def test_escaping_no_position(self):515 self.assertFalse(516 self.check.check_format("{{ string }}", "string", False, self.unit)517 )518 def test_simple_format(self):519 self.assertFalse(520 self.check.check_format("{0} strins", "{0} string", False, self.unit)521 )522 def test_format_with_width(self):523 self.assertFalse(524 self.check.check_format("{0,1} strins", "{0,1} string", False, self.unit)525 )526 def test_format_with_flag(self):527 self.assertFalse(528 self.check.check_format("{0:C2} strins", "{0:C2} string", False, self.unit)529 )530 def test_full_format(self):531 self.assertFalse(532 self.check.check_format(533 "{0,1:N0} strins", "{0,1:N0} string", False, self.unit534 )535 )536 def test_missing_format(self):537 self.assertTrue(538 self.check.check_format("{0} strins", "string", False, self.unit)539 )540 def test_missing_type_format(self):541 self.assertTrue(542 self.check.check_format("{0,number} strins", "string", False, self.unit)543 )544 def test_missing_flag_format(self):545 self.assertTrue(546 self.check.check_format("{0} strins", "string", False, self.unit)547 )548 def test_missing_full_format(self):549 self.assertTrue(550 self.check.check_format(551 "{0,number,integer} strins", "string", False, self.unit552 )553 )554 def test_wrong_format(self):555 self.assertTrue(556 self.check.check_format("{0} string", "{1} string", False, self.unit)557 )558 def test_missing_named_format_ignore(self):559 self.assertFalse(560 self.check.check_format("{0} string", "string", True, self.unit)561 )562 def test_escaping_with_position(self):563 self.assertFalse(self.check.check_format("{{ 0 }}", "string", False, self.unit))564 def test_wrong_attribute_format(self):565 self.assertTrue(566 self.check.check_format("{0} string", "{1} string", False, self.unit)567 )568 def test_reordered_format(self):569 self.assertFalse(570 self.check.check_format(571 "{0} string {1}", "{1} string {0}", False, self.unit572 )573 )574 def test_skip(self):575 unit = MockUnit(source="source")576 self.assertTrue(self.check.should_skip(unit))577 unit = MockUnit(source="source", flags="java-messageformat")578 self.assertFalse(self.check.should_skip(unit))579 unit = MockUnit(source="source", flags="auto-java-messageformat")580 self.assertTrue(self.check.should_skip(unit))581 unit = MockUnit(source="{0}", flags="auto-java-messageformat")582 self.assertFalse(self.check.should_skip(unit))583 def test_quotes(self):584 self.assertFalse(585 self.check.check_format(586 "{0} string {1}", "'{1}' strin''g '{0}'", False, self.unit587 )588 )589 self.assertTrue(590 self.check.check_format(591 "{0} string {1}", "'{1}' strin''g '{0}", False, self.unit592 )593 )594 self.assertTrue(595 self.check.check_format(596 "{0} string {1}", "'{1}' strin'g '{0}'", False, self.unit597 )598 )599 def test_description(self):600 unit = Unit(601 source="{0}''s brush is {1} centimeters tall",602 target="{0}'s brush is {1} centimeters tall",603 extra_flags="java-messageformat",604 translation=Translation(605 component=Component(606 file_format="auto",607 source_language=Language("en"),608 ),609 language=Language("cs"),610 ),611 )612 check = Check(unit=unit)613 self.assertEqual(614 self.check.get_description(check),615 "You need to pair up an apostrophe with another one.",616 )617class QtFormatCheckTest(CheckTestCase):618 check = QtFormatCheck()619 flag = "qt-format"620 def setUp(self):621 super().setUp()622 self.test_highlight = (self.flag, "%1string%2", [(0, 2, "%1"), (8, 10, "%2")])623 def test_no_format(self):624 self.assertFalse(self.check.check_format("strins", "string", False, None))625 def test_simple_format(self):626 self.assertFalse(self.check.check_format("%1 strins", "%1 string", False, None))627 def test_missing_format(self):628 self.assertTrue(self.check.check_format("%1 strins", "string", False, None))629 def test_wrong_format(self):630 self.assertTrue(self.check.check_format("%1 string", "%2 string", False, None))631 def test_reordered_format(self):632 self.assertFalse(633 self.check.check_format("%1 string %2", "%2 string %1", False, None)634 )635 def test_reused_format(self):636 self.assertFalse(637 self.check.check_format("%1 string %1", "%1 string %1", False, None)638 )639class QtPluralCheckTest(CheckTestCase):640 check = QtPluralCheck()641 flag = "qt-plural-format"642 def setUp(self):643 super().setUp()644 self.test_highlight = (self.flag, "%Lnstring", [(0, 3, "%Ln")])645 def test_no_format(self):646 self.assertFalse(self.check.check_format("strins", "string", False, None))647 def test_plural_format(self):648 self.assertFalse(649 self.check.check_format("%n string(s)", "%n string", False, None)650 )651 def test_plural_localized_format(self):652 self.assertFalse(653 self.check.check_format("%Ln string(s)", "%Ln string", False, None)654 )655 def test_missing_format(self):656 self.assertTrue(self.check.check_format("%n string(s)", "string", False, None))657class RubyFormatCheckTest(CheckTestCase):658 check = RubyFormatCheck()659 flag = "ruby-format"660 def test_check_highlight(self):661 self.test_highlight = (self.flag, "%dstring%s", [(0, 2, "%d"), (8, 10, "%s")])662 super().test_check_highlight()663 def test_check_highlight_named(self):664 self.test_highlight = (665 self.flag,666 "%<int>dstring%<str>s",667 [(0, 7, "%<int>d"), (13, 20, "%<str>s")],668 )669 super().test_check_highlight()670 def test_check_highlight_named_template(self):671 self.test_highlight = (672 self.flag,673 "%{int}string%{str}",674 [(0, 6, "%{int}"), (12, 18, "%{str}")],675 )676 super().test_check_highlight()677 def test_check_highlight_complex_named_template(self):678 self.test_highlight = (679 self.flag,680 "%8.8{foo}string%+08.2<float>fstring",681 [(0, 9, "%8.8{foo}"), (15, 29, "%+08.2<float>f")],682 )683 super().test_check_highlight()684 def test_no_format(self):685 self.assertFalse(self.check.check_format("strins", "string", False, None))686 def test_format(self):687 self.assertFalse(self.check.check_format("%s string", "%s string", False, None))688 def test_space_format(self):689 self.assertTrue(690 self.check.check_format("%d % string", "%d % other", False, None)691 )692 def test_percent_format(self):693 self.assertFalse(694 self.check.check_format("%d%% string", "%d%% string", False, None)695 )696 def test_named_format(self):697 self.assertFalse(698 self.check.check_format("%<name>s string", "%<name>s string", False, None)699 )700 def test_missing_format(self):701 self.assertTrue(self.check.check_format("%s string", "string", False, None))702 def test_missing_named_format(self):703 self.assertTrue(704 self.check.check_format("%<name>s string", "string", False, None)705 )706 def test_missing_named_format_ignore(self):707 self.assertFalse(708 self.check.check_format("%<name>s string", "string", True, None)709 )710 def test_wrong_format(self):711 self.assertTrue(self.check.check_format("%s string", "%c string", False, None))712 def test_reordered_format(self):713 self.assertTrue(714 self.check.check_format("%s %d string", "%d %s string", False, None)715 )716 def test_wrong_named_format(self):717 self.assertTrue(718 self.check.check_format("%<name>s string", "%<jmeno>s string", False, None)719 )720 def test_reordered_named_format(self):721 self.assertFalse(722 self.check.check_format(723 "%<name>s %<foo>s string",724 "%<foo>s %<name>s string",725 False,726 None,727 )728 )729 def test_reordered_named_format_long(self):730 self.assertFalse(731 self.check.check_format(732 "%<count>d strings into %<languages>d languages %<percent>d%%",733 "%<languages>d dil içinde %<count>d satır %%%<percent>d",734 False,735 None,736 )737 )738 def test_formatting_named_format(self):739 self.assertFalse(740 self.check.check_format(741 "%+08.2<foo>f string", "%+08.2<foo>f string", False, None742 )743 )744 def test_missing_named_template_format(self):745 self.assertTrue(746 self.check.check_format("%{name} string", "string", False, None)747 )748 def test_missing_named_template_format_ignore(self):749 self.assertFalse(750 self.check.check_format("%{name} string", "string", True, None)751 )752 def test_wrong_named_template_format(self):753 self.assertTrue(754 self.check.check_format("%{name} string", "%{jmeno} string", False, None)755 )756 def test_reordered_named_template_format(self):757 self.assertFalse(758 self.check.check_format(759 "%{name} %{foo} string",760 "%{foo} %{name} string",761 False,762 None,763 )764 )765 def test_formatting_named_template_format(self):766 self.assertFalse(767 self.check.check_format("%8.8{foo} string", "%8.8{foo} string", False, None)768 )769 def test_reordered_named_template_format_long(self):770 self.assertFalse(771 self.check.check_format(772 "%{count} strings into %{languages} languages %{percent}%%",773 "%{languages} dil içinde %{count} satır %%%{percent}",774 False,775 None,776 )777 )778class PluralTest(FixtureTestCase):779 check = PythonFormatCheck()780 def do_check(self, sources, targets, translation):781 return self.check.check_target_unit(782 sources,783 targets,784 Unit(785 translation=translation,786 source=join_plural(sources),787 target=join_plural(targets),788 ),789 )790 def test_arabic(self):791 arabic = Language.objects.get(code="ar")792 translation = Translation(language=arabic, plural=arabic.plural)793 # Singular, correct format string794 self.assertFalse(self.do_check(["hello %s"], ["hell %s"], translation))795 # Singular, missing format string796 self.assertTrue(self.do_check(["hello %s"], ["hell"], translation))797 # Plural, correct format string798 self.assertFalse(self.do_check(["hello %s"] * 2, ["hell %s"] * 6, translation))799 # Plural, missing format string800 self.assertTrue(self.do_check(["hello %s"] * 2, ["hell"] * 6, translation))801 # Plural, correct format string (missing on single value plurals)802 self.assertFalse(803 self.do_check(804 ["hello %s"] * 2, ["hell"] * 3 + ["hello %s"] * 3, translation805 )806 )807 # Plural, missing format string on multi value plural808 self.assertTrue(809 self.do_check(810 ["hello %s"] * 2, ["hell"] * 4 + ["hello %s"] * 2, translation811 )812 )813 def test_non_format_singular(self):814 czech = Language.objects.get(code="cs")815 translation = Translation(language=czech, plural=czech.plural)816 self.assertFalse(817 self.do_check(818 ["One apple", "%d apples"],819 ["%d jablko", "%d jablka", "%d jablek"],820 translation,821 )822 )823 self.assertFalse(824 self.do_check(825 ["One apple", "%d apples"],826 ["Jedno jablko", "%d jablka", "%d jablek"],827 translation,828 )829 )830 self.assertTrue(831 self.do_check(832 ["One apple", "%d apples"],833 ["Jedno jablko", "jablka", "%d jablek"],834 translation,835 )836 )837 def test_non_format_singular_named(self):838 language = Language.objects.get(code="cs")839 translation = Translation(language=language, plural=language.plural)840 self.assertFalse(841 self.do_check(842 ["One apple", "%(count)s apples"],843 ["%(count)s jablko", "%(count)s jablka", "%(count)s jablek"],844 translation,845 )846 )847 self.assertFalse(848 self.do_check(849 ["One apple", "%(count)s apples"],850 ["Jedno jablko", "%(count)s jablka", "%(count)s jablek"],851 translation,852 )853 )854 self.assertTrue(855 self.do_check(856 ["One apple", "%(count)s apples"],857 ["Jedno jablko", "jablka", "%(count)s jablek"],858 translation,859 )860 )861 def test_non_format_singular_named_be(self):862 language = Language.objects.get(code="be")863 translation = Translation(language=language, plural=language.plural)864 self.assertTrue(865 self.do_check(866 ["One apple", "%(count)s apples"],867 ["Jedno jablko", "%(count)s jablka", "%(count)s jablek"],868 translation,869 )870 )871 def test_non_format_singular_named_kab(self):872 language = Language.objects.get(code="kab")873 translation = Translation(language=language, plural=language.plural)874 self.assertFalse(875 self.do_check(876 ["One apple", "%(count)s apples"],877 ["Jedno jablko", "%(count)s jablka", "%(count)s jablek"],878 translation,879 )880 )881 def test_french_singular(self):882 language = Language.objects.get(code="fr")883 translation = Translation(language=language, plural=language.plural)884 self.assertFalse(885 self.do_check(886 ["One apple", "%(count)s apples"],887 ["Jedno jablko", "%(count)s jablek"],888 translation,889 )890 )891 self.assertFalse(892 self.do_check(893 ["%(count)s apple", "%(count)s apples"],894 ["%(count)s jablko", "%(count)s jablek"],895 translation,896 )897 )898 self.assertFalse(899 self.do_check(900 ["One apple", "%(count)s apples"],901 ["%(count)s jablko", "%(count)s jablek"],902 translation,903 )904 )905 self.assertFalse(906 self.do_check(907 ["%(count)s apple", "%(count)s apples"],908 ["Jedno jablko", "%(count)s jablek"],909 translation,910 )911 )912class I18NextInterpolationCheckTest(CheckTestCase):913 check = I18NextInterpolationCheck()914 def setUp(self):915 super().setUp()916 self.test_highlight = (917 "i18next-interpolation",918 "{{foo}} string {{bar}}",919 [(0, 7, "{{foo}}"), (15, 22, "{{bar}}")],920 )921 def test_no_format(self):922 self.assertFalse(self.check.check_format("strins", "string", False, None))923 def test_format(self):924 self.assertFalse(925 self.check.check_format("{{foo}} string", "{{foo}} string", False, None)926 )927 self.assertFalse(928 self.check.check_format("{{ foo }} string", "{{ foo }} string", False, None)929 )930 self.assertFalse(931 self.check.check_format("{{ foo }} string", "{{foo}} string", False, None)932 )933 def test_nesting(self):934 self.assertFalse(935 self.check.check_format("$t(bar) string", "$t(bar) other", False, None)936 )937 self.assertFalse(938 self.check.check_format("$t( bar ) string", "$t( bar ) other", False, None)939 )940 self.assertFalse(941 self.check.check_format("$t( bar ) string", "$t(bar) other", False, None)942 )943 def test_missing_format(self):944 self.assertTrue(945 self.check.check_format("{{foo}} string", "string", False, None)946 )947 def test_missing_nesting(self):948 self.assertTrue(self.check.check_format("$t(bar) string", "other", False, None))949 def test_wrong_format(self):950 self.assertTrue(951 self.check.check_format("{{foo}} string", "{{bar}} string", False, None)952 )953class ESTemplateLiteralsCheckTest(CheckTestCase):954 check = ESTemplateLiteralsCheck()955 def setUp(self):956 super().setUp()957 self.test_highlight = (958 "es-format",959 "${foo} string ${bar}",960 [(0, 6, "${foo}"), (14, 20, "${bar}")],961 )962 def test_no_format(self):963 self.assertFalse(self.check.check_format("strins", "string", False, None))964 def test_format(self):965 self.assertFalse(966 self.check.check_format("${foo} string", "${foo} string", False, None)967 )968 self.assertFalse(969 self.check.check_format("${ foo } string", "${ foo } string", False, None)970 )971 self.assertFalse(972 self.check.check_format("${ foo } string", "${foo} string", False, None)973 )974 def test_missing_format(self):975 self.assertTrue(self.check.check_format("${foo} string", "string", False, None))976 def test_wrong_format(self):977 self.assertTrue(978 self.check.check_format("${foo} string", "${bar} string", False, None)979 )980 def test_description(self):981 unit = Unit(982 source="${foo}",983 target="${bar}",984 extra_flags="es-format",985 )986 check = Check(unit=unit)987 self.assertEqual(988 self.check.get_description(check),989 "Following format strings are missing: ${foo}<br />"990 "Following format strings are extra: ${bar}",991 )992class PercentPlaceholdersCheckTest(CheckTestCase):993 check = PercentPlaceholdersCheck()994 def setUp(self):995 super().setUp()996 self.test_highlight = (997 "percent-placeholders",998 "%foo% string %bar%",999 [(0, 5, "%foo%"), (13, 18, "%bar%")],1000 )1001 def test_no_format(self):1002 self.assertFalse(self.check.check_format("strins", "string", False, None))1003 def test_format(self):1004 self.assertFalse(1005 self.check.check_format("%foo% string", "%foo% string", False, None)1006 )1007 def test_missing_format(self):1008 self.assertTrue(self.check.check_format("%foo% string", "string", False, None))1009 def test_wrong_format(self):1010 self.assertTrue(1011 self.check.check_format("%foo% string", "%bar% string", False, None)1012 )1013class VueFormattingCheckTest(CheckTestCase):1014 check = VueFormattingCheck()1015 def setUp(self):1016 super().setUp()1017 self.test_highlight = (1018 "vue-format",1019 "{foo} string %{bar}",1020 [(0, 5, "{foo}"), (13, 19, "%{bar}")],1021 )1022 def test_no_format(self):1023 self.assertFalse(self.check.check_format("strins", "string", False, None))1024 def test_format(self):1025 self.assertFalse(1026 self.check.check_format("%{foo} string", "%{foo} string", False, None)1027 )1028 self.assertFalse(1029 self.check.check_format("{foo} string", "{foo} string", False, None)1030 )1031 self.assertFalse(1032 self.check.check_format(1033 "@.lower:message.homeAddress string",1034 "@.lower:message.homeAddress string",1035 False,1036 None,1037 )1038 )1039 self.assertFalse(1040 self.check.check_format(1041 "@:message.the_world string",1042 "@:message.the_world string",1043 False,1044 None,1045 )1046 )1047 self.assertFalse(1048 self.check.check_format(1049 "@:(message.dio) string",1050 "@:(message.dio) string",1051 False,1052 None,1053 )1054 )1055 def test_missing_format(self):1056 self.assertTrue(self.check.check_format("%{foo} string", "string", False, None))1057 self.assertTrue(self.check.check_format("{foo} string", "string", False, None))1058 self.assertTrue(1059 self.check.check_format(1060 "@.lower:message.homeAddress string",1061 "string",1062 False,1063 None,1064 )1065 )1066 self.assertTrue(1067 self.check.check_format("@:message.the_world string", "string", False, None)1068 )1069 self.assertTrue(...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run tavern automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful