11import io
22import os
33
4- from mako .ext .babelplugin import extract
4+ import pytest
5+
56from mako .testing .assertions import eq_
67from mako .testing .config import config
78from mako .testing .exclusions import requires_babel
89from mako .testing .fixtures import TemplateTest
910
1011
12+ class UsesExtract :
13+ @pytest .fixture (scope = "class" )
14+ def extract (self ):
15+ from mako .ext .babelplugin import extract
16+
17+ return extract
18+
19+
1120@requires_babel
12- class PluginExtractTest :
13- def test_parse_python_expression (self ):
21+ class PluginExtractTest ( UsesExtract ) :
22+ def test_parse_python_expression (self , extract ):
1423 input_ = io .BytesIO (b'<p>${_("Message")}</p>' )
1524 messages = list (extract (input_ , ["_" ], [], {}))
1625 eq_ (messages , [(1 , "_" , ("Message" ), [])])
1726
18- def test_python_gettext_call (self ):
27+ def test_python_gettext_call (self , extract ):
1928 input_ = io .BytesIO (b'<p>${_("Message")}</p>' )
2029 messages = list (extract (input_ , ["_" ], [], {}))
2130 eq_ (messages , [(1 , "_" , ("Message" ), [])])
2231
23- def test_translator_comment (self ):
32+ def test_translator_comment (self , extract ):
2433 input_ = io .BytesIO (
2534 b"""
2635 <p>
@@ -43,8 +52,8 @@ def test_translator_comment(self):
4352
4453
4554@requires_babel
46- class MakoExtractTest (TemplateTest ):
47- def test_extract (self ):
55+ class MakoExtractTest (UsesExtract , TemplateTest ):
56+ def test_extract (self , extract ):
4857 with open (
4958 os .path .join (config .template_base , "gettext.mako" )
5059 ) as mako_tmpl :
@@ -83,7 +92,7 @@ def test_extract(self):
8392 ]
8493 eq_ (expected , messages )
8594
86- def test_extract_utf8 (self ):
95+ def test_extract_utf8 (self , extract ):
8796 with open (
8897 os .path .join (config .template_base , "gettext_utf8.mako" ), "rb"
8998 ) as mako_tmpl :
@@ -92,7 +101,7 @@ def test_extract_utf8(self):
92101 )
93102 assert message == (1 , "_" , "K\xf6 ln" , [])
94103
95- def test_extract_cp1251 (self ):
104+ def test_extract_cp1251 (self , extract ):
96105 with open (
97106 os .path .join (config .template_base , "gettext_cp1251.mako" ), "rb"
98107 ) as mako_tmpl :
0 commit comments