Add admin port support with other major refactorations #9
@@ -11,15 +11,17 @@ sys.path.insert(0, os.path.dirname(__file__))
|
||||
from openttd import OpenTTDClient, OpenTTDAdminClient
|
||||
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]
|
||||
public_funcs = {} # name -> has_params
|
||||
|
||||
for cls in classes:
|
||||
# Class must be marked as public
|
||||
if not getattr(cls, '__is_public_api__', False):
|
||||
continue
|
||||
# Standard asyncio/lifecycle protocol methods that are not user-facing APIs
|
||||
auto_exclude = {
|
||||
"connection_made", "connection_lost", "data_received",
|
||||
"eof_received", "pause_writing", "resume_writing", "connected"
|
||||
}
|
||||
|
||||
for cls in classes:
|
||||
# Class constructor call (e.g. OpenTTDClient(host, ...))
|
||||
sig_init = inspect.signature(cls.__init__)
|
||||
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':
|
||||
continue
|
||||
# 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
|
||||
|
||||
sig = inspect.signature(val)
|
||||
@@ -69,9 +71,10 @@ class E2ECallVisitor(ast.NodeVisitor):
|
||||
|
||||
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):
|
||||
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
|
||||
source = inspect.getsource(val)
|
||||
func_tree = ast.parse(source)
|
||||
|
||||
Reference in New Issue
Block a user