<commit_before>from flatland import (
    Integer,
    List,
    String,
)
from flatland.schema.base import Unspecified

from tests._util import eq_, assert_raises


def test_set_flat_linear():
    pairs = [(u'l_0_i', 1), (u'l_1_i', 2), (u'l_2_i', 3)]

    schema = List.named(u'l').of(Integer.named(u'i'))
    el = schema.from_flat(pairs)

    eq_(len(el), len(pairs))
    eq_(el.value, list(pair[1] for pair in pairs))


def test_set_flat_miss():
    pairs = [(u'l_galump', u'3'), (u'l_snorgle', u'4')]

    schema = List.named(u'l').of(Integer.named(u'i'))
    el = schema.from_flat(pairs)

    eq_(len(el), 0)
    eq_(el.value, [])


def test_set_flat_pruned():
    # pruned won't insert empty elements for a skipped index or empty rhs
    pairs = [(u'l_0_i', u'0'), (u'l_2_i', u''), (u'l_3_i', u'3')]
<commit_msg>Test that List.set_flat does not respond to (listname, value)<commit_after>from flatland import (
    Integer,
    List,
    String,
)
from flatland.schema.base import Unspecified

from tests._util import eq_


def test_set_flat_linear():
    pairs = [(u'l_0_i', 1), (u'l_1_i', 2), (u'l_2_i', 3)]

    schema = List.named(u'l').of(Integer.named(u'i'))
    el = schema.from_flat(pairs)

    eq_(len(el), len(pairs))
    eq_(el.value, list(pair[1] for pair in pairs))


def test_set_flat_miss():
    pairs = [(u'l_galump', u'3'), (u'l_snorgle', u'4')]

    schema = List.named(u'l').of(Integer.named(u'i'))
    el = schema.from_flat(pairs)

    eq_(len(el), 0)
    eq_(el.value, [])


def test_set_flat_scalar():
    pairs = [(u'l', u'1')]

    schema = List.named(u'l').of(Integer.named(u'i'))
    el = schema()
    canary = []
    def setter(self, value):
        canary.append(value)
        return type(el).set(self, value)
    el.set = setter.__get__(el, type(el))

    el.set_flat(pairs)
    eq_(len(el), 0)
    eq_(el.value, [])
    eq_(canary, [])


def test_set_flat_pruned():
    # pruned won't insert empty elements for a skipped index or empty rhs
    pairs = [(u'l_0_i', u'0'), (u'l_2_i', u''), (u'l_3_i', u'3')]

{'fraction_non_alphanumeric': 0.1831537708129285, 'fraction_numerical': 0.015670910871694418, 'mean_word_length': 3.6117381489841986, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6857443', 'n_tokens_mistral': 874, 'n_tokens_neox': 836, 'n_words': 174}