def assert_origin_inheritance(origin): placeholder = Placeholder(origin) assert origin is Placeholder.originof(placeholder) if origin is None: return mclass = origin.__class__ if mclass is None: return assert isinstance(origin, mclass) assert isinstance(placeholder, mclass) assert isinstance(placeholder, Placeholder) if isinstance(origin, Placeholder): return assert not isinstance(Placeholder.originof(placeholder), Placeholder)
def test_callable(): original = np.random.random np.random.random = Placeholder(np.random.random) def revert(numpy): numpy.random.random = Placeholder.originof(numpy.random.random) return numpy assert_rand_arrays(revert)
def revert(numpy): numpy.random.random = Placeholder.originof(numpy.random.random) return numpy
def test_class_init(): rs = Placeholder(np.random.RandomState) Placeholder.self_compatible_inheritance = True assert isinstance(rs(), rs) Placeholder.self_compatible_inheritance = False assert isinstance(rs(), np.random.RandomState)
def test_basic(): global np np = Placeholder(NUMPY_ORIGINAL_POINTER) assert_rand_arrays()
def test_containers(): a = Placeholder(my_list)
def test_inheritance(): origins = [ np.random, np, np.random.random, None, Placeholder, Placeholder(type) ] [assert_origin_inheritance(origin) for origin in origins]
def test_async(): coroutine_func = Placeholder(do_something) coroutine = Placeholder(do_something()) run_tasks(coroutine_func(), coroutine)