import ast from pathlib import Path SKILL_FILE = ( Path(__file__).resolve().parents[2] / "core" / "character" / "GF" / "swordman_female" / "demon_slayer.py" ) def _skill_class(name: str) -> ast.ClassDef: module = ast.parse(SKILL_FILE.read_text(encoding="utf-8")) return next( node for node in module.body if isinstance(node, ast.ClassDef) and any( isinstance(item, ast.Assign) and any(isinstance(target, ast.Name) and target.id == "name" for target in item.targets) and isinstance(item.value, ast.Constant) and item.value.value == name for item in node.body ) ) def test_blade_dance_shadow_uses_final_hit_damage_not_hit_count(): skill = _skill_class("魔刃狂舞") shadow_final_hit = next( item for item in skill.body if isinstance(item, ast.Assign) and any(isinstance(target, ast.Name) and target.id == "data5" for target in item.targets) ) assert isinstance(shadow_final_hit.value, ast.Name) assert shadow_final_hit.value.id == "data2" def test_blade_dance_shadow_uses_its_own_passive_ratio(): passive = _skill_class("唤魔 : 弑神剑") associations = next( item.value for item in passive.body if isinstance(item, ast.Assign) and any(isinstance(target, ast.Name) and target.id == "associate" for target in item.targets) ) shadow_associations = [ dict(zip((key.value for key in entry.keys), entry.values)) for entry in associations.elts if isinstance(entry, ast.Dict) ] for power in ("+power4", "+power5"): association = next( entry for entry in shadow_associations if isinstance(entry.get("type"), ast.Constant) and entry["type"].value == power ) assert isinstance(association["data"], ast.Name) assert association["data"].id == "data3"