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

Class TestChunkIds

tests/unit/ast_cache_test.py:40–64  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

38
39
40class TestChunkIds(unittest.TestCase):
41 def _ids(self, source: str) -> list:
42 tree = ast.parse(source)
43 seen: dict = {}
44 return [_make_chunk_id(n, seen) for n in tree.body]
45
46 def test_function(self):
47 self.assertEqual(self._ids("def foo(): pass"), ["FunctionDef:foo"])
48
49 def test_async_function(self):
50 self.assertEqual(self._ids("async def bar(): pass"), ["AsyncFunctionDef:bar"])
51
52 def test_class(self):
53 self.assertEqual(self._ids("class MyClass: pass"), ["ClassDef:MyClass"])
54
55 def test_bare_statement(self):
56 self.assertEqual(self._ids("x = 1"), ["stmt:1"])
57
58 def test_duplicate_names_get_suffix(self):
59 ids = self._ids("def foo(): pass\ndef foo(): pass")
60 self.assertEqual(ids, ["FunctionDef:foo", "FunctionDef:foo:1"])
61
62 def test_mixed(self):
63 ids = self._ids("x = 1\ndef foo(): pass\nclass Bar: pass")
64 self.assertEqual(ids, ["stmt:1", "FunctionDef:foo", "ClassDef:Bar"])
65
66
67# ── TestBuildAstJson ─────────────────────────────────────────────────────────

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected