<commit_before>import mock
import numpy
import pytest

from constants import DUMMY_VALUE_1, DUMMY_VALUE_2, DUMMY_VALUE_3
import pytac
from pytac.units import NullUnitConv, PchipUnitConv, PolyUnitConv, UnitConv


def f1(value):
    return value * 2


def f2(value):
    return value / 2


def test_UnitConv_not_implemented():
    uc = UnitConv(0)
    with pytest.raises(NotImplementedError):
        uc.convert(10, pytac.PHYS, pytac.ENG)
    with pytest.raises(NotImplementedError):
        uc.convert(-11, pytac.ENG, pytac.PHYS)


def test_set_conversion_limits():
    uc = UnitConv(0)
    assert uc.lower_limit is None
    assert uc.upper_limit is None
    uc.set_conversion_limits(0, 1)
    assert uc.lower_limit == 0
    assert uc.upper_limit == 1
    uc.set_conversion_limits(0.1, 2.1)
    assert uc.lower_limit == 0.1
    assert uc.upper_limit == 2.1
    uc.set_conversion_limits(-1, 1e5)
    assert uc.lower_limit == -1
    assert uc.upper_limit == 1e5


@pytest.mark.parametrize('origin, target', [(pytac.ENG, pytac.PHYS),
                                            (pytac.PHYS, pytac.ENG)])
def test_UnitConv_raises_UnitsException_for_values_outside_limits(origin,
                                                                  target):
    uc = NullUnitConv()
    uc.set_conversion_limits(0, 10)
    with pytest.raises(pytac.exceptions.UnitsException):
        uc.convert(-1, origin, target)  # below lower limit
    with pytest.raises(pytac.exceptions.UnitsException):
        uc.convert(11, origin, target)  # above upper limit


def test_UnitConv_includes_name_in_exception():
    uc = UnitConv(name='test_unitconv')
    with pytest.raises(NotImplementedError) as e:
        uc.convert(10, pytac.ENG, pytac.PHYS)
    assert 'test_unitconv' in str(e)


@pytest.mark.parametrize('origin, target', [(pytac.LIVE, pytac.ENG),
                                            (pytac.PHYS, pytac.SP),
                                            ('a', 'b')])
def test_UnitConv_requires_correct_arguments(origin, target):
    uc = UnitConv(name=12)
    assert uc.name == 12<commit_msg>Use pytest to check exception message.<commit_after>import mock
import numpy
import pytest

from constants import DUMMY_VALUE_1, DUMMY_VALUE_2, DUMMY_VALUE_3
import pytac
from pytac.units import NullUnitConv, PchipUnitConv, PolyUnitConv, UnitConv


def f1(value):
    return value * 2


def f2(value):
    return value / 2


def test_UnitConv_not_implemented():
    uc = UnitConv(0)
    with pytest.raises(NotImplementedError):
        uc.convert(10, pytac.PHYS, pytac.ENG)
    with pytest.raises(NotImplementedError):
        uc.convert(-11, pytac.ENG, pytac.PHYS)


def test_set_conversion_limits():
    uc = UnitConv(0)
    assert uc.lower_limit is None
    assert uc.upper_limit is None
    uc.set_conversion_limits(0, 1)
    assert uc.lower_limit == 0
    assert uc.upper_limit == 1
    uc.set_conversion_limits(0.1, 2.1)
    assert uc.lower_limit == 0.1
    assert uc.upper_limit == 2.1
    uc.set_conversion_limits(-1, 1e5)
    assert uc.lower_limit == -1
    assert uc.upper_limit == 1e5


@pytest.mark.parametrize('origin, target', [(pytac.ENG, pytac.PHYS),
                                            (pytac.PHYS, pytac.ENG)])
def test_UnitConv_raises_UnitsException_for_values_outside_limits(origin,
                                                                  target):
    uc = NullUnitConv()
    uc.set_conversion_limits(0, 10)
    with pytest.raises(pytac.exceptions.UnitsException):
        uc.convert(-1, origin, target)  # below lower limit
    with pytest.raises(pytac.exceptions.UnitsException):
        uc.convert(11, origin, target)  # above upper limit


def test_UnitConv_includes_name_in_exception():
    uc = UnitConv(name='test_unitconv')
    with pytest.raises(NotImplementedError, match="test_unitconv"):
        uc.convert(10, pytac.ENG, pytac.PHYS)


@pytest.mark.parametrize('origin, target', [(pytac.LIVE, pytac.ENG),
                                            (pytac.PHYS, pytac.SP),
                                            ('a', 'b')])
def test_UnitConv_requires_correct_arguments(origin, target):
    uc = UnitConv(name=12)
    assert uc.name == 12
{'fraction_non_alphanumeric': 0.10215311004784688, 'fraction_numerical': 0.02057416267942584, 'mean_word_length': 2.6739894551845342, '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': 16, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '613176', 'n_tokens_mistral': 1499, 'n_tokens_neox': 1394, 'n_words': 281}