File: test_int.py

package info (click to toggle)
python-srsly 2.5.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,256 kB
  • sloc: python: 17,567; ansic: 1,434; sh: 12; makefile: 6
file content (36 lines) | stat: -rwxr-xr-x 907 bytes parent folder | download | duplicates (3)
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
# coding: utf-8

from __future__ import print_function, absolute_import, division, unicode_literals

import pytest  # NOQA

from .roundtrip import dedent, round_trip_load, round_trip_dump

# http://yaml.org/type/int.html is where underscores in integers are defined


class TestBinHexOct:
    def test_calculate(self):
        # make sure type, leading zero(s) and underscore are preserved
        s = dedent(
            """\
        - 42
        - 0b101010
        - 0x_2a
        - 0x2A
        - 0o00_52
        """
        )
        d = round_trip_load(s)
        for idx, elem in enumerate(d):
            elem -= 21
            d[idx] = elem
        for idx, elem in enumerate(d):
            elem *= 2
            d[idx] = elem
        for idx, elem in enumerate(d):
            t = elem
            elem **= 2
            elem //= t
            d[idx] = elem
        assert round_trip_dump(d) == s