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 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
|
# coding: utf-8
import pytest # type: ignore # NOQA
from roundtrip import ( # type: ignore # NOQA
dedent,
round_trip,
round_trip_dump,
round_trip_load,
)
# http://yaml.org/type/int.html is where underscores in integers are defined
class TestFloat:
def test_round_trip_non_exp(self) -> None:
data = round_trip(
"""\
- 1.0
- 1.00
- 23.100
- -1.0
- -1.00
- -23.100
- 42.
- -42.
- +42.
- .5
- +.5
- -.5
- !!float '42'
- !!float '-42'
"""
)
print(data)
assert 0.999 < data[0] < 1.001
assert 0.999 < data[1] < 1.001
assert 23.099 < data[2] < 23.101
assert 0.999 < -data[3] < 1.001
assert 0.999 < -data[4] < 1.001
assert 23.099 < -data[5] < 23.101
assert 41.999 < data[6] < 42.001
assert 41.999 < -data[7] < 42.001
assert 41.999 < data[8] < 42.001
assert 0.49 < data[9] < 0.51
assert 0.49 < data[10] < 0.51
assert -0.51 < data[11] < -0.49
assert 41.99 < data[12] < 42.01
assert 41.99 < -data[13] < 42.01
def test_round_trip_zeros_0(self) -> None:
data = round_trip(
"""\
- 0.
- +0.
- -0.
- 0.0
- +0.0
- -0.0
- 0.00
- +0.00
- -0.00
"""
)
print(data)
for d in data:
assert -0.00001 < d < 0.00001
def test_round_trip_exp_trailing_dot(self) -> None:
data = round_trip(
"""\
- 3.e4
"""
)
print(data)
def test_yaml_1_1_no_dot(self) -> None:
from ruyaml.error import MantissaNoDotYAML1_1Warning
with pytest.warns(MantissaNoDotYAML1_1Warning):
round_trip_load(
"""\
%YAML 1.1
---
- 1e6
"""
)
class TestCalculations:
def test_mul_00(self) -> None:
# issue 149 reported by jan.brezina@tul.cz
d = round_trip_load(
"""\
- 0.1
"""
)
d[0] *= -1
x = round_trip_dump(d)
assert x == '- -0.1\n'
|