Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014Typ5sXWNMFirr2va2uL8o
31 lines
1.3 KiB
Python
31 lines
1.3 KiB
Python
import ast
|
|
import os
|
|
import unittest
|
|
|
|
from _common import SRC
|
|
|
|
# Ограничение проверки: ast.parse(feature_version=(3, 9)) ловит синтаксис 3.10+ (match и т. п.) и сторонние
|
|
# импорты; API и конструкции, новые в 3.9 (например, `X | Y` в аннотациях), не проверяет. Их подтверждает только
|
|
# прогон на /usr/bin/python3 (3.9.6).
|
|
|
|
|
|
class Py39Test(unittest.TestCase):
|
|
def test_agent_parses_as_python_39(self):
|
|
with open(os.path.join(SRC, "agent.py"), encoding="utf-8") as f:
|
|
ast.parse(f.read(), feature_version=(3, 9))
|
|
|
|
def test_no_third_party_imports(self):
|
|
with open(os.path.join(SRC, "agent.py"), encoding="utf-8") as f:
|
|
tree = ast.parse(f.read())
|
|
allowed = {"argparse", "base64", "json", "os", "signal", "ssl", "http", "sys", "time", "urllib", "datetime", "typing"}
|
|
for node in ast.walk(tree):
|
|
if isinstance(node, ast.Import):
|
|
for a in node.names:
|
|
self.assertIn(a.name.split(".")[0], allowed, a.name)
|
|
elif isinstance(node, ast.ImportFrom):
|
|
self.assertIn((node.module or "").split(".")[0], allowed, node.module)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|