MCPcopy Create free account
hub / github.com/ParzivalHack/PySpector / TestAssembleModuleJson

Class TestAssembleModuleJson

tests/unit/ast_cache_test.py:133–163  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

131
132
133class TestAssembleModuleJson(unittest.TestCase):
134 def test_non_empty_body_goes_to_children(self):
135 body = ['{"node_type": "Assign"}']
136 result = _parse_json(_assemble_module_json(body, []))
137 self.assertIn("body", result["children"])
138 self.assertNotIn("body", result["fields"])
139
140 def test_empty_body_goes_to_fields(self):
141 result = _parse_json(_assemble_module_json([], []))
142 self.assertIn("body", result["fields"])
143 self.assertEqual(result["fields"]["body"], [])
144
145 def test_non_empty_type_ignores_goes_to_children(self):
146 ti = ['{"node_type": "TypeIgnore"}']
147 result = _parse_json(_assemble_module_json([], ti))
148 self.assertIn("type_ignores", result["children"])
149
150 def test_empty_type_ignores_goes_to_fields(self):
151 result = _parse_json(_assemble_module_json([], []))
152 self.assertIn("type_ignores", result["fields"])
153 self.assertEqual(result["fields"]["type_ignores"], [])
154
155 def test_module_metadata(self):
156 result = _parse_json(_assemble_module_json([], []))
157 self.assertEqual(result["node_type"], "Module")
158 self.assertEqual(result["lineno"], -1)
159 self.assertEqual(result["col_offset"], -1)
160
161 def test_output_is_valid_json(self):
162 body = ['{"node_type": "Expr", "lineno": 1}']
163 json.loads(_assemble_module_json(body, [])) # must not raise
164
165
166# ── TestSerializeDeserialize ──────────────────────────────────────────────────

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected