Esempio 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)
Esempio 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)
Esempio n. 3
0
 def revert(numpy):
     numpy.random.random = Placeholder.originof(numpy.random.random)
     return numpy
Esempio 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)
Esempio n. 5
0
def test_basic():
    global np
    np = Placeholder(NUMPY_ORIGINAL_POINTER)
    assert_rand_arrays()
def test_containers():
    a = Placeholder(my_list)
Esempio 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]
Esempio n. 8
0
def test_async():
    coroutine_func = Placeholder(do_something)
    coroutine = Placeholder(do_something())
    run_tasks(coroutine_func(), coroutine)