Added auto_exclude to public_calls.py file
This commit is contained in:
@@ -11,15 +11,17 @@ sys.path.insert(0, os.path.dirname(__file__))
|
|||||||
from openttd import OpenTTDClient, OpenTTDAdminClient
|
from openttd import OpenTTDClient, OpenTTDAdminClient
|
||||||
from openttd.protocol import OpenTTDProtocol, OpenTTDAdminProtocol
|
from openttd.protocol import OpenTTDProtocol, OpenTTDAdminProtocol
|
||||||
|
|
||||||
# 1. Gather public functions dynamically at runtime using reflection markers
|
# 1. Gather public functions dynamically at runtime using reflection
|
||||||
classes = [OpenTTDClient, OpenTTDAdminClient, OpenTTDProtocol, OpenTTDAdminProtocol]
|
classes = [OpenTTDClient, OpenTTDAdminClient, OpenTTDProtocol, OpenTTDAdminProtocol]
|
||||||
public_funcs = {} # name -> has_params
|
public_funcs = {} # name -> has_params
|
||||||
|
|
||||||
for cls in classes:
|
# Standard asyncio/lifecycle protocol methods that are not user-facing APIs
|
||||||
# Class must be marked as public
|
auto_exclude = {
|
||||||
if not getattr(cls, '__is_public_api__', False):
|
"connection_made", "connection_lost", "data_received",
|
||||||
continue
|
"eof_received", "pause_writing", "resume_writing", "connected"
|
||||||
|
}
|
||||||
|
|
||||||
|
for cls in classes:
|
||||||
# Class constructor call (e.g. OpenTTDClient(host, ...))
|
# Class constructor call (e.g. OpenTTDClient(host, ...))
|
||||||
sig_init = inspect.signature(cls.__init__)
|
sig_init = inspect.signature(cls.__init__)
|
||||||
has_params_init = len([p for name, p in sig_init.parameters.items() if name != 'self']) > 0
|
has_params_init = len([p for name, p in sig_init.parameters.items() if name != 'self']) > 0
|
||||||
@@ -38,7 +40,7 @@ for cls in classes:
|
|||||||
if name.startswith('receive_') and name != 'receive_packet':
|
if name.startswith('receive_') and name != 'receive_packet':
|
||||||
continue
|
continue
|
||||||
# Exclude lifecycle callbacks and manually decorated ones
|
# Exclude lifecycle callbacks and manually decorated ones
|
||||||
if getattr(val, '__exclude_call_check__', False):
|
if name in auto_exclude or getattr(val, '__exclude_call_check__', False):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
sig = inspect.signature(val)
|
sig = inspect.signature(val)
|
||||||
@@ -69,9 +71,10 @@ class E2ECallVisitor(ast.NodeVisitor):
|
|||||||
|
|
||||||
visitor = E2ECallVisitor()
|
visitor = E2ECallVisitor()
|
||||||
|
|
||||||
# Reflectively iterate through all test functions in tests.test_e2e
|
# Reflectively iterate through all test functions defined inside tests.test_e2e
|
||||||
for name, val in inspect.getmembers(test_e2e, predicate=inspect.isfunction):
|
for name, val in inspect.getmembers(test_e2e, predicate=inspect.isfunction):
|
||||||
if name.startswith("test_e2e_"):
|
# Only analyze functions defined directly in the module (skips imported ones)
|
||||||
|
if inspect.getmodule(val) == test_e2e:
|
||||||
# Retrieve function source dynamically via reflection
|
# Retrieve function source dynamically via reflection
|
||||||
source = inspect.getsource(val)
|
source = inspect.getsource(val)
|
||||||
func_tree = ast.parse(source)
|
func_tree = ast.parse(source)
|
||||||
|
|||||||
Reference in New Issue
Block a user