def test_whitespace(self): unit = MockUnit(source=u'Foo\n') fix = SameBookendingWhitespace() self.assertEqual(fix.fix_target(['Bar'], unit), ([u'Bar\n'], True)) self.assertEqual(fix.fix_target(['Bar\n'], unit), ([u'Bar\n'], False)) unit = MockUnit(source=u' ') self.assertEqual(fix.fix_target([' '], unit), ([' '], False))
def test_translate(self): machine_translation = DummyTranslation() self.assertEqual( machine_translation.translate('cs', 'Hello', MockUnit(), None), []) self.assertEqual( len( machine_translation.translate('cs', 'Hello, world!', MockUnit(), None)), 2)
def test_same_db_screen(self): self.assertTrue( self.check.check_single('some long text is here', 'some long text is here', MockUnit(code='de'), 0)) self.assertFalse( self.check.check_single('some long text is here', 'some long text is here', MockUnit(code='de', comment='Tag: screen'), 0))
def test_extended_formatting(self): self.assertFalse( self.check.check_single( u'Value: {{ something.value | currency }}', u'Wert: {{ something.value | currency }}', MockUnit('angularjs_format', flags='angularjs-format'))) self.assertTrue( self.check.check_single( u'Value: {{ something.value | currency }}', u'Value: {{ something.value }}', MockUnit('angularjs_format', flags='angularjs-format')))
def test_fmtsourcediff(self): unit = MockUnit(source='Hello word!') self.assertEqual( fmtsourcediff('Hello world!', unit), u'<span lang="en" dir="ltr" class="direction">' 'Hello wor<del>l</del>d!' '</span>')
def test_different_whitespace(self): self.assertFalse(self.check.check_single( u'{{ name }} string', u'{{name}} string', MockUnit('angularjs_different_whitespace', flags='angularjs-format') ))
def test_format_ignore_position(self): self.assertFalse(self.check.check_single( u'{{name}} string {{other}}', u'{{other}} string {{name}}', MockUnit('angularjs_format_ignore_position', flags='angularjs-format') ))
def test_same_english(self): self.assertFalse( self.check.check_single( 'source', 'source', MockUnit(code='en'), ))
def test_controlchars(self): unit = MockUnit(source='Foo\x1b') fix = RemoveControlChars() self.assertEqual(fix.fix_target(['Bar'], unit), (['Bar'], False)) self.assertEqual(fix.fix_target(['Bar\x1b'], unit), (['Bar\x1b'], False)) self.assertEqual(fix.fix_target(['Bar\n'], unit), (['Bar\n'], False))
def test_failing(self): self.assertTrue( self.check.check_source( ['text...'], MockUnit(), ) )
def test_good(self): self.assertFalse( self.check.check_source( ['text…'], MockUnit(), ) )
def test_hit(self): self.assertTrue( self.check.check_target( ['string', 'plural'], ['string', 'string'], MockUnit('plural_partial_empty'), ))
def test_plural(self): self.assertFalse( self.check.check_source( ['text', 'texts'], MockUnit(), ) )
def test_none(self): self.assertFalse( self.check.check_target( ['string'], ['string'], MockUnit('plural_none'), ))
def test_empty(self): self.assertFalse( self.check.check_target( ['string', 'plural'], ['', ''], MockUnit('plural_empty'), ))
def test_none(self): self.assertFalse( self.check.check_source( ['text'], MockUnit(), ) )
def test_good(self): self.assertFalse( self.check.check_target( ['string', 'plural'], ['translation', 'trplural'], MockUnit('plural_good'), ))
def test_format_diff(self): unit = MockUnit(source='Hello word!') self.assertEqual( format_translation( unit.source, unit.translation.subproject.project.source_language, diff='Hello world!', )['items'][0]['content'], u'Hello wor<del>l</del>d!')
def test_locale_delimiter(self): self.assertFalse(self.check.check_format( u'lines: %6.3f', u'radky: %\'6.3f', MockUnit('c_locale_delimiter'), 0, False ))
def test_no_format(self): self.assertFalse(self.check.check_format( 'strins', 'string', MockUnit('python_brace_no_format'), 0, False ))
def test_wrong_format(self): self.assertTrue(self.check.check_format( u'%s string', u'%c string', MockUnit('python_wrong_format'), 0, False ))
def test_named_format(self): self.assertFalse(self.check.check_format( u'{s1} string {s2}', u'{s1} string {s2}', MockUnit('python_brace_named_format'), 0, False ))
def test_named_format(self): self.assertFalse(self.check.check_format( u'%(name)s string', u'%(name)s string', MockUnit('python_named_format'), 0, False ))
def test_percent_format(self): self.assertFalse(self.check.check_format( u'%d%% string', u'%d%% string', MockUnit('python_percent_format'), 0, False ))
def test_wrong_attribute_format(self): self.assertTrue(self.check.check_format( u'{s.foo} string', u'{s.bar} string', MockUnit('python_brace_wrong_attribute_format'), 0, False ))
def test_escaping(self): self.assertFalse(self.check.check_format( u'{{ string }}', u'string', MockUnit('python_brace_escaping'), 0, False ))
def test_wrong_format(self): self.assertTrue(self.check.check_format( u'{s} string', u'{c} string', MockUnit('python_brace_wrong_format'), 0, False ))
def test_missing_named_format_ignore(self): self.assertFalse(self.check.check_format( u'%(name)s string', u'string', MockUnit('python_missing_named_format'), 0, True ))
def test_missing_named_format(self): self.assertTrue(self.check.check_format( u'{s1} string', u'string', MockUnit('python_brace_missing_named_format'), 0, False ))
def test_position_format(self): self.assertFalse(self.check.check_format( u'{} string {}', u'{} string {}', MockUnit('python_brace_position_format'), 0, False ))