Exemplo n.º 1
0
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)
Exemplo n.º 2
0
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)
Exemplo n.º 3
0
 def revert(numpy):
     numpy.random.random = Placeholder.originof(numpy.random.random)
     return numpy
Exemplo n.º 4
0
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)
Exemplo n.º 5
0
def test_basic():
    global np
    np = Placeholder(NUMPY_ORIGINAL_POINTER)
    assert_rand_arrays()
Exemplo n.º 6
0
def test_containers():
    a = Placeholder(my_list)
Exemplo n.º 7
0
def test_inheritance():
    origins = [
        np.random, np, np.random.random, None, Placeholder,
        Placeholder(type)
    ]
    [assert_origin_inheritance(origin) for origin in origins]
Exemplo n.º 8
0
def test_async():
    coroutine_func = Placeholder(do_something)
    coroutine = Placeholder(do_something())
    run_tasks(coroutine_func(), coroutine)