File: test_babel.py

package info (click to toggle)
python-pint 0.9-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 1,068 kB
  • sloc: python: 9,481; makefile: 138
file content (41 lines) | stat: -rw-r--r-- 1,277 bytes parent folder | download
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
31
32
33
34
35
36
37
38
39
40
41
# -*- coding: utf-8 -*-
from __future__ import division, unicode_literals, print_function, absolute_import

from pint.testsuite import helpers, BaseTestCase
from pint import UnitRegistry
import os
import unittest

class TestBabel(BaseTestCase):

    @helpers.requires_proper_babel()
    @unittest.skip("Not working on Debian")
    def test_babel(self):
        ureg = UnitRegistry()
        dirname = os.path.dirname(__file__)
        ureg.load_definitions(os.path.join(dirname, '../xtranslated.txt'))

        distance = 24.0 * ureg.meter
        self.assertEqual(
            distance.format_babel(locale='fr_FR', length='long'),
            "24.0 mètres"
        )
        time = 8.0 * ureg.second
        self.assertEqual(
            time.format_babel(locale='fr_FR', length='long'),
            "8.0 secondes"
        )
        self.assertEqual(
            time.format_babel(locale='ro', length='short'),
            "8.0 s"
        )
        acceleration = distance / time ** 2
        self.assertEqual(
            acceleration.format_babel(locale='fr_FR', length='long'),
            "0.375 mètre par seconde²"
        )
        mks = ureg.get_system('mks')
        self.assertEqual(
            mks.format_babel(locale='fr_FR'),
            "métrique"
        )