mirror of
https://github.com/open-mmlab/mmengine.git
synced 2025-06-03 21:54:44 +08:00
Refine the repr of Registry (#942)
* Refine the repr of Registry * fix ut * fix ut
This commit is contained in:
parent
a6d06a424d
commit
e16dacf7e3
@ -1,6 +1,5 @@
|
|||||||
# Copyright (c) OpenMMLab. All rights reserved.
|
# Copyright (c) OpenMMLab. All rights reserved.
|
||||||
import inspect
|
import inspect
|
||||||
import io
|
|
||||||
import logging
|
import logging
|
||||||
import sys
|
import sys
|
||||||
from collections.abc import Callable
|
from collections.abc import Callable
|
||||||
@ -131,11 +130,11 @@ class Registry:
|
|||||||
for name, obj in sorted(self._module_dict.items()):
|
for name, obj in sorted(self._module_dict.items()):
|
||||||
table.add_row(name, str(obj))
|
table.add_row(name, str(obj))
|
||||||
|
|
||||||
with io.StringIO() as sio:
|
console = Console()
|
||||||
console = Console(file=sio)
|
with console.capture() as capture:
|
||||||
console.print(table, end='')
|
console.print(table, end='')
|
||||||
table_str = sio.getvalue()
|
|
||||||
return table_str
|
return capture.get()
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def infer_scope() -> str:
|
def infer_scope() -> str:
|
||||||
|
@ -1,9 +1,7 @@
|
|||||||
# Copyright (c) OpenMMLab. All rights reserved.
|
# Copyright (c) OpenMMLab. All rights reserved.
|
||||||
import io
|
|
||||||
import time
|
import time
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from rich.console import Console
|
|
||||||
|
|
||||||
from mmengine.config import Config, ConfigDict # type: ignore
|
from mmengine.config import Config, ConfigDict # type: ignore
|
||||||
from mmengine.registry import (DefaultScope, Registry, build_from_cfg,
|
from mmengine.registry import (DefaultScope, Registry, build_from_cfg,
|
||||||
@ -475,12 +473,9 @@ class TestRegistry:
|
|||||||
class Munchkin:
|
class Munchkin:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
with io.StringIO() as sio:
|
assert 'Registry of cat' in repr(CATS)
|
||||||
console = Console(file=sio)
|
assert 'BritishShorthair' in repr(CATS)
|
||||||
console.print(CATS, end='')
|
assert 'Munchkin' in repr(CATS)
|
||||||
repr_str = sio.getvalue()
|
|
||||||
|
|
||||||
assert repr(CATS) == repr_str
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('cfg_type', [dict, ConfigDict, Config])
|
@pytest.mark.parametrize('cfg_type', [dict, ConfigDict, Config])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user