<commit_before>import numpy
import pytest

import snuggs

# Fixtures follow the tests. See the end of the file.


def test_integer():
    assert list(snuggs.integer.parseString('1')) == [1]


def test_real():
    assert list(snuggs.real.parseString('1.1')) == [1.1]


def test_int_expr():
    assert snuggs.eval('(+ 1 2)') == 3


def test_int_mult_expr():
    assert snuggs.eval('(+ 1 2 3)') == 6


def test_real_expr():
    assert round(snuggs.eval('(* 0.1 0.2)'), 3) == 0.02


def test_int_real_expr():
    assert snuggs.eval('(+ 2 1.1)') == 3.1


def test_real_int_expr():
    assert snuggs.eval('(+ 1.1 2)') == 3.1


def test_arr_var(ones):
    r = snuggs.eval('(+ foo 0)', foo=ones)
    assert list(r.flatten()) == [1, 1, 1, 1]


def test_arr_lookup(ones):
    r = snuggs.eval('(read 1)', foo=ones)
    assert list(r.flatten()) == [1, 1, 1, 1]


def test_arr_lookup_2(ones):
    r = snuggs.eval('(read 1 1)', foo=ones)
    assert list(r.flatten()) == [1, 1]


def test_arr_take(ones):
    r = snuggs.eval('(take foo 1)', foo=ones)
    assert list(r.flatten()) == [1, 1]
    r = snuggs.eval('(take foo 2)', foo=ones)
    assert list(r.flatten()) == [1, 1]<commit_msg>Add test that catches and shows issue #9 fix<commit_after>from collections import OrderedDict

import numpy
import pytest

import snuggs

# Fixtures follow the tests. See the end of the file.


def test_integer():
    assert list(snuggs.integer.parseString('1')) == [1]


def test_real():
    assert list(snuggs.real.parseString('1.1')) == [1.1]


def test_int_expr():
    assert snuggs.eval('(+ 1 2)') == 3


def test_int_mult_expr():
    assert snuggs.eval('(+ 1 2 3)') == 6


def test_real_expr():
    assert round(snuggs.eval('(* 0.1 0.2)'), 3) == 0.02


def test_int_real_expr():
    assert snuggs.eval('(+ 2 1.1)') == 3.1


def test_real_int_expr():
    assert snuggs.eval('(+ 1.1 2)') == 3.1


def test_arr_var(ones):
    r = snuggs.eval('(+ foo 0)', foo=ones)
    assert list(r.flatten()) == [1, 1, 1, 1]


def test_arr_lookup(ones):
    kwargs = OrderedDict((('foo', ones),
                          ('bar', 2.0 * ones),
                          ('a', 3.0 * ones)))
    r = snuggs.eval('(read 1)', kwargs)
    assert list(r.flatten()) == [1, 1, 1, 1]
    # Passed via kwargs this should fail (see issue #9)
    r = snuggs.eval('(read 1)', **kwargs)
    assert list(r.flatten()) != [1, 1, 1, 1]


def test_arr_lookup_2(ones):
    r = snuggs.eval('(read 1 1)', foo=ones)
    assert list(r.flatten()) == [1, 1]


def test_arr_take(ones):
    r = snuggs.eval('(take foo 1)', foo=ones)
    assert list(r.flatten()) == [1, 1]
    r = snuggs.eval('(take foo 2)', foo=ones)
    assert list(r.flatten()) == [1, 1]
{'fraction_non_alphanumeric': 0.19106145251396647, 'fraction_numerical': 0.04283054003724395, 'mean_word_length': 3.2232704402515724, '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': '6561820', 'n_tokens_mistral': 1152, 'n_tokens_neox': 1050, 'n_words': 277}