import sys
def _register_stub(module_name):
    parts=module_name.rsplit('.',1)
    package=parts[0] if len(parts)>1 else module_name
    class _Mod:pass
    _Mod.__name__=module_name
    _Mod.__package__=package
    sys.modules[module_name]=_Mod
    if len(parts)>1 and parts[0] in sys.modules:
        setattr(sys.modules[parts[0]],parts[1],_Mod)
_lazy_pending=[]
def _populate_module(module_name, source_code):
    parts=module_name.rsplit('.',1)
    package=parts[0] if len(parts)>1 else module_name
    namespace={'__name__':module_name,'__package__':package}
    exec(source_code,namespace)
    module_obj=sys.modules[module_name]
    for key, value in namespace.items():
        if not key.startswith('__'):
            setattr(module_obj,key,value)
    lazy=namespace.get('__getattr__')
    if lazy is not None:
        # Class-as-module attribute misses never reach a module-level
        # __getattr__, so PEP-562 lazy exports are resolved by
        # _materialize_lazy_exports after every module is populated.
        _lazy_pending.append((module_obj,lazy,namespace.get('__all__',()),tuple(namespace)))
    if len(parts)>1 and parts[0] in sys.modules:
        setattr(sys.modules[parts[0]],parts[1],module_obj)
def _materialize_lazy_exports():
    # Runs after population settles, so a resolution failure means the
    # providing submodule is structurally absent from this deploy (the
    # walker stages only what eager imports reach).  The name is left
    # off, matching a flash deploy where the file is not on the board;
    # a test importing it fails at its own import with the true message.
    for module_obj, lazy, names, populated in _lazy_pending:
        for key in names:
            if key not in populated and not hasattr(module_obj,key):
                try:
                    setattr(module_obj,key,lazy(key))
                except Exception:
                    pass
    _lazy_pending[:]=[]


# Pass 1: register empty stubs so import statements resolve.

# Execute the test file.
_test_namespace={}
exec($TEST_SOURCE,_test_namespace)
class _TestModule:pass
for key, value in _test_namespace.items():
    setattr(_TestModule,key,value)
from chumicro_test_harness.runner import run_module
run_module(_TestModule,name_filter=$FILTER_REPR)
