from types import SimpleNamespace from slic.utils.namespace import Namespace def test_namespace_pretty_repr_mixed_and_nested(): laser = SimpleNamespace(power="5W", wavelength="1030nm", mode="CW") detector = SimpleNamespace(model="X-500") stage = SimpleNamespace() experiment = SimpleNamespace(id=42, meta=SimpleNamespace(author="Dr. X", approved=True)) ns = Namespace() ns.laser = laser ns.detector = detector ns.stage = stage ns.experiment = experiment output = repr(ns) expected = """\ detector: namespace(model='X-500') experiment: namespace(id=42, meta=namespace(approved=True, author='Dr. X')) laser: namespace(mode='CW', power='5W', wavelength='1030nm') stage: namespace() """ if not output.endswith("\n"): output += "\n" assert output == expected