Ejemplo n.º 1
0
def test_multivalue_mutation():
    schema = MultiValue.of(Integer)
    el = schema()

    eq_(el.value, None)
    eq_(el.u, u'')
    eq_(list(el), [])
    eq_(len(el), 0)
    assert not el

    el.set([1, 2])
    eq_(el.value, 1)
    eq_(el.u, u'1')
    eq_(len(el), 2)
    assert el

    el.insert(0, 0)
    eq_(el.value, 0)
    eq_(el.u, u'0')
    eq_(len(el), 3)

    el[0].set(9)
    eq_(el.value, 9)
    eq_(el.u, u'9')
    eq_([child.value for child in el], [9, 1, 2])
    eq_(len(el), 3)
Ejemplo n.º 2
0
def test_multivalue_set():
    schema = MultiValue.of(Integer)
    el = schema()

    eq_(el.value, None)
    eq_(el.u, u'')
    eq_(list(el), [])
    eq_(len(el), 0)
    assert not el

    assert not el.set(0)
    assert el.value is None

    assert el.set([])
    assert not el.value

    assert el.set([0])
    eq_(el.value, 0)
    eq_(el.u, u'0')
    assert len(el) == 1
    assert el

    el = schema([0, 1])
    eq_(el.value, 0)
    eq_(el.u, u'0')
    assert len(el) == 2
    assert el
Ejemplo n.º 3
0
def test_multivalue_mutation():
    schema = MultiValue.of(Integer)
    el = schema()

    eq_(el.value, None)
    eq_(el.u, u'')
    eq_(list(el), [])
    eq_(len(el), 0)
    assert not el

    el.set([1, 2])
    eq_(el.value, 1)
    eq_(el.u, u'1')
    eq_(len(el), 2)
    assert el

    el.insert(0, 0)
    eq_(el.value, 0)
    eq_(el.u, u'0')
    eq_(len(el), 3)

    el[0].set(9)
    eq_(el.value, 9)
    eq_(el.u, u'9')
    eq_([child.value for child in el], [9, 1, 2])
    eq_(len(el), 3)
Ejemplo n.º 4
0
def test_multivalue_set():
    schema = MultiValue.of(Integer)
    el = schema()

    eq_(el.value, None)
    eq_(el.u, u'')
    eq_(list(el), [])
    eq_(len(el), 0)
    assert not el

    assert not el.set(0)
    assert el.value is None

    assert el.set([])
    assert not el.value

    assert el.set([0])
    eq_(el.value, 0)
    eq_(el.u, u'0')
    assert len(el) == 1
    assert el

    el = schema([0, 1])
    eq_(el.value, 0)
    eq_(el.u, u'0')
    assert len(el) == 2
    assert el
Ejemplo n.º 5
0
def test_multivalue_mutation():
    schema = MultiValue.of(Integer)
    el = schema()

    assert el.value is None
    assert el.u == u''
    assert list(el) == []
    assert len(el) == 0
    assert not el

    el.set([1, 2])
    assert el.value == 1
    assert el.u == u'1'
    assert len(el) == 2
    assert el

    el.insert(0, 0)
    assert el.value == 0
    assert el.u == u'0'
    assert len(el) == 3

    el[0].set(9)
    assert el.value == 9
    assert el.u == u'9'
    assert [child.value for child in el] == [9, 1, 2]
    assert len(el) == 3
Ejemplo n.º 6
0
def test_multivalue_set():
    schema = MultiValue.of(Integer)
    el = schema()

    assert el.value is None
    assert el.u == u''
    assert list(el) == []
    assert len(el) == 0
    assert not el

    assert not el.set(0)
    assert el.value is None

    assert el.set([])
    assert not el.value

    assert el.set([0])
    assert el.value == 0
    assert el.u == u'0'
    assert len(el) == 1
    assert el

    el = schema([0, 1])
    assert el.value == 0
    assert el.u == u'0'
    assert len(el) == 2
    assert el
Ejemplo n.º 7
0
def test_multivalue_roundtrip():
    schema = MultiValue.of(String.named(u's'))
    data = [u'abc', u'def']
    el = schema(data)
    assert [e.value for e in el] == data

    flat = el.flatten()
    assert flat == [(u's', u'abc'), (u's', u'def')]
    restored = schema.from_flat(flat)
    assert restored.value == u'abc'
    assert [e.value for e in restored] == data
Ejemplo n.º 8
0
def test_multivalue_roundtrip():
    schema = MultiValue.of(String.named(u's'))
    data = [u'abc', u'def']
    el = schema(data)
    eq_([e.value for e in el], data)

    flat = el.flatten()
    eq_(flat, [(u's', u'abc'), (u's', u'def')])
    restored = schema.from_flat(flat)
    eq_(restored.value, u'abc')
    eq_([e.value for e in restored], data)
Ejemplo n.º 9
0
def test_multivalue_roundtrip():
    schema = MultiValue.of(String.named(u's'))
    data = [u'abc', u'def']
    el = schema(data)
    eq_([e.value for e in el], data)

    flat = el.flatten()
    eq_(flat, [(u's', u'abc'), (u's', u'def')])
    restored = schema.from_flat(flat)
    eq_(restored.value, u'abc')
    eq_([e.value for e in restored], data)
Ejemplo n.º 10
0
def test_multivalue_set_flat_fully_anonymous_array():
    schema = MultiValue.of(String)
    pairs = [(u'', u'abc'), (u'', u'def')]

    _assert_multivalue_set_flat(schema, pairs)
Ejemplo n.º 11
0
def test_multivalue_set_flat_fully_anonymous_array():
    schema = MultiValue.of(String)
    pairs = [(u'', u'abc'), (u'', u'def')]

    _assert_multivalue_set_flat(schema, pairs)
Ejemplo n.º 12
0
def test_multivalue_set_flat_anonymous_array():
    schema = MultiValue.of(String.named(u's'))
    pairs = [(u's', u'abc'), (u's', u'def')]
    bogus = [(u'', u'xxx')]

    _assert_multivalue_set_flat(schema, pairs, bogus)
Ejemplo n.º 13
0
def test_multivalue_set_flat_unnamed_child():
    pairs = [(u's', u'abc'), (u's', u'def')]
    bogus = [(u'', u'xxx')]
    schema = MultiValue.named(u's').of(String)

    _assert_multivalue_set_flat(schema, pairs, bogus)
Ejemplo n.º 14
0
def test_multivalue_set_flat_unpruned():
    pairs = [(u's', u'val0'), (u's', ''), (u's', u'val1'), (u's', u'')]
    schema = MultiValue.of(String).named(u's').using(prune_empty=False)

    _assert_multivalue_set_flat(schema, pairs)
Ejemplo n.º 15
0
def test_multivalue_set_flat_unpruned():
    pairs = [(u's', u'val0'), (u's', ''), (u's', u'val1'), (u's', u'')]
    schema = MultiValue.of(String).named(u's').using(prune_empty=False)

    _assert_multivalue_set_flat(schema, pairs)
Ejemplo n.º 16
0
def test_multivalue_set_flat_like_named():
    pairs = [(u's_s', u'abc'), (u's_s', u'def')]
    bogus = [(u's', u'xxx')]
    schema = MultiValue.named(u's').of(String.named(u's'))

    _assert_multivalue_set_flat(schema, pairs, bogus)
Ejemplo n.º 17
0
def test_multivalue_set_flat_unnamed_child():
    pairs = [(u's', u'abc'), (u's', u'def')]
    bogus = [(u'', 'xxx')]
    schema = MultiValue.named(u's').of(String)

    _assert_multivalue_set_flat(schema, pairs, bogus)
Ejemplo n.º 18
0
def test_multivalue_set_flat_anonymous_array():
    schema = MultiValue.of(String.named(u's'))
    pairs = [(u's', u'abc'), (u's', u'def')]
    bogus = [(u'', 'xxx')]

    _assert_multivalue_set_flat(schema, pairs, bogus)