<commit_before>import pytest

from tri.struct import NamedStruct, named_struct, FrozenStruct, NamedStructField


def test_init():
    assert named_struct('foo')().keys() == ['foo']
    assert sorted(named_struct(['foo', 'bar'])().keys()) == ['bar', 'foo']
    assert sorted(named_struct('foo, bar')().keys()) == ['bar', 'foo']
    assert named_struct('foo, bar')().__class__.__name__ == 'NamedStruct'

    assert sorted(named_struct('foo, bar', 'SomeName')().keys()) == ['bar', 'foo']
    assert named_struct('foo, bar', 'SomeName')().__class__.__name__ == 'SomeName'


TestNamedStruct = named_struct('foo')


def test_access():
    s = TestNamedStruct()
    assert s.foo is None

    s.foo = 17
    assert s.foo == 17
    assert s['foo'] == 17


def test_read_constraints():
    s = TestNamedStruct()
    with pytest.raises(AttributeError):
        # noinspection PyStatementEffect
        s.bar


def test_write_constraints():
    s = TestNamedStruct()
    with pytest.raises(AttributeError):
        # noinspection PyStatementEffect
        s.bar = 17


def test_constructor():
    MyNamedStruct = named_struct('foo, bar')
    s = MyNamedStruct(bar=42, foo=17)
    assert s == dict(foo=17, bar=42)


def test_contstructor_failure():
    MyNamedStruct = named_struct('foo, bar')

    with pytest.raises(ValueError):
        MyNamedStruct(1, 2, 3)  # Too many args
<commit_msg>Fix error message when running tests<commit_after>import pytest

from tri.struct import NamedStruct, named_struct, FrozenStruct, NamedStructField


def test_init():
    assert named_struct('foo')().keys() == ['foo']
    assert sorted(named_struct(['foo', 'bar'])().keys()) == ['bar', 'foo']
    assert sorted(named_struct('foo, bar')().keys()) == ['bar', 'foo']
    assert named_struct('foo, bar')().__class__.__name__ == 'NamedStruct'

    assert sorted(named_struct('foo, bar', 'SomeName')().keys()) == ['bar', 'foo']
    assert named_struct('foo, bar', 'SomeName')().__class__.__name__ == 'SomeName'


MyNamedStruct = named_struct('foo')


def test_access():
    s = MyNamedStruct()
    assert s.foo is None

    s.foo = 17
    assert s.foo == 17
    assert s['foo'] == 17


def test_read_constraints():
    s = MyNamedStruct()
    with pytest.raises(AttributeError):
        # noinspection PyStatementEffect
        s.bar


def test_write_constraints():
    s = MyNamedStruct()
    with pytest.raises(AttributeError):
        # noinspection PyStatementEffect
        s.bar = 17


def test_constructor():
    MyNamedStruct = named_struct('foo, bar')
    s = MyNamedStruct(bar=42, foo=17)
    assert s == dict(foo=17, bar=42)


def test_contstructor_failure():
    MyNamedStruct = named_struct('foo, bar')

    with pytest.raises(ValueError):
        MyNamedStruct(1, 2, 3)  # Too many args

{'fraction_non_alphanumeric': 0.1530133525802959, 'fraction_numerical': 0.013713460844460484, 'mean_word_length': 3.9323843416370106, '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': '5801641', 'n_tokens_mistral': 926, 'n_tokens_neox': 897, 'n_words': 207}