<commit_before>import sqlalchemy as sa
from tests import TestCase
from sqlalchemy_utils import (
    NumberRangeType,
    NumberRange,
    coercion_listener
)


class TestNumberRangeType(TestCase):
    def create_models(self):
        class Building(self.Base):
            __tablename__ = 'building'
            id = sa.Column(sa.Integer, primary_key=True)
            persons_at_night = sa.Column(NumberRangeType)

            def __repr__(self):
                return 'Building(%r)' % self.id

        self.Building = Building

    def test_save_number_range(self):
        building = self.Building(
            persons_at_night=NumberRange(1, 3)
        )

        self.session.add(building)
        self.session.commit()
        building = self.session.query(self.Building).first()
        assert building.persons_at_night.lower == 1
        assert building.persons_at_night.upper == 3

    def test_infinite_upper_bound(self):
        building = self.Building(
            persons_at_night=NumberRange(1, float('inf'))
        )
        self.session.add(building)
        self.session.commit()
        building = self.session.query(self.Building).first()
        assert building.persons_at_night.lower == 1
        assert building.persons_at_night.upper is None

    def test_nullify_number_range(self):
        building = self.Building(
            persons_at_night=NumberRange(1, 3)
        )

        self.session.add(building)
        self.session.commit()

        building = self.session.query(self.Building).first()
        building.persons_at_night = None
        self.session.commit()

        building = self.session.query(self.Building).first()
        assert building.persons_at_night is None

    def test_string_coercion(self):
        building = self.Building(persons_at_night='[12, 18]')

        assert isinstance(building.persons_at_night, NumberRange)

    def test_integer_coercion(self):
        building = self.Building(persons_at_night=15)
        assert building.persons_at_night.lower == 15
        assert building.persons_at_night.upper == 15
<commit_msg>More tests for number range<commit_after>import sqlalchemy as sa
from tests import TestCase
from sqlalchemy_utils import (
    NumberRangeType,
    NumberRange,
    coercion_listener
)


class TestNumberRangeType(TestCase):
    def create_models(self):
        class Building(self.Base):
            __tablename__ = 'building'
            id = sa.Column(sa.Integer, primary_key=True)
            persons_at_night = sa.Column(NumberRangeType)

            def __repr__(self):
                return 'Building(%r)' % self.id

        self.Building = Building

    def test_save_number_range(self):
        building = self.Building(
            persons_at_night=NumberRange(1, 3)
        )

        self.session.add(building)
        self.session.commit()
        building = self.session.query(self.Building).first()
        assert building.persons_at_night.lower == 1
        assert building.persons_at_night.upper == 3

    def test_infinite_upper_bound(self):
        building = self.Building(
            persons_at_night=NumberRange(1, float('inf'))
        )
        self.session.add(building)
        self.session.commit()
        building = self.session.query(self.Building).first()
        assert building.persons_at_night.lower == 1
        assert building.persons_at_night.upper is None

    def test_infinite_lower_bound(self):
        building = self.Building(
            persons_at_night=NumberRange(-float('inf'), 1)
        )
        self.session.add(building)
        self.session.commit()
        building = self.session.query(self.Building).first()
        assert building.persons_at_night.lower is None
        assert building.persons_at_night.upper is 1

    def test_nullify_number_range(self):
        building = self.Building(
            persons_at_night=NumberRange(1, 3)
        )

        self.session.add(building)
        self.session.commit()

        building = self.session.query(self.Building).first()
        building.persons_at_night = None
        self.session.commit()

        building = self.session.query(self.Building).first()
        assert building.persons_at_night is None

    def test_string_coercion(self):
        building = self.Building(persons_at_night='[12, 18]')

        assert isinstance(building.persons_at_night, NumberRange)

    def test_integer_coercion(self):
        building = self.Building(persons_at_night=15)
        assert building.persons_at_night.lower == 15
        assert building.persons_at_night.upper == 15

{'fraction_non_alphanumeric': 0.09303852889667251, 'fraction_numerical': 0.008318739054290718, 'mean_word_length': 2.6175771971496435, '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': '1343208', 'n_tokens_mistral': 1384, 'n_tokens_neox': 1307, 'n_words': 230}