Ejemplo n.º 1
0
def test_constructor():
    body = Body(399)
    assert body.id == 399
    assert body.name == 'EARTH'
    pytest.raises(ValueError, Body, 398)
    pytest.raises(TypeError, Body, 399.5)
    with pytest.raises(AttributeError):
        body.id = 10
    with pytest.raises(AttributeError):
        body.name = 'MARS'
Ejemplo n.º 2
0
def test_constructor(idcode, name, children, parent, class_):
    # constructor and cache
    assert idcode not in Body._CACHE
    body = Body(idcode)
    assert idcode in Body._CACHE
    assert body is Body._CACHE[idcode]
    assert Body(idcode) is body
    assert type(body) is class_
    # properties
    assert body.id == idcode
    assert body.name == name
    with pytest.raises(AttributeError):
        body.id = idcode
    with pytest.raises(AttributeError):
        body.name = name
    # parent/children
    try:
        assert body.parent().id == parent
    except AttributeError:
        assert type(body) is bodies.Barycenter
        assert body.parent() is None
    assert [child.id for child in body.children()] == children