File: test_deprecation.py

package info (click to toggle)
python-ruyaml 0.92.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,732 kB
  • sloc: python: 19,399; makefile: 200; sh: 13
file content (133 lines) | stat: -rw-r--r-- 4,147 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
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# coding: utf-8

import sys

import pytest  # type:ignore  # NOQA

last_to_warn = (0, 17, 40)


@pytest.mark.skipif(
    sys.version_info < (3, 7) or sys.version_info >= (3, 9),  # type: ignore
    reason='collections not available?',
)
def test_collections_deprecation() -> None:
    with pytest.warns(DeprecationWarning):
        from collections import Hashable  # type: ignore  # NOQA


class TestFunctionDeprecation:
    def test_deprecation_scan(self) -> None:
        import ruyaml

        if ruyaml.version_info <= last_to_warn:
            with pytest.warns(PendingDeprecationWarning):
                data = ruyaml.load('a: 42')  # NOQA
        else:
            with pytest.raises(AttributeError):
                data = ruyaml.load('a: 42')  # NOQA

    def test_deprecation_parse(self) -> None:
        import ruyaml

        if ruyaml.version_info <= last_to_warn:
            data = ruyaml.parse('a: 42')  # NOQA
        else:
            with pytest.raises(AttributeError):
                data = ruyaml.parse('a: 42')  # NOQA

    def test_deprecation_compose(self) -> None:
        import ruyaml

        if ruyaml.version_info <= last_to_warn:
            with pytest.warns(PendingDeprecationWarning):
                data = ruyaml.compose('a: 42')  # NOQA
        else:
            with pytest.raises(AttributeError):
                data = ruyaml.parse('a: 42')  # NOQA

    def test_deprecation_compose_all(self) -> None:
        import ruyaml

        if ruyaml.version_info <= last_to_warn:
            data = ruyaml.compose_all('a: 42')  # NOQA
        else:
            with pytest.raises(AttributeError):
                data = ruyaml.parse('a: 42')  # NOQA

    def test_deprecation_load(self) -> None:
        import ruyaml

        if ruyaml.version_info <= last_to_warn:
            with pytest.warns(PendingDeprecationWarning):
                data = ruyaml.load('a: 42')  # NOQA
        else:
            with pytest.raises(AttributeError):
                data = ruyaml.parse('a: 42')  # NOQA

    def test_deprecation_load_all(self) -> None:
        import ruyaml

        if ruyaml.version_info <= last_to_warn:
            data = ruyaml.load_all('a: 42')  # NOQA
        else:
            with pytest.raises(AttributeError):
                data = ruyaml.parse('a: 42')  # NOQA

    def test_deprecation_safe_load(self) -> None:
        import ruyaml

        if ruyaml.version_info <= last_to_warn:
            with pytest.warns(PendingDeprecationWarning):
                data = ruyaml.safe_load('a: 42')  # NOQA
        else:
            with pytest.raises(AttributeError):
                data = ruyaml.parse('a: 42')  # NOQA

    def test_deprecation_round_trip_load(self) -> None:
        import ruyaml

        if ruyaml.version_info <= last_to_warn:
            with pytest.warns(PendingDeprecationWarning):
                data = ruyaml.round_trip_load('a: 42')  # NOQA
        else:
            with pytest.raises(AttributeError):
                data = ruyaml.parse('a: 42')  # NOQA


class TestYamlTyp:
    def test_unsafe_deprecation(self) -> None:
        import ruyaml

        if ruyaml.version_info < (0, 18, 0):
            yaml = ruyaml.YAML(typ='unsafe')
        else:
            with pytest.warns(PendingDeprecationWarning):
                #   with pytest.raises(SystemExit):
                yaml = ruyaml.YAML(typ='unsafe')  # NOQA

    def test_full_load_error(self) -> None:
        import ruyaml

        yaml = ruyaml.YAML(typ='full', pure=True)
        with pytest.raises(ruyaml.error.YAMLError):
            yaml.load('a: b')
        yaml = ruyaml.YAML(typ='full')  # C scanner/loader
        with pytest.raises(ruyaml.error.YAMLError):
            yaml.load('a: b')

    def test_full_rt(self) -> None:
        import io
        import os

        import ruyaml

        yaml = ruyaml.YAML(typ='full', pure=True)
        buf = io.BytesIO()
        yaml.dump([{'fun': os.system}], buf)
        print(buf.getvalue())
        yaml = ruyaml.YAML()
        data = yaml.load(buf.getvalue())
        print(data)
        ts = data[0]['fun']
        assert 'posix.system' in str(ts.tag)