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
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)
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
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
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)
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
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)
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)
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)
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)