<s> from __future__ import with_statement <EOL> from django . test import TestCase <EOL> from transifex . languages . models import Language <EOL> from transifex . resources . formats . validators import * <EOL> class TestValidators ( TestCase ) : <EOL> def test_empty_translation ( self ) : <EOL> old = '<STR_LIT>' <EOL> new = '<STR_LIT>' <EOL> v = BaseValidator ( ) <EOL> v ( old , new ) <EOL> def test_spaces ( self ) : <EOL> v = SpaceValidator ( ) <EOL> old = "<STR_LIT>" <EOL> new = "<STR_LIT:U+0020>" <EOL> self . assertRaises ( ValidationError , v , old , new ) <EOL> new = "<STR_LIT>" <EOL> self . assertRaises ( ValidationError , v , old , new ) <EOL> def test_brackets ( self ) : <EOL> v = MatchingBracketsValidator ( ) <EOL> for c in MatchingBracketsValidator . bracket_chars : <EOL> old = c + "<STR_LIT:string>" <EOL> new = c + "<STR_LIT>" <EOL> v ( old , new ) <EOL> new = "<STR_LIT>" + c <EOL> v ( old , new ) <EOL> new = "<STR_LIT>" + c + "<STR_LIT>" <EOL> v ( old , new ) <EOL> new = "<STR_LIT>" <EOL> self . assertRaises ( ValidationError , v , old , new ) <EOL> for c1 in MatchingBracketsValidator . bracket_chars : <EOL> for c2 in MatchingBracketsValidator . bracket_chars : <EOL> old = '<STR_LIT:a>' + c1 + '<STR_LIT:b>' + c2 + '<STR_LIT:c>' <EOL> new = c1 + '<STR_LIT:abc>' + c2 <EOL> v ( old , new ) <EOL> new = c2 + '<STR_LIT:abc>' + c1 <EOL> v <EOL> new = c1 + '<STR_LIT:abc>' <EOL> self . assertRaises ( ValidationError , v , old , new ) <EOL> new = c2 + '<STR_LIT:abc>' <EOL> self . assertRaises ( ValidationError , v , old , new ) <EOL> def test_urls ( self ) : <EOL> v = UrlsValidator ( ) <EOL> old = "<STR_LIT>" <EOL> new = "<STR_LIT>" <EOL> v ( old , new ) <EOL> new = "<STR_LIT>" <EOL> self . assertRaises ( ValidationError , v , old , new ) <EOL> new = "<STR_LIT>" <EOL> self . assertRaises ( ValidationError , v , old , new ) <EOL> new = "<STR_LIT>" <EOL> self . assertRaises ( ValidationError , v , old , new ) <EOL> old = "<STR_LIT>" <EOL> new = "<STR_LIT>" <EOL> v ( old , new ) <EOL> new = "<STR_LIT>" <EOL> self . assertRaises ( ValidationError , v , old , new ) <EOL> def test_emails ( self ) : <EOL> v = EmailAddressesValidator ( ) <EOL> old = "<STR_LIT>" <EOL> new = "<STR_LIT>" <EOL> v ( old , new ) <EOL> new = "<STR_LIT>" <EOL> self . assertRaises ( ValidationError , v , old , new ) <EOL> old = "<STR_LIT>" <EOL> new = "<STR_LIT>" <EOL> v ( old , new ) <EOL> new = "<STR_LIT>" <EOL> self . assertRaises ( ValidationError , v , old , new ) <EOL> def test_start_newlines ( self ) : <EOL> v = NewLineAtBeginningValidator ( ) <EOL> old = "<STR_LIT>" <EOL> new = "<STR_LIT>" <EOL> v ( old , new ) <EOL> old = "<STR_LIT>" <EOL> self . assertRaises ( ValidationError , v , old , new ) <EOL> new = "<STR_LIT>" <EOL> v ( old , new ) <EOL> old = "<STR_LIT>" <EOL> self . assertRaises ( ValidationError , v , old , new ) <EOL> def test_start_newlines ( self ) : <EOL> v = NewLineAtEndValidator ( ) <EOL> old = "<STR_LIT>" <EOL> new = "<STR_LIT>" <EOL> v ( old , new ) <EOL> old = "<STR_LIT>" <EOL> self . assertRaises ( ValidationError , v , old , new ) <EOL> new = "<STR_LIT>" <EOL> v ( old , new ) <EOL> old = "<STR_LIT>" <EOL> self . assertRaises ( ValidationError , v , old , new ) <EOL> def test_numbers ( self ) : <EOL> v = NumbersValidator ( ) <EOL> old = "<STR_LIT>" <EOL> new = "<STR_LIT>" <EOL> v ( old , new ) <EOL> new = "<STR_LIT>" <EOL> v ( old , new ) <EOL> new = "<STR_LIT>" <EOL> self . assertRaises ( ValidationError , v , old , new ) <EOL> new = "<STR_LIT>" <EOL> self . assertRaises ( ValidationError , v , old , new ) <EOL> new = "<STR_LIT>" <EOL> self . assertRaises ( ValidationError , v , old , new ) <EOL> old = "<STR_LIT>" <EOL> new = "<STR_LIT>" <EOL> v ( old , new ) <EOL> def test_printf_formats ( self ) : <EOL> class Language ( object ) : <EOL> pass <EOL> sl = Language ( ) <EOL> sl . nplurals = <NUM_LIT:2> <EOL> tl = Language ( ) <EOL> tl . nplurals = <NUM_LIT:2> <EOL> v = PrintfFormatNumberValidator ( sl , tl ) <EOL> old = "<STR_LIT>" <EOL> new = "<STR_LIT>" <EOL> v ( old , new ) <EOL> new = "<STR_LIT>" <EOL> self . assertRaises ( ValidationError , v , old , new ) <EOL> tl . nplurals = <NUM_LIT:3> <EOL> new = "<STR_LIT>" <EOL> v ( old , new ) <EOL> def test_source_printf_format ( self ) : <EOL> v = PrintfFormatSourceValidator ( ) <EOL> old = "<STR_LIT>" <EOL> new = "<STR_LIT>" <EOL> v ( old , new ) <EOL> new = "<STR_LIT>" <EOL> self . assertRaises ( ValidationError , v , old , new ) <EOL> new = "<STR_LIT:%s>" <EOL> self . assertRaises ( ValidationError , v , old , new ) <EOL> old = "<STR_LIT>" <EOL> new = "<STR_LIT>" <EOL> v ( old , new ) <EOL> old = "<STR_LIT>" <EOL> new = "<STR_LIT>" <EOL> with self . assertRaises ( ValidationError ) as cm : <EOL> v ( old , new ) <EOL> self . assertIn ( '<STR_LIT:foo>' , unicode ( cm . exception ) ) <EOL> new = "<STR_LIT>" <EOL> with self . assertRaises ( ValidationError ) as cm : <EOL> v ( old , new ) <EOL> self . assertIn ( '<STR_LIT:bar>' , unicode ( cm . exception ) ) <EOL> new = "<STR_LIT>" <EOL> with self . assertRaises ( ValidationError ) as cm : <EOL> v ( old , new ) <EOL> self . assertIn ( '<STR_LIT:foo>' , unicode ( cm . exception ) ) <EOL> new = "<STR_LIT>" <EOL> v ( old , new ) <EOL> def test_translation_printf_format ( self ) : <EOL> v = PrintfFormatTranslationValidator ( ) <EOL> old = "<STR_LIT>" <EOL> new = "<STR_LIT>" <EOL> v ( old , new ) <EOL> old = "<STR_LIT>" <EOL> self . assertRaises ( ValidationError , v , old , new ) <EOL> old = "<STR_LIT>" <EOL> self . assertRaises ( ValidationError , v , old , new ) <EOL> old = "<STR_LIT>" <EOL> new = "<STR_LIT>" <EOL> v ( old , new ) <EOL> old = "<STR_LIT>" <EOL> new = "<STR_LIT>" <EOL> with self . assertRaises ( ValidationError ) as cm : <EOL> v ( old , new ) <EOL> self . assertIn ( '<STR_LIT>' , unicode ( cm . exception ) ) <EOL> new = "<STR_LIT>" <EOL> with self . assertRaises ( ValidationError ) as cm : <EOL> v ( old , new ) <EOL> self . assertIn ( '<STR_LIT>' , unicode ( cm . exception ) ) <EOL> new = "<STR_LIT>" <EOL> v ( old , new ) <EOL> def test_singular_printf_number ( self ) : <EOL> class Language ( object ) : <EOL> pass <EOL> sl = Language ( ) <EOL> sl . nplurals = <NUM_LIT:2> <EOL> tl = Language ( ) <EOL> tl . nplurals = <NUM_LIT:2> <EOL> v = PrintfFormatPluralizedNumberValidator ( sl , tl , rule = <NUM_LIT:5> ) <EOL> old = "<STR_LIT>" <EOL> new = "<STR_LIT>" <EOL> self . assertRaises ( ValidationError , v , old , new ) <EOL> v . rule = <NUM_LIT:1> <EOL> new = "<STR_LIT>" <EOL> v ( old , new ) <EOL> v . rule = <NUM_LIT:5> <EOL> tl . nplurals = <NUM_LIT:5> <EOL> v ( old , new ) <EOL> def test_singular_printf_source ( self ) : <EOL> v = PrintfFormatPluralizedSourceValidator ( rule = <NUM_LIT:5> ) <EOL> old = "<STR_LIT>" <EOL> new = "<STR_LIT>" <EOL> self . assertRaises ( ValidationError , v , old , new ) <EOL> v . rule = <NUM_LIT:1> <EOL> new = "<STR_LIT>" <EOL> v ( old , new ) </s>
