1515
1616
1717def test_en_basic ():
18+ bundle = fluent .Bundle ("en" , [data_dir / "en.ftl" ])
19+ assert bundle .get_translation ("hello-world" ) == "Hello World"
20+
21+
22+ def test_en_basic_str_path ():
1823 bundle = fluent .Bundle ("en" , [str (data_dir / "en.ftl" )])
1924 assert bundle .get_translation ("hello-world" ) == "Hello World"
2025
2126
2227def test_en_basic_with_named_arguments ():
2328 bundle = fluent .Bundle (
2429 language = "en" ,
25- ftl_filenames = [str ( data_dir / "en.ftl" ) ],
30+ ftl_filenames = [data_dir / "en.ftl" ],
2631 )
2732 assert bundle .get_translation ("hello-world" ) == "Hello World"
2833
2934
3035def test_en_with_variables ():
31- bundle = fluent .Bundle ("en" , [str ( data_dir / "en.ftl" ) ])
36+ bundle = fluent .Bundle ("en" , [data_dir / "en.ftl" ])
3237 assert (
3338 bundle .get_translation ("hello-user" , variables = {"user" : "Bob" })
3439 == f"Hello, { BIDI_OPEN } Bob{ BIDI_CLOSE } "
3540 )
3641
3742
3843def test_en_with_variables_use_isolating_off ():
39- bundle = fluent .Bundle ("en" , [str ( data_dir / "en.ftl" ) ])
44+ bundle = fluent .Bundle ("en" , [data_dir / "en.ftl" ])
4045 assert (
4146 bundle .get_translation (
4247 "hello-user" ,
@@ -61,7 +66,7 @@ def test_en_with_variables_use_isolating_off():
6166 ),
6267)
6368def test_variables_of_different_types (description , identifier , variables , expected ):
64- bundle = fluent .Bundle ("en" , [str ( data_dir / "en.ftl" ) ])
69+ bundle = fluent .Bundle ("en" , [data_dir / "en.ftl" ])
6570
6671 result = bundle .get_translation (identifier , variables = variables )
6772
@@ -84,7 +89,7 @@ def test_invalid_language():
8489 ),
8590)
8691def test_invalid_variable_keys_raise_type_error (key ):
87- bundle = fluent .Bundle ("en" , [str ( data_dir / "en.ftl" ) ])
92+ bundle = fluent .Bundle ("en" , [data_dir / "en.ftl" ])
8893
8994 with pytest .raises (TypeError , match = "Variable key not a str, got" ):
9095 bundle .get_translation ("hello-user" , variables = {key : "Bob" })
@@ -99,20 +104,20 @@ def test_invalid_variable_keys_raise_type_error(key):
99104 ),
100105)
101106def test_invalid_variable_values_use_key_instead (value ):
102- bundle = fluent .Bundle ("en" , [str ( data_dir / "en.ftl" ) ])
107+ bundle = fluent .Bundle ("en" , [data_dir / "en.ftl" ])
103108
104109 result = bundle .get_translation ("hello-user" , variables = {"user" : value })
105110
106111 assert result == f"Hello, { BIDI_OPEN } user{ BIDI_CLOSE } "
107112
108113
109114def test_fr_basic ():
110- bundle = fluent .Bundle ("fr" , [str ( data_dir / "fr.ftl" ) ])
115+ bundle = fluent .Bundle ("fr" , [data_dir / "fr.ftl" ])
111116 assert bundle .get_translation ("hello-world" ) == "Bonjour le monde!"
112117
113118
114119def test_fr_with_args ():
115- bundle = fluent .Bundle ("fr" , [str ( data_dir / "fr.ftl" ) ])
120+ bundle = fluent .Bundle ("fr" , [data_dir / "fr.ftl" ])
116121 assert (
117122 bundle .get_translation ("hello-user" , variables = {"user" : "Bob" })
118123 == f"Bonjour, { BIDI_OPEN } Bob{ BIDI_CLOSE } !"
@@ -130,7 +135,7 @@ def test_fr_with_args():
130135 ),
131136)
132137def test_selector (number , expected ):
133- bundle = fluent .Bundle ("en" , [str ( data_dir / "en.ftl" ) ])
138+ bundle = fluent .Bundle ("en" , [data_dir / "en.ftl" ])
134139
135140 result = bundle .get_translation ("with-selector" , variables = {"number" : number })
136141
@@ -140,7 +145,7 @@ def test_selector(number, expected):
140145def test_new_overwrites_old ():
141146 bundle = fluent .Bundle (
142147 "en" ,
143- [str ( data_dir / "fr.ftl" ), str ( data_dir / "en_hello.ftl" ) ],
148+ [data_dir / "fr.ftl" , data_dir / "en_hello.ftl" ],
144149 )
145150 assert bundle .get_translation ("hello-world" ) == "Hello World"
146151 assert (
@@ -150,14 +155,14 @@ def test_new_overwrites_old():
150155
151156
152157def test_id_not_found ():
153- bundle = fluent .Bundle ("fr" , [str ( data_dir / "fr.ftl" ) ])
158+ bundle = fluent .Bundle ("fr" , [data_dir / "fr.ftl" ])
154159 with pytest .raises (ValueError ):
155160 bundle .get_translation ("missing" , variables = {"user" : "Bob" })
156161
157162
158163def test_file_not_found ():
159164 with pytest .raises (FileNotFoundError ):
160- fluent .Bundle ("fr" , [str ( data_dir / "none.ftl" ) ])
165+ fluent .Bundle ("fr" , [data_dir / "none.ftl" ])
161166
162167
163168@pytest .mark .parametrize ("pass_strict_argument_explicitly" , (True , False ))
@@ -166,14 +171,14 @@ def test_parses_other_parts_of_file_that_contains_errors_in_non_strict_mode(
166171):
167172 kwargs = dict (strict = False ) if pass_strict_argument_explicitly else {}
168173
169- bundle = fluent .Bundle ("fr" , [str ( data_dir / "errors.ftl" ) ], ** kwargs )
174+ bundle = fluent .Bundle ("fr" , [data_dir / "errors.ftl" ], ** kwargs )
170175 translation = bundle .get_translation ("valid-message" )
171176
172177 assert translation == "I'm valid."
173178
174179
175180def test_raises_parser_error_on_file_that_contains_errors_in_strict_mode ():
176- filename = str ( data_dir / "errors.ftl" )
181+ filename = data_dir / "errors.ftl"
177182
178183 with pytest .raises (fluent .ParserError ) as exc_info :
179184 fluent .Bundle ("fr" , [filename ], strict = True )
0 commit comments