1- #-*- coding: utf-8 -*-
1+ # -*- coding: utf-8 -*-
22import unittest
33
44import pytest
5+
56from babel .messages import extract
67from babel ._compat import BytesIO
78
@@ -35,7 +36,11 @@ def test_extract_var(self):
3536 self .assertEqual ([(1 , None , u'%(anton)s' , [])], messages )
3637
3738 def test_extract_filter_with_filter (self ):
38- buf = BytesIO (b'{% blocktrans with berta=anton|lower %}{{ berta }}{% endblocktrans %}' )
39+ test_tmpl = (
40+ b'{% blocktrans with berta=anton|lower %}'
41+ b'{{ berta }}{% endblocktrans %}'
42+ )
43+ buf = BytesIO (test_tmpl )
3944 messages = list (extract_django (buf , default_keys , [], {}))
4045 self .assertEqual ([(1 , None , u'%(berta)s' , [])], messages )
4146
@@ -45,42 +50,69 @@ def test_extract_with_interpolation(self):
4550 self .assertEqual ([(1 , None , u'xxx%(anton)sxxx' , [])], messages )
4651
4752 def test_extract_unicode (self ):
48- buf = BytesIO (b '{% trans "@ſðæ314“ſſ¶ÐĐÞ→SÆ^ĸŁ" %}' )
53+ buf = BytesIO (u '{% trans "@ſðæ314“ſſ¶ÐĐÞ→SÆ^ĸŁ" %}'. encode ( 'utf8' ) )
4954 messages = list (extract_django (buf , default_keys , [], {}))
5055 self .assertEqual ([(1 , None , u'@ſðæ314“ſſ¶ÐĐÞ→SÆ^ĸŁ' , [])], messages )
5156
5257 def test_extract_unicode_blocktrans (self ):
53- buf = BytesIO (b'{% blocktrans %}@ſðæ314“ſſ¶ÐĐÞ→SÆ^ĸŁ{% endblocktrans %}' )
58+ test_tmpl = u'{% blocktrans %}@ſðæ314“ſſ¶ÐĐÞ→SÆ^ĸŁ{% endblocktrans %}'
59+ buf = BytesIO (test_tmpl .encode ('utf8' ))
5460 messages = list (extract_django (buf , default_keys , [], {}))
5561 self .assertEqual ([(1 , None , u'@ſðæ314“ſſ¶ÐĐÞ→SÆ^ĸŁ' , [])], messages )
5662
5763 # TODO: Yet expected to not extract the comments.
5864 def test_extract_ignored_comment (self ):
59- buf = BytesIO (b'{# ignored comment #1 #}{% trans "Translatable literal #9a" %}' )
65+ buf = BytesIO (
66+ b'{# ignored comment #1 #}{% trans "Translatable literal #9a" %}' ,
67+ )
6068 messages = list (extract_django (buf , default_keys , [], {}))
61- self .assertEqual ([(1 , None , u'Translatable literal #9a' , [])], messages )
69+ self .assertEqual (
70+ [(1 , None , u'Translatable literal #9a' , [])], messages
71+ )
6272
6373 def test_extract_ignored_comment2 (self ):
64- buf = BytesIO (b'{# Translators: ignored i18n comment #1 #}{% trans "Translatable literal #9a" %}' )
74+ test_tmpl = (
75+ b'{# Translators: ignored i18n comment #1 #}'
76+ b'{% trans "Translatable literal #9a" %}'
77+ )
78+ buf = BytesIO (test_tmpl )
6579 messages = list (extract_django (buf , default_keys , [], {}))
66- self .assertEqual ([(1 , None , u'Translatable literal #9a' , [])], messages )
80+ self .assertEqual (
81+ [(1 , None , u'Translatable literal #9a' , [])], messages
82+ )
6783
6884 def test_extract_valid_comment (self ):
69- buf = BytesIO (b'{# ignored comment #6 #}{% trans "Translatable literal #9h" %}{# Translators: valid i18n comment #7 #}' )
85+ test_tmpl = (
86+ b'{# ignored comment #6 #}'
87+ b'{% trans "Translatable literal #9h" %}'
88+ b'{# Translators: valid i18n comment #7 #}'
89+ )
90+ buf = BytesIO (test_tmpl )
7091 messages = list (extract_django (buf , default_keys , [], {}))
71- self .assertEqual ([(1 , None , u'Translatable literal #9h' , [])], messages )
92+ self .assertEqual (
93+ [(1 , None , u'Translatable literal #9h' , [])], messages
94+ )
7295
7396 def test_extract_singular_form (self ):
74- buf = BytesIO (b'{% blocktrans count counter=number %}singular{% plural %}{{ counter }} plural{% endblocktrans %}' )
97+ test_tmpl = (
98+ b'{% blocktrans count counter=number %}'
99+ b'singular{% plural %}{{ counter }} plural'
100+ b'{% endblocktrans %}'
101+ )
102+ buf = BytesIO (test_tmpl )
75103 messages = list (extract_django (buf , default_keys , [], {}))
76- self .assertEqual ([(1 , 'ngettext' , (u'singular' , u'%(counter)s plural' ), [])], messages )
104+ self .assertEqual (
105+ [(1 , 'ngettext' , (u'singular' , u'%(counter)s plural' ), [])],
106+ messages
107+ )
77108
78109 def test_trans_blocks_must_not_include_other_block_tags (self ):
79110 buf = BytesIO (b'{% blocktrans %}{% other_tag %}{% endblocktrans %}' )
80111 gen = extract_django (buf , default_keys , [], {})
81- pytest .raises (SyntaxError , gen .next )
112+ with pytest .raises (SyntaxError ):
113+ next (gen )
82114
83- def test_extract_var (self ):
115+ def test_extract_var_other (self ):
84116 buf = BytesIO (b'{{ book }}' )
85117 messages = list (extract_django (buf , default_keys , [], {}))
86118 self .assertEqual ([], messages )
@@ -100,7 +132,7 @@ def test_extract_constant_single_quotes(self):
100132 messages = list (extract_django (buf , default_keys , [], {}))
101133 self .assertEqual ([(1 , None , u"'constant'" , [])], messages )
102134
103- def test_extract_constant_single_quotes (self ):
135+ def test_extract_constant_double_quotes (self ):
104136 buf = BytesIO (b'{{ _("constant") }}' )
105137 messages = list (extract_django (buf , default_keys , [], {}))
106138 self .assertEqual ([(1 , None , u'"constant"' , [])], messages )
@@ -111,8 +143,12 @@ def test_extract_constant_block(self):
111143 self .assertEqual ([(1 , None , u'"constant"' , [])], messages )
112144
113145 def test_extract_constant_in_block (self ):
114- buf = BytesIO (b'{% blocktrans foo=_("constant") %}{{ foo }}{% endblocktrans %}' )
146+ test_tmpl = (
147+ b'{% blocktrans foo=_("constant") %}{{ foo }}{% endblocktrans %}'
148+ )
149+ buf = BytesIO (test_tmpl )
115150 messages = list (extract_django (buf , default_keys , [], {}))
116151 self .assertEqual (
117152 [(1 , None , u'"constant"' , []), (1 , None , u'%(foo)s' , [])],
118- messages )
153+ messages ,
154+ )
0 commit comments