File: test_helper.py

package info (click to toggle)
python-django-pint 0.7.3-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 432 kB
  • sloc: python: 1,531; makefile: 28; sh: 12
file content (30 lines) | stat: -rw-r--r-- 952 bytes parent folder | download | duplicates (2)
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")