Exemple #1
0
def test_scalar_set_default():
    el = Integer()
    el.set_default()
    assert el.value is None

    el = Integer(default=10)
    el.set_default()
    assert el.value == 10

    el = Integer(default_factory=lambda e: 20)
    el.set_default()
    assert el.value == 20
Exemple #2
0
def test_scalar_set_signal():
    data = []
    sentinel = lambda sender, adapted: data.append((sender, adapted))

    Integer(0)
    with element_set.connected_to(sentinel):
        Integer(1)
        Integer(u'bogus')

    assert len(data) == 2
    assert data[0][0].value == 1
    assert data[0][1] is True

    assert data[1][0].raw == u'bogus'
    assert data[1][1] is False
Exemple #3
0
def test_sparsedict_flattening():
    schema = SparseDict.named(u'top').\
                        of(Integer.named(u'x'), Integer.named(u'y'))

    els = [
        schema({u'x': 123, u'y': 456}),
        schema(),
        schema(),
        schema(),
        ]
    els[1].set({u'x': 123, u'y': 456})
    els[2][u'x'] = 123
    els[2][u'y'] = 456
    els[3][u'x'] = Integer(123)
    els[3][u'y'] = Integer(456)

    wanted = [(u'top_x', u'123'), (u'top_y', u'456')]
    for el in els:
        got = sorted(el.flatten())
        assert wanted == got
Exemple #4
0
def test_binops():
    schema = Dict.of(Integer.named(u'main'),
                     Ref.named(u'aux').to(u'../main'), Integer.named(u'other'))
    el = schema({u'main': 5})

    assert el[u'aux'] == Integer(5)
    assert el[u'aux'].value == 5
    assert el[u'aux'].u == u'5'
    assert Integer(5) == el[u'aux']
    assert 5 == el[u'aux'].value
    assert u'5' == el[u'aux'].u

    assert el[u'aux'] != Integer(6)
    assert el[u'aux'].value != 6
    assert el[u'aux'].u != u'6'
    assert Integer(6) != el[u'aux']
    assert 6 != el[u'aux']
    assert u'6' != el[u'aux']

    assert el[u'aux'] == el[u'main']
    assert el[u'main'] == el[u'aux']
    assert el[u'aux'] != el[u'other']
    assert el[u'other'] != el[u'aux']
Exemple #5
0
def integer_scalar(value):
    return Integer(value, name=u'test')