File size: 541 Bytes
079c32c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
import pytest
from ding.utils.registry import Registry
@pytest.mark.unittest
def test_registry():
TEST_REGISTRY = Registry()
@TEST_REGISTRY.register('a')
class A:
pass
instance = TEST_REGISTRY.build('a')
assert isinstance(instance, A)
with pytest.raises(AssertionError):
@TEST_REGISTRY.register('a')
class A1:
pass
@TEST_REGISTRY.register('a', force_overwrite=True)
class A2:
pass
instance = TEST_REGISTRY.build('a')
assert isinstance(instance, A2)
|