Ejemplo n.º 1
0
def test_c_to_python_and_back(Class):
    """ checks module object can  be changed and subclassed from C """
    import gc
    from nose.tools import assert_is, assert_is_not, assert_equal
    from numpy.testing import assert_allclose, assert_equal as np_assert_equal
    from numpy import all, abs
    from pylada.crystal.cppwrappers import Atom
    from pylada.crystal.tests.atom_self import get_static_object, set_static_object, _atom
    
    a = Class(0.3,0.1,0.2, 'Au')
    set_static_object(a)
    c = get_static_object();
    assert_is(c, a)
    assert_is(c.__class__, Class)
    assert_allclose(a.pos, [0.3, 0.1, 0.2])
    assert_equal(a.type, 'Au')
    # checks same as above but with deletion.
    a = Class(0.4,0.1,0.2, 'Au', 'Pd', m=5)
    set_static_object(a)
    del a; del c; gc.collect()
    c = get_static_object();
    assert_is(c.__class__, Class)
    assert_allclose(c.pos, [0.4, 0.1, 0.2])
    np_assert_equal(c.type, ['Au', 'Pd'])
    assert_equal(c.__dict__, {'m': 5})
Ejemplo n.º 2
0
def test_c_object_to_python():
    from nose.tools import assert_is
    from pylada.crystal.tests.atom_self import get_static_object, _atom
    
    # checks the static object is an Atom at start.
    a = get_static_object();
    assert_is(a.__class__, Atom)
    assert_is(a, _atom)
    # checks the static object is always itself.
    b = get_static_object();
    assert_is(a, b)
    assert_is(b, _atom)