File: test_formatting.py

package info (click to toggle)
python-quantities 0.16.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, trixie
  • size: 864 kB
  • sloc: python: 8,006; makefile: 72; sh: 3
file content (17 lines) | stat: -rw-r--r-- 439 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
from .. import units as pq
from .common import TestCase


class TestFormatting(TestCase):

    @staticmethod
    def _check(quantity, formatted):
        assert str(quantity) == formatted
        assert f'{quantity}' == formatted
        assert f'{quantity!s}' == formatted

    def test_str_format_scalar(self):
        self._check(1*pq.J, '1.0 J')

    def test_str_format_non_scalar(self):
        self._check([1, 2]*pq.J, '[1. 2.] J')