2626ROUND_TRIP_DIR = Path (__file__ ).absolute ().parent
2727HCL2_ORIGINAL_DIR = ROUND_TRIP_DIR / "hcl2_original"
2828
29+ SPECIAL_DIR = ROUND_TRIP_DIR / "special"
30+
2931_STEP_DIRS = {
3032 "hcl2_original" : HCL2_ORIGINAL_DIR ,
3133 "hcl2_reconstructed" : ROUND_TRIP_DIR / "hcl2_reconstructed" ,
3234 "json_serialized" : ROUND_TRIP_DIR / "json_serialized" ,
3335 "json_reserialized" : ROUND_TRIP_DIR / "json_reserialized" ,
34- "json_operator_precedence" : ROUND_TRIP_DIR / "json_operator_precedence" ,
3536}
3637
3738_STEP_SUFFIXES = {
3839 "hcl2_original" : ".tf" ,
3940 "hcl2_reconstructed" : ".tf" ,
4041 "json_serialized" : ".json" ,
4142 "json_reserialized" : ".json" ,
42- "json_operator_precedence" : ".json" ,
4343}
4444
4545
@@ -48,7 +48,6 @@ class SuiteStep(Enum):
4848 RECONSTRUCTED = "hcl2_reconstructed"
4949 JSON_SERIALIZED = "json_serialized"
5050 JSON_RESERIALIZED = "json_reserialized"
51- JSON_OPERATOR_PRECEDENCE = "json_operator_precedence"
5251
5352
5453def _get_suites () -> List [str ]:
@@ -109,20 +108,18 @@ class TestRoundTripSerialization(TestCase):
109108
110109 def test_hcl_to_json (self ):
111110 for suite in _get_suites ():
112- yield self .check_hcl_to_json , suite
113-
114- def check_hcl_to_json (self , suite : str ):
115- hcl_path = _get_suite_file (suite , SuiteStep .ORIGINAL )
116- json_path = _get_suite_file (suite , SuiteStep .JSON_SERIALIZED )
111+ with self .subTest (suite = suite ):
112+ hcl_path = _get_suite_file (suite , SuiteStep .ORIGINAL )
113+ json_path = _get_suite_file (suite , SuiteStep .JSON_SERIALIZED )
117114
118- actual = _parse_and_serialize (hcl_path .read_text ())
119- expected = json .loads (json_path .read_text ())
115+ actual = _parse_and_serialize (hcl_path .read_text ())
116+ expected = json .loads (json_path .read_text ())
120117
121- self .assertEqual (
122- actual ,
123- expected ,
124- f"HCL → JSON serialization mismatch for { suite } " ,
125- )
118+ self .assertEqual (
119+ actual ,
120+ expected ,
121+ f"HCL → JSON serialization mismatch for { suite } " ,
122+ )
126123
127124
128125class TestRoundTripReserialization (TestCase ):
@@ -132,21 +129,19 @@ class TestRoundTripReserialization(TestCase):
132129
133130 def test_json_reserialization (self ):
134131 for suite in _get_suites ():
135- yield self .check_json_reserialization , suite
132+ with self .subTest (suite = suite ):
133+ hcl_path = _get_suite_file (suite , SuiteStep .ORIGINAL )
134+ json_reserialized_path = _get_suite_file (suite , SuiteStep .JSON_RESERIALIZED )
136135
137- def check_json_reserialization (self , suite : str ):
138- hcl_path = _get_suite_file (suite , SuiteStep .ORIGINAL )
139- json_reserialized_path = _get_suite_file (suite , SuiteStep .JSON_RESERIALIZED )
136+ serialized = _parse_and_serialize (hcl_path .read_text ())
137+ actual = _deserialize_and_reserialize (serialized )
140138
141- serialized = _parse_and_serialize (hcl_path .read_text ())
142- actual = _deserialize_and_reserialize (serialized )
143-
144- expected = json .loads (json_reserialized_path .read_text ())
145- self .assertEqual (
146- actual ,
147- expected ,
148- f"JSON reserialization mismatch for { suite } " ,
149- )
139+ expected = json .loads (json_reserialized_path .read_text ())
140+ self .assertEqual (
141+ actual ,
142+ expected ,
143+ f"JSON reserialization mismatch for { suite } " ,
144+ )
150145
151146
152147class TestRoundTripReconstruction (TestCase ):
@@ -156,21 +151,19 @@ class TestRoundTripReconstruction(TestCase):
156151
157152 def test_json_to_hcl (self ):
158153 for suite in _get_suites ():
159- yield self .check_json_to_hcl , suite
160-
161- def check_json_to_hcl (self , suite : str ):
162- hcl_path = _get_suite_file (suite , SuiteStep .ORIGINAL )
163- hcl_reconstructed_path = _get_suite_file (suite , SuiteStep .RECONSTRUCTED )
154+ with self .subTest (suite = suite ):
155+ hcl_path = _get_suite_file (suite , SuiteStep .ORIGINAL )
156+ hcl_reconstructed_path = _get_suite_file (suite , SuiteStep .RECONSTRUCTED )
164157
165- serialized = _parse_and_serialize (hcl_path .read_text ())
166- actual = _deserialize_and_reconstruct (serialized )
158+ serialized = _parse_and_serialize (hcl_path .read_text ())
159+ actual = _deserialize_and_reconstruct (serialized )
167160
168- expected = hcl_reconstructed_path .read_text ()
169- self .assertMultiLineEqual (
170- actual ,
171- expected ,
172- f"HCL reconstruction mismatch for { suite } " ,
173- )
161+ expected = hcl_reconstructed_path .read_text ()
162+ self .assertMultiLineEqual (
163+ actual ,
164+ expected ,
165+ f"HCL reconstruction mismatch for { suite } " ,
166+ )
174167
175168
176169class TestRoundTripFull (TestCase ):
@@ -180,27 +173,25 @@ class TestRoundTripFull(TestCase):
180173
181174 def test_full_round_trip (self ):
182175 for suite in _get_suites ():
183- yield self .check_full_round_trip , suite
184-
185- def check_full_round_trip (self , suite : str ):
186- hcl_path = _get_suite_file (suite , SuiteStep .ORIGINAL )
187- original_hcl = hcl_path .read_text ()
176+ with self .subTest (suite = suite ):
177+ hcl_path = _get_suite_file (suite , SuiteStep .ORIGINAL )
178+ original_hcl = hcl_path .read_text ()
188179
189- # Forward: HCL → JSON
190- serialized = _parse_and_serialize (original_hcl )
180+ # Forward: HCL → JSON
181+ serialized = _parse_and_serialize (original_hcl )
191182
192- # Reconstruct: JSON → HCL
193- reconstructed_hcl = _deserialize_and_reconstruct (serialized )
183+ # Reconstruct: JSON → HCL
184+ reconstructed_hcl = _deserialize_and_reconstruct (serialized )
194185
195- # Re-parse : reconstructed HCL → JSON
196- reserialized = _parse_and_serialize (reconstructed_hcl )
186+ # Reparse : reconstructed HCL → JSON
187+ reserialized = _parse_and_serialize (reconstructed_hcl )
197188
198- self .assertEqual (
199- reserialized ,
200- serialized ,
201- f"Full round-trip mismatch for { suite } : "
202- f"HCL → JSON → HCL → JSON did not produce identical JSON" ,
203- )
189+ self .assertEqual (
190+ reserialized ,
191+ serialized ,
192+ f"Full round-trip mismatch for { suite } : "
193+ f"HCL → JSON → HCL → JSON did not produce identical JSON" ,
194+ )
204195
205196
206197class TestOperatorPrecedence (TestCase ):
0 commit comments