Esempio n. 1
0
def test_variable_methods():
    """Test the variable modification methods.

    """
    v = Variable()
    assert v.name() == ""
    v.setName(u'γ')
    assert v.name() == 'γ'
    v.setName('foo')
    assert v.name() == 'foo'
    with pytest.raises(TypeError):
        v.setName(1)
    if sys.version_info >= (3,):
        with pytest.raises(TypeError):
            v.setName(b'r')

    assert v.value() == 0.0

    assert v.context() is None
    ctx = object()
    v.setContext(ctx)
    assert v.context() is ctx

    assert str(v) == 'foo'

    with pytest.raises(TypeError):
        Variable(1)
Esempio n. 2
0
def test_variable_methods():
    """Test the variable modification methods.

    """
    v = Variable()
    assert v.name() == ""
    v.setName(u'γ')
    assert v.name() == 'γ'
    v.setName('foo')
    assert v.name() == 'foo'
    with pytest.raises(TypeError):
        v.setName(1)
    if sys.version_info >= (3, ):
        with pytest.raises(TypeError):
            v.setName(b'r')

    assert v.value() == 0.0

    assert v.context() is None
    ctx = object()
    v.setContext(ctx)
    assert v.context() is ctx

    assert str(v) == 'foo'

    with pytest.raises(TypeError):
        Variable(1)