1616from tests .resources import ENCLOSINGS
1717
1818
19- def _skip_pseudo_enclosing_value (value : str ):
20- starts_and_ends_in_brackets = value .startswith ("{" ) and value .endswith ("}" )
21- starts_and_ends_in_quotes = value .startswith ('"' ) and value .endswith ('"' )
22- if starts_and_ends_in_quotes or starts_and_ends_in_brackets :
23- pytest .skip ("No enclosing to remove" )
24-
25-
2619@pytest .mark .parametrize ("enclosing" , ENCLOSINGS + [pytest .param ("{0}" , id = "no_enclosing" )])
2720@pytest .mark .parametrize ("value" , EDGE_CASE_VALUES )
2821@pytest .mark .parametrize ("inplace" , [True , False ], ids = ["inplace" , "not_inplace" ])
@@ -32,9 +25,6 @@ def test_removal_of_enclosing_on_string(enclosing, value, inplace):
3225 Also covers the internals for other block types (i.e., Entry),
3326 which thus can be tested more light-weight."""
3427
35- if enclosing == "{0}" :
36- _skip_pseudo_enclosing_value (value )
37-
3828 # Create test string
3929 key = "someKey"
4030 raw = "<--- does not matter for this unit test -->"
@@ -51,8 +41,20 @@ def test_removal_of_enclosing_on_string(enclosing, value, inplace):
5141 assert len (transformed_library .strings ) == 1
5242 # Assert correct removal of enclosing
5343 transformed = transformed_library .strings [0 ]
54- assert transformed .value == value
55- expected_enclosing = enclosing .format ("" )[0 ] if enclosing != "{0}" else "no-enclosing"
44+ input_value = enclosing .format (value )
45+ if input_value .startswith ("{" ) and input_value .endswith ("}" ):
46+ expected_value = input_value [1 :- 1 ]
47+ expected_enclosing = "{"
48+ elif input_value .startswith ('"' ) and input_value .endswith ('"' ):
49+ expected_value = input_value [1 :- 1 ]
50+ expected_enclosing = '"'
51+ else :
52+ expected_value = input_value
53+ expected_enclosing = "no-enclosing"
54+
55+ # Values that already look enclosed are necessarily interpreted as enclosed,
56+ # even when the test did not add another wrapper around them.
57+ assert transformed .value == expected_value
5658 assert transformed .parser_metadata ["removed_enclosing" ] == expected_enclosing
5759 # Assert remaining fields are unchanged
5860 assert transformed .start_line == start_line
@@ -162,9 +164,6 @@ def test_addition_of_enclosing_on_entry(
162164 transformed = transformed_library .entries [0 ]
163165 changed_value = transformed ["year" ]
164166
165- # Figure out which enclosing was added
166- used_enclosing = _figure_out_added_enclosing (changed_value , value )
167-
168167 # Assert correct enclosing was added
169168 if reuse_previous_enclosing and metadata_enclosing is not None :
170169 expected_enclosing = metadata_enclosing
@@ -174,9 +173,11 @@ def test_addition_of_enclosing_on_entry(
174173 expected_enclosing = default_enclosing
175174
176175 if expected_enclosing == "no-enclosing" :
177- _skip_pseudo_enclosing_value (value )
178-
179- assert used_enclosing == expected_enclosing
176+ # Inspect the exact output because a value may itself begin and end with
177+ # enclosure-like characters even though the middleware added nothing.
178+ assert changed_value == str (value )
179+ else :
180+ assert _figure_out_added_enclosing (changed_value , value ) == expected_enclosing
180181
181182 # Assert remaining fields are unchanged
182183 assert_nonfield_entry_attributes_unchanged (input_entry , transformed )
0 commit comments