42 lines
1.1 KiB
Python
42 lines
1.1 KiB
Python
import json
|
|
import subprocess
|
|
import unittest
|
|
from pathlib import Path
|
|
|
|
|
|
ROOT = Path(__file__).resolve().parents[2]
|
|
SNAPSHOT = ROOT / "snapshots" / "js-ordered-consume.dtp"
|
|
SCRIPT = ROOT / "tools" / "dtp_parse.py"
|
|
|
|
|
|
def walk(node):
|
|
yield node
|
|
for child in node.get("children", []):
|
|
yield from walk(child)
|
|
|
|
|
|
class DtpParserTests(unittest.TestCase):
|
|
def test_emits_machine_readable_call_tree(self):
|
|
result = subprocess.run(
|
|
["python3", str(SCRIPT), str(SNAPSHOT), "--stdout"],
|
|
cwd=ROOT,
|
|
capture_output=True,
|
|
text=True,
|
|
check=False,
|
|
)
|
|
|
|
self.assertEqual(result.returncode, 0, msg=result.stderr)
|
|
payload = json.loads(result.stdout)
|
|
|
|
self.assertIn("callTree", payload)
|
|
self.assertIn("hotspots", payload)
|
|
self.assertTrue(payload["callTree"]["children"])
|
|
self.assertTrue(payload["hotspots"]["inclusive"])
|
|
|
|
node_names = [node["name"] for node in walk(payload["callTree"])]
|
|
self.assertTrue(any(not name.startswith("[special:") for name in node_names))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|