11import unittest
2+ from os .path import join
23from .utils import patch_files
34
45from fluent .runtime import FluentLocalization , FluentResourceLoader
@@ -11,30 +12,26 @@ def test_init(self):
1112 )
1213 self .assertTrue (callable (l10n .format_value ))
1314
14- @patch_files ({
15- "de/one.ftl" : """one = in German
16- .foo = one in German
17- """ ,
18- "de/two.ftl" : """two = in German
19- .foo = two in German
20- """ ,
21- "fr/two.ftl" : """three = in French
22- .foo = three in French
23- """ ,
24- "en/one.ftl" : """four = exists
25- .foo = four in English
26- """ ,
27- "en/two.ftl" : """
28- five = exists
29- .foo = five in English
30- bar =
31- .foo = bar in English
32- baz = baz in English
33- """ ,
34- })
35- def test_bundles (self ):
15+ @patch_files (
16+ {
17+ "de" : {
18+ "one.ftl" : "one = in German\n .foo = one in German\n " ,
19+ "two.ftl" : "two = in German\n .foo = two in German\n " ,
20+ },
21+ "fr" : {"two.ftl" : "three = in French\n .foo = three in French\n " },
22+ "en" : {
23+ "one.ftl" : "four = exists\n .foo = four in English\n " ,
24+ "two.ftl" : "five = exists\n .foo = five in English\n "
25+ + "bar =\n .foo = bar in English\n "
26+ + "baz = baz in English\n " ,
27+ },
28+ }
29+ )
30+ def test_bundles (self , root ):
3631 l10n = FluentLocalization (
37- ["de" , "fr" , "en" ], ["one.ftl" , "two.ftl" ], FluentResourceLoader ("{locale}" )
32+ ["de" , "fr" , "en" ],
33+ ["one.ftl" , "two.ftl" ],
34+ FluentResourceLoader (join (root , "{locale}" )),
3835 )
3936 bundles_gen = l10n ._bundles ()
4037 bundle_de = next (bundles_gen )
@@ -91,29 +88,31 @@ def test_bundles(self):
9188
9289
9390class TestResourceLoader (unittest .TestCase ):
94- @patch_files ({
95- "en/one.ftl" : "one = exists" ,
96- "en/two.ftl" : "two = exists" ,
97- })
98- def test_all_exist (self ):
99- loader = FluentResourceLoader ("{locale}" )
91+ @patch_files (
92+ {
93+ "en" : {
94+ "one.ftl" : "one = exists" ,
95+ "two.ftl" : "two = exists" ,
96+ }
97+ }
98+ )
99+ def test_all_exist (self , root ):
100+ loader = FluentResourceLoader (join (root , "{locale}" ))
100101 resources_list = list (loader .resources ("en" , ["one.ftl" , "two.ftl" ]))
101102 self .assertEqual (len (resources_list ), 1 )
102103 resources = resources_list [0 ]
103104 self .assertEqual (len (resources ), 2 )
104105
105- @patch_files ({
106- "en/two.ftl" : "two = exists" ,
107- })
108- def test_one_exists (self ):
109- loader = FluentResourceLoader ("{locale}" )
106+ @patch_files ({"en" : {"two.ftl" : "two = exists" }})
107+ def test_one_exists (self , root ):
108+ loader = FluentResourceLoader (join (root , "{locale}" ))
110109 resources_list = list (loader .resources ("en" , ["one.ftl" , "two.ftl" ]))
111110 self .assertEqual (len (resources_list ), 1 )
112111 resources = resources_list [0 ]
113112 self .assertEqual (len (resources ), 1 )
114113
115114 @patch_files ({})
116- def test_none_exist (self ):
117- loader = FluentResourceLoader ("{locale}" )
115+ def test_none_exist (self , root ):
116+ loader = FluentResourceLoader (join ( root , "{locale}" ) )
118117 resources_list = list (loader .resources ("en" , ["one.ftl" , "two.ftl" ]))
119118 self .assertEqual (len (resources_list ), 0 )
0 commit comments