1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
|
from django.test import TestCase
from pint import DimensionalityError
import quantityfield.fields as fields
import quantityfield.helper as helper
from quantityfield.units import ureg
class TestMatchingUnitDimensionsHelper(TestCase):
def test_valid_choices(self):
helper.check_matching_unit_dimension(ureg, "meter", ["mile", "foot", "cm"])
def test_invalid_choices(self):
with self.assertRaises(DimensionalityError):
helper.check_matching_unit_dimension(
ureg, "meter", ["mile", "foot", "cm", "kg"]
)
class TestEdgeCases(TestCase):
def test_fix_unit_registry(self):
field = fields.IntegerQuantityField("meter")
with self.assertRaises(ValueError):
field.fix_unit_registry(1)
def test_get_prep_value(self):
field = fields.IntegerQuantityField("meter")
with self.assertRaises(ValueError):
field.get_prep_value("foobar")
|