File: test_loader.py

package info (click to toggle)
python-annotatedyaml 1.0.2-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,088 kB
  • sloc: python: 1,303; makefile: 18
file content (601 lines) | stat: -rw-r--r-- 20,069 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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
"""Test annotatedyaml loader."""

import asyncio
import importlib
import io
import os
import pathlib
from collections.abc import Generator
from typing import Any
from unittest.mock import Mock, patch

import pytest
import voluptuous as vol
import yaml as pyyaml

import annotatedyaml as yaml_util
from annotatedyaml import YAMLException
from annotatedyaml import loader as yaml_loader
from tests.common import YAML_CONFIG_FILE


def _get_annotation(item: Any) -> tuple[str, int | str] | None:
    if not hasattr(item, "__config_file__"):
        return None

    return (item.__config_file__, getattr(item, "__line__", "?"))


@pytest.fixture(params=["enable_c_loader", "disable_c_loader"])
def try_both_loaders(request: pytest.FixtureRequest) -> Generator[None]:
    """Disable the yaml c loader."""
    if request.param != "disable_c_loader":
        yield
        return
    try:
        cloader = pyyaml.CSafeLoader
    except ImportError:
        return
    del pyyaml.CSafeLoader
    importlib.reload(yaml_loader)
    yield
    pyyaml.CSafeLoader = cloader
    importlib.reload(yaml_loader)


@pytest.fixture(params=["enable_c_dumper", "disable_c_dumper"])
def try_both_dumpers(request: pytest.FixtureRequest) -> Generator[None]:
    """Disable the yaml c dumper."""
    if request.param != "disable_c_dumper":
        yield
        return
    try:
        cdumper = pyyaml.CSafeDumper
    except ImportError:
        return
    del pyyaml.CSafeDumper
    importlib.reload(yaml_loader)
    yield
    pyyaml.CSafeDumper = cdumper
    importlib.reload(yaml_loader)


@pytest.mark.usefixtures("try_both_loaders")
def test_simple_list() -> None:
    """Test simple list."""
    conf = "config:\n  - simple\n  - list"
    with io.StringIO(conf) as file:
        doc = yaml_loader.parse_yaml(file)
    assert doc["config"] == ["simple", "list"]


@pytest.mark.usefixtures("try_both_loaders")
def test_simple_dict() -> None:
    """Test simple dict."""
    conf = "key: value"
    with io.StringIO(conf) as file:
        doc = yaml_loader.parse_yaml(file)
    assert doc["key"] == "value"


@pytest.mark.parametrize("mock_yaml", ["message:\n  {{ states.state }}"])
@pytest.mark.usefixtures("try_both_loaders", "patch_yaml_config")
def test_unhashable_key(mock_yaml: None) -> None:
    """Test an unhashable key."""
    with pytest.raises(YAMLException):
        yaml_loader.load_yaml(YAML_CONFIG_FILE)


@pytest.mark.parametrize("mock_yaml", ["a: a\nnokeyhere"])
@pytest.mark.usefixtures("try_both_loaders", "patch_yaml_config")
def test_no_key(mock_yaml: None) -> None:
    """Test item without a key."""
    with pytest.raises(YAMLException):
        yaml_util.load_yaml(YAML_CONFIG_FILE)


@pytest.mark.usefixtures("try_both_loaders")
def test_environment_variable() -> None:
    """Test config file with environment variable."""
    os.environ["PASSWORD"] = "secret_password"  # noqa: S105
    conf = "password: !env_var PASSWORD"
    with io.StringIO(conf) as file:
        doc = yaml_loader.parse_yaml(file)
    assert doc["password"] == "secret_password"  # noqa: S105
    del os.environ["PASSWORD"]


@pytest.mark.usefixtures("try_both_loaders")
def test_environment_variable_default() -> None:
    """Test config file with default value for environment variable."""
    conf = "password: !env_var PASSWORD secret_password"
    with io.StringIO(conf) as file:
        doc = yaml_loader.parse_yaml(file)
    assert doc["password"] == "secret_password"  # noqa: S105


@pytest.mark.usefixtures("try_both_loaders")
def test_invalid_environment_variable() -> None:
    """Test config file with no environment variable sat."""
    conf = "password: !env_var PASSWORD"
    with pytest.raises(YAMLException), io.StringIO(conf) as file:
        yaml_loader.parse_yaml(file)


@pytest.mark.parametrize(
    ("mock_yaml_files", "value"),
    [
        ({"test.yaml": "value"}, "value"),
        ({"test.yaml": None}, {}),
        ({"test.yaml": "123"}, 123),
    ],
)
@pytest.mark.usefixtures("try_both_loaders", "patch_yaml_config")
def test_include_yaml(mock_yaml_files: None, value: Any) -> None:
    """Test include yaml."""
    conf = "key: !include test.yaml"
    with io.StringIO(conf) as file:
        doc = yaml_loader.parse_yaml(file)
        assert doc["key"] == value


@patch("annotatedyaml.loader.os.walk")
@pytest.mark.parametrize(
    ("mock_yaml_files", "value"),
    [
        ({"/test/one.yaml": "one", "/test/two.yaml": "two"}, ["one", "two"]),
        ({"/test/one.yaml": "1", "/test/two.yaml": "2"}, [1, 2]),
        ({"/test/one.yaml": "1", "/test/two.yaml": None}, [1]),
    ],
)
@pytest.mark.usefixtures("try_both_loaders", "patch_yaml_config")
def test_include_dir_list(mock_walk: Mock, mock_yaml_files: None, value: Any) -> None:
    """Test include dir list yaml."""
    mock_walk.return_value = [["/test", [], ["two.yaml", "one.yaml"]]]

    conf = "key: !include_dir_list /test"
    with io.StringIO(conf) as file:
        doc = yaml_loader.parse_yaml(file)
        assert sorted(doc["key"]) == sorted(value)


@patch("annotatedyaml.loader.os.walk")
@pytest.mark.parametrize(
    "mock_yaml_files",
    [
        {
            "/test/zero.yaml": "zero",
            "/test/tmp2/one.yaml": "one",
            "/test/tmp2/two.yaml": "two",
        }
    ],
)
@pytest.mark.usefixtures("try_both_loaders", "patch_yaml_config")
def test_include_dir_list_recursive(mock_walk: Mock, mock_yaml_files: None) -> None:
    """Test include dir recursive list yaml."""
    mock_walk.return_value = [
        ["/test", ["tmp2", ".ignore", "ignore"], ["zero.yaml"]],
        ["/test/tmp2", [], ["one.yaml", "two.yaml"]],
        ["/test/ignore", [], [".ignore.yaml"]],
    ]

    conf = "key: !include_dir_list /test"
    with io.StringIO(conf) as file:
        assert ".ignore" in mock_walk.return_value[0][1], "Expecting .ignore in here"
        doc = yaml_loader.parse_yaml(file)
        assert "tmp2" in mock_walk.return_value[0][1]
        assert ".ignore" not in mock_walk.return_value[0][1]
        assert sorted(doc["key"]) == sorted(["zero", "one", "two"])


@patch("annotatedyaml.loader.os.walk")
@pytest.mark.parametrize(
    ("mock_yaml_files", "value"),
    [
        (
            {"/test/first.yaml": "one", "/test/second.yaml": "two"},
            {"first": "one", "second": "two"},
        ),
        (
            {"/test/first.yaml": "1", "/test/second.yaml": "2"},
            {"first": 1, "second": 2},
        ),
        (
            {"/test/first.yaml": "1", "/test/second.yaml": None},
            {"first": 1, "second": {}},
        ),
    ],
)
@pytest.mark.usefixtures("try_both_loaders", "patch_yaml_config")
def test_include_dir_named(mock_walk: Mock, mock_yaml_files: None, value: Any) -> None:
    """Test include dir named yaml."""
    mock_walk.return_value = [
        ["/test", [], ["first.yaml", "second.yaml", "secrets.yaml"]]
    ]

    conf = "key: !include_dir_named /test"
    with io.StringIO(conf) as file:
        doc = yaml_loader.parse_yaml(file)
        assert doc["key"] == value


@patch("annotatedyaml.loader.os.walk")
@pytest.mark.parametrize(
    "mock_yaml_files",
    [
        {
            "/test/first.yaml": "one",
            "/test/tmp2/second.yaml": "two",
            "/test/tmp2/third.yaml": "three",
        }
    ],
)
@pytest.mark.usefixtures("try_both_loaders", "patch_yaml_config")
def test_include_dir_named_recursive(mock_walk: Mock, mock_yaml_files: None) -> None:
    """Test include dir named yaml."""
    mock_walk.return_value = [
        ["/test", ["tmp2", ".ignore", "ignore"], ["first.yaml"]],
        ["/test/tmp2", [], ["second.yaml", "third.yaml"]],
        ["/test/ignore", [], [".ignore.yaml"]],
    ]

    conf = "key: !include_dir_named /test"
    correct = {"first": "one", "second": "two", "third": "three"}
    with io.StringIO(conf) as file:
        assert ".ignore" in mock_walk.return_value[0][1], "Expecting .ignore in here"
        doc = yaml_loader.parse_yaml(file)
        assert "tmp2" in mock_walk.return_value[0][1]
        assert ".ignore" not in mock_walk.return_value[0][1]
        assert doc["key"] == correct


@patch("annotatedyaml.loader.os.walk")
@pytest.mark.parametrize(
    ("mock_yaml_files", "value"),
    [
        (
            {"/test/first.yaml": "- one", "/test/second.yaml": "- two\n- three"},
            ["one", "two", "three"],
        ),
        (
            {"/test/first.yaml": "- 1", "/test/second.yaml": "- 2\n- 3"},
            [1, 2, 3],
        ),
        (
            {"/test/first.yaml": "- 1", "/test/second.yaml": None},
            [1],
        ),
    ],
)
@pytest.mark.usefixtures("try_both_loaders", "patch_yaml_config")
def test_include_dir_merge_list(
    mock_walk: Mock, mock_yaml_files: None, value: Any
) -> None:
    """Test include dir merge list yaml."""
    mock_walk.return_value = [["/test", [], ["first.yaml", "second.yaml"]]]

    conf = "key: !include_dir_merge_list /test"
    with io.StringIO(conf) as file:
        doc = yaml_loader.parse_yaml(file)
        assert sorted(doc["key"]) == sorted(value)


@patch("annotatedyaml.loader.os.walk")
@pytest.mark.parametrize(
    "mock_yaml_files",
    [
        {
            "/test/first.yaml": "- one",
            "/test/tmp2/second.yaml": "- two",
            "/test/tmp2/third.yaml": "- three\n- four",
        }
    ],
)
@pytest.mark.usefixtures("try_both_loaders", "patch_yaml_config")
def test_include_dir_merge_list_recursive(
    mock_walk: Mock, mock_yaml_files: None
) -> None:
    """Test include dir merge list yaml."""
    mock_walk.return_value = [
        ["/test", ["tmp2", ".ignore", "ignore"], ["first.yaml"]],
        ["/test/tmp2", [], ["second.yaml", "third.yaml"]],
        ["/test/ignore", [], [".ignore.yaml"]],
    ]

    conf = "key: !include_dir_merge_list /test"
    with io.StringIO(conf) as file:
        assert ".ignore" in mock_walk.return_value[0][1], "Expecting .ignore in here"
        doc = yaml_loader.parse_yaml(file)
        assert "tmp2" in mock_walk.return_value[0][1]
        assert ".ignore" not in mock_walk.return_value[0][1]
        assert sorted(doc["key"]) == sorted(["one", "two", "three", "four"])


@patch("annotatedyaml.loader.os.walk")
@pytest.mark.parametrize(
    ("mock_yaml_files", "value"),
    [
        (
            {
                "/test/first.yaml": "key1: one",
                "/test/second.yaml": "key2: two\nkey3: three",
            },
            {"key1": "one", "key2": "two", "key3": "three"},
        ),
        (
            {
                "/test/first.yaml": "key1: 1",
                "/test/second.yaml": "key2: 2\nkey3: 3",
            },
            {"key1": 1, "key2": 2, "key3": 3},
        ),
        (
            {
                "/test/first.yaml": "key1: 1",
                "/test/second.yaml": None,
            },
            {"key1": 1},
        ),
    ],
)
@pytest.mark.usefixtures("try_both_loaders", "patch_yaml_config")
def test_include_dir_merge_named(
    mock_walk: Mock, mock_yaml_files: None, value: Any
) -> None:
    """Test include dir merge named yaml."""
    mock_walk.return_value = [["/test", [], ["first.yaml", "second.yaml"]]]

    conf = "key: !include_dir_merge_named /test"
    with io.StringIO(conf) as file:
        doc = yaml_loader.parse_yaml(file)
        assert doc["key"] == value


@patch("annotatedyaml.loader.os.walk")
@pytest.mark.parametrize(
    "mock_yaml_files",
    [
        {
            "/test/first.yaml": "key1: one",
            "/test/tmp2/second.yaml": "key2: two",
            "/test/tmp2/third.yaml": "key3: three\nkey4: four",
        }
    ],
)
@pytest.mark.usefixtures("try_both_loaders", "patch_yaml_config")
def test_include_dir_merge_named_recursive(
    mock_walk: Mock, mock_yaml_files: None
) -> None:
    """Test include dir merge named yaml."""
    mock_walk.return_value = [
        ["/test", ["tmp2", ".ignore", "ignore"], ["first.yaml"]],
        ["/test/tmp2", [], ["second.yaml", "third.yaml"]],
        ["/test/ignore", [], [".ignore.yaml"]],
    ]

    conf = "key: !include_dir_merge_named /test"
    with io.StringIO(conf) as file:
        assert ".ignore" in mock_walk.return_value[0][1], "Expecting .ignore in here"
        doc = yaml_loader.parse_yaml(file)
        assert "tmp2" in mock_walk.return_value[0][1]
        assert ".ignore" not in mock_walk.return_value[0][1]
        assert doc["key"] == {
            "key1": "one",
            "key2": "two",
            "key3": "three",
            "key4": "four",
        }


@patch("annotatedyaml.loader.open", create=True)
@pytest.mark.usefixtures("try_both_loaders")
def test_load_yaml_encoding_error(mock_open: Mock) -> None:
    """Test raising a UnicodeDecodeError."""
    mock_open.side_effect = UnicodeDecodeError("", b"", 1, 0, "")
    with pytest.raises(YAMLException):
        yaml_loader.load_yaml("test")


@pytest.mark.usefixtures("try_both_dumpers")
def test_dump() -> None:
    """The that the dump method returns empty None values."""
    assert yaml_util.dump({"a": None, "b": "b"}) == "a:\nb: b\n"


@pytest.mark.usefixtures("try_both_dumpers")
def test_dump_unicode() -> None:
    """The that the dump method returns empty None values."""
    assert yaml_util.dump({"a": None, "b": "привет"}) == "a:\nb: привет\n"


@pytest.mark.parametrize("mock_yaml", ['key: [1, "2", 3]'])
@pytest.mark.usefixtures("try_both_dumpers", "patch_yaml_config")
def test_representing_yaml_loaded_data(mock_yaml: None) -> None:
    """Test we can represent YAML loaded data."""
    data = yaml_loader.load_yaml(YAML_CONFIG_FILE)
    assert yaml_util.dump(data) == "key:\n- 1\n- '2'\n- 3\n"


@pytest.mark.parametrize("mock_yaml", ["key: thing1\nkey: thing2"])
@pytest.mark.usefixtures("try_both_loaders", "patch_yaml_config")
def test_duplicate_key(caplog: pytest.LogCaptureFixture, mock_yaml: None) -> None:
    """Test duplicate dict keys."""
    yaml_loader.load_yaml(YAML_CONFIG_FILE)
    assert "contains duplicate key" in caplog.text


@pytest.mark.parametrize(
    "mock_yaml_files",
    [{YAML_CONFIG_FILE: "key: !secret a", yaml_util.SECRET_YAML: "a: 1\nb: !secret a"}],
)
@pytest.mark.usefixtures("try_both_loaders", "patch_yaml_config")
def test_no_recursive_secrets(mock_yaml_files: None) -> None:
    """Test that loading of secrets from the secrets file fails correctly."""
    with pytest.raises(YAMLException) as e:
        yaml_loader.load_yaml(YAML_CONFIG_FILE)

    assert e.value.args == ("Secrets not supported in this YAML file",)


def test_input_class() -> None:
    """Test input class."""
    yaml_input = yaml_util.Input("hello")
    yaml_input2 = yaml_util.Input("hello")

    assert yaml_input.name == "hello"
    assert yaml_input == yaml_input2

    assert len({yaml_input, yaml_input2}) == 1


@pytest.mark.usefixtures("try_both_loaders", "try_both_dumpers")
def test_input() -> None:
    """Test loading inputs."""
    data = {"hello": yaml_util.Input("test_name")}
    assert yaml_util.parse_yaml(yaml_util.dump(data)) == data


@pytest.mark.skipif(
    not os.environ.get("HASS_CI"),
    reason="This test validates that the CI has the C loader available",
)
def test_c_loader_is_available_in_ci() -> None:
    """Verify we are testing the C loader in the CI."""
    assert yaml_util.loader.HAS_C_LOADER is True


@pytest.mark.usefixtures("try_both_loaders")
@pytest.mark.asyncio
async def test_loading_actual_file_with_syntax_error() -> None:
    """Test loading a real file with syntax errors."""
    fixture_path = pathlib.Path(__file__).parent.joinpath("fixtures", "bad.yaml.txt")
    loop = asyncio.get_event_loop()

    with pytest.raises(YAMLException):
        await loop.run_in_executor(None, yaml_loader.load_yaml, fixture_path, None)


@pytest.mark.usefixtures("try_both_loaders")
def test_string_annotated() -> None:
    """Test strings are annotated with file + line."""
    conf = (
        "key1: str\n"
        "key2:\n"
        "  blah: blah\n"
        "key3:\n"
        " - 1\n"
        " - 2\n"
        " - 3\n"
        "key4: yes\n"
        "key5: 1\n"
        "key6: 1.0\n"
    )
    expected_annotations = {
        "key1": [("<file>", 1), ("<file>", 1)],
        "key2": [("<file>", 2), ("<file>", 3)],
        "key3": [("<file>", 4), ("<file>", 5)],
        "key4": [("<file>", 8), (None, None)],
        "key5": [("<file>", 9), (None, None)],
        "key6": [("<file>", 10), (None, None)],
    }
    with io.StringIO(conf) as file:
        doc = yaml_loader.parse_yaml(file)
    for key, value in doc.items():
        assert getattr(key, "__config_file__", None) == expected_annotations[key][0][0]
        assert getattr(key, "__line__", None) == expected_annotations[key][0][1]
        assert (
            getattr(value, "__config_file__", None) == expected_annotations[key][1][0]
        )
        assert getattr(value, "__line__", None) == expected_annotations[key][1][1]


@pytest.mark.usefixtures("try_both_loaders")
def test_string_used_as_vol_schema() -> None:
    """Test the subclassed strings can be used in voluptuous schemas."""
    conf = "wanted_data:\n  key_1: value_1\n  key_2: value_2\n"
    with io.StringIO(conf) as file:
        doc = yaml_loader.parse_yaml(file)

    # Test using the subclassed strings in a schema
    schema = vol.Schema(
        {vol.Required(key): value for key, value in doc["wanted_data"].items()},
    )
    # Test using the subclassed strings when validating a schema
    schema(doc["wanted_data"])
    schema({"key_1": "value_1", "key_2": "value_2"})
    with pytest.raises(vol.Invalid):
        schema({"key_1": "value_2", "key_2": "value_1"})


@pytest.mark.parametrize(
    ("mock_yaml", "expected_data"), [("", {}), ("bla:", {"bla": None})]
)
@pytest.mark.usefixtures("try_both_loaders", "patch_yaml_config")
def test_load_yaml_dict(mock_yaml: None, expected_data: Any) -> None:
    """Test item without a key."""
    assert yaml_util.load_yaml_dict(YAML_CONFIG_FILE) == expected_data


@pytest.mark.parametrize("mock_yaml", ["abc", "123", "[]"])
@pytest.mark.usefixtures("try_both_loaders", "patch_yaml_config")
def test_load_yaml_dict_fail(mock_yaml: None) -> None:
    """Test item without a key."""
    with pytest.raises(YAMLException):
        yaml_loader.load_yaml_dict(YAML_CONFIG_FILE)


@pytest.mark.parametrize(
    "tag",
    [
        "!include",
        "!include_dir_named",
        "!include_dir_merge_named",
        "!include_dir_list",
        "!include_dir_merge_list",
    ],
)
@pytest.mark.usefixtures("try_both_loaders")
def test_include_without_parameter(tag: str) -> None:
    """Test include extensions without parameters."""
    with (
        io.StringIO(f"key: {tag}") as file,
        pytest.raises(YAMLException, match=f"{tag} needs an argument"),
    ):
        yaml_loader.parse_yaml(file)


@pytest.mark.parametrize(
    ("open_exception", "load_yaml_exception"),
    [
        (FileNotFoundError, OSError),
        (NotADirectoryError, YAMLException),
        (PermissionError, YAMLException),
    ],
)
@pytest.mark.usefixtures("try_both_loaders")
def test_load_yaml_wrap_oserror(
    open_exception: Exception,
    load_yaml_exception: Exception,
) -> None:
    """Test load_yaml wraps OSError in AnnotatedYAMLOSError."""
    with (
        patch("annotatedyaml.loader.open", side_effect=open_exception),
        pytest.raises(load_yaml_exception),
    ):
        yaml_loader.load_yaml("bla")


@pytest.mark.parametrize("mock_yaml", ["key: !include missing.yaml"])
@pytest.mark.usefixtures("try_both_loaders", "patch_yaml_config")
def test_load_missing_included_file(mock_yaml: None) -> None:
    """Test loading a file that includes a missing file."""
    with pytest.raises(YAMLException):
        yaml_loader.load_yaml(YAML_CONFIG_FILE)


@pytest.mark.parametrize("mock_yaml", ['key: [1, "2", 3]'])
@pytest.mark.usefixtures("try_both_dumpers", "patch_yaml_config")
def test_getting_annotation(mock_yaml: None) -> None:
    """Test we can fetch annotations in pure python."""
    data = yaml_loader.load_yaml(YAML_CONFIG_FILE)
    assert _get_annotation(data) == ("test.yaml", 1)