<commit_before>from inspect import isabstract

from nose.tools import assert_not_equals
from nose.tools import assert_raises
from nose.tools import assert_raises_regexp
from nose.tools import eq_
from nose.tools import ok_

from pyrecord import Record
from pyrecord import RecordTypeError


def test_abstract():
    ok_(isabstract(Record))


def test_creation():
    Point = Record.create_type("Point", "coordinate_x", "coordinate_y")
    eq_("Point", Point.__name__)
    ok_(issubclass(Point, Record))
    assert_not_equals(Point, Record)


def test_subtype_creation():
    Point = Record.create_type("Point", "coordinate_x", "coordinate_y")
    Circle = Point.extend_type("Circle", "radius")
    eq_("Circle", Circle.__name__)
    ok_(issubclass(Circle, Point))
    assert_not_equals(Circle, Point)


def test_creation_with_ilegal_type_name():
    assert_raises(RecordTypeError, Record.create_type, "Invalid-Name")


def test_creation_with_ilegal_field_name():
    assert_raises(
        RecordTypeError,
        Record.create_type,
        "Point",
        "coordinate-x",
        )


def test_creation_with_duplicated_field_names():
    # Same field duplicated by position
    assert_raises_regexp(
        RecordTypeError,
        "^The following field names are duplicated: coordinate_x$",
        Record.create_type,
        "Point",
        "coordinate_x",
        "coordinate_x",
        )
    
    # Same field duplicated by position and name
    assert_raises_regexp(
        RecordTypeError,
        "^The following field names are duplicated: coordinate_x$",
        Record.create_type,
        "Point",
        "coordinate_x",
        coordinate_x=2,
        )
    
    # Multiple fields duplicated
    assert_raises_regexp(
        RecordTypeError,
        "^The following field names are duplicated: " \
            "coordinate_y, coordinate_x$",
        Record.create_type,
        "Point",
        "coordinate_x",
        "coordinate_y",
        coordinate_x=2,
        coordinate_y=2,
        )<commit_msg>Added missing tests for record subtypes.<commit_after>from inspect import isabstract

from nose.tools import assert_not_equals
from nose.tools import assert_raises
from nose.tools import assert_raises_regexp
from nose.tools import eq_
from nose.tools import ok_

from pyrecord import Record
from pyrecord import RecordTypeError


def test_abstract():
    ok_(isabstract(Record))


def test_creation():
    Point = Record.create_type("Point", "coordinate_x", "coordinate_y")
    eq_("Point", Point.__name__)
    ok_(issubclass(Point, Record))
    assert_not_equals(Point, Record)


def test_subtype_creation():
    Point = Record.create_type("Point", "coordinate_x", "coordinate_y")
    Circle = Point.extend_type("Circle", "radius")
    eq_("Circle", Circle.__name__)
    ok_(issubclass(Circle, Point))
    assert_not_equals(Circle, Point)


def test_creation_with_ilegal_type_name():
    # Supertype
    assert_raises(RecordTypeError, Record.create_type, "Invalid-Name")
    
    # Subtype
    Point = Record.create_type("Point", "coordinate_x", "coordinate_y")
    assert_raises(RecordTypeError, Point.extend_type, "Invalid-Name")


def test_creation_with_ilegal_field_name():
    # Supertype
    assert_raises(
        RecordTypeError,
        Record.create_type,
        "Point",
        "coordinate-x",
        )
    
    # Subtype
    Point = Record.create_type("Point", "coordinate_x", "coordinate_y")
    assert_raises(RecordTypeError, Point.extend_type, "Circle", "Invalid-Field")


def test_creation_with_duplicated_field_names():
    # Same field duplicated by position
    assert_raises_regexp(
        RecordTypeError,
        "^The following field names are duplicated: coordinate_x$",
        Record.create_type,
        "Point",
        "coordinate_x",
        "coordinate_x",
        )
    
    # Same field duplicated by position and name
    assert_raises_regexp(
        RecordTypeError,
        "^The following field names are duplicated: coordinate_x$",
        Record.create_type,
        "Point",
        "coordinate_x",
        coordinate_x=2,
        )
    
    # Multiple fields duplicated
    assert_raises_regexp(
        RecordTypeError,
        "^The following field names are duplicated: " \
            "coordinate_y, coordinate_x$",
        Record.create_type,
        "Point",
        "coordinate_x",
        "coordinate_y",
        coordinate_x=2,
        coordinate_y=2,
        )
    
    # Subtype
    Point = Record.create_type("Point", "coordinate_x", "coordinate_y")
    assert_raises_regexp(
        RecordTypeError,
        "^The following field names are duplicated: radius$",
        Point.extend_type,
        "Circle",
        "radius",
        "radius",
        )
    
    # Subtype redefining field
    Point = Record.create_type("Point", "coordinate_x", "coordinate_y")
    assert_raises_regexp(
        RecordTypeError,
        "^The following field names are duplicated: coordinate_x$",
        Point.extend_type,
        "Circle",
        "radius",
        "coordinate_x",
        )
{'fraction_non_alphanumeric': 0.09405255878284924, 'fraction_numerical': 0.0011855364552459987, 'mean_word_length': 3.011093502377179, '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': '7455494', 'n_tokens_mistral': 1554, 'n_tokens_neox': 1484, 'n_words': 328}