예제 #1
0
 def can_register_and_unregister():
     try:
         assert Description.bases is str
         register_description(str)
         assert Description.bases is str
         register_description(int)
         assert Description.bases == (str, int)
         register_description(int)
         assert Description.bases == (str, int)
         register_description(float)
         assert Description.bases == (str, int, float)
         unregister_description(int)
         assert Description.bases == (str, float)
         unregister_description(float)
         assert Description.bases is str
         unregister_description(str)
         assert Description.bases is object
         register_description(str)
         assert Description.bases is str
         register_description(object)
         assert Description.bases is object
         Description.bases = (str,)
         unregister_description(str)
         assert Description.bases is object
         unregister_description(str)
         assert Description.bases is object
     finally:
         Description.bases = str
예제 #2
0
 def can_only_unregister_types():
     with raises(TypeError, match="Only types can be unregistered\\."):
         # noinspection PyTypeChecker
         unregister_description("foo")  # type: ignore
예제 #3
0
def registered(base: type):
    register_description(base)
    try:
        yield None
    finally:
        unregister_description(LazyString)