File: test_gitlab_data_transform.py

package info (click to toggle)
python-check-jsonschema 0.34.1-1
  • links: PTS
  • area: main
  • in suites: sid
  • size: 3,796 kB
  • sloc: python: 5,529; makefile: 4
file content (56 lines) | stat: -rw-r--r-- 1,324 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
import pytest

from check_jsonschema.parsers.yaml import ParseError, construct_yaml_implementation
from check_jsonschema.transforms.gitlab import (
    GITLAB_TRANSFORM,
    GitLabReferenceExpectationViolation,
)


def test_can_parse_yaml_with_transform():
    rawdata = """\
a: b
c: d
"""

    impl = construct_yaml_implementation()

    data = impl.load(rawdata)
    assert data == {"a": "b", "c": "d"}

    GITLAB_TRANSFORM.modify_yaml_implementation(impl)
    data = impl.load(rawdata)
    assert data == {"a": "b", "c": "d"}


def test_can_parse_ok_gitlab_yaml_with_transform():
    rawdata = """\
foo:
- !reference [bar, baz]
"""
    impl = construct_yaml_implementation()

    with pytest.raises(ParseError):
        data = impl.load(rawdata)

    GITLAB_TRANSFORM.modify_yaml_implementation(impl)
    data = impl.load(rawdata)
    assert data == {"foo": [["bar", "baz"]]}


def test_cannot_parse_bad_gitlab_yaml_with_transform():
    rawdata = """\
foo:
- !reference true
"""
    impl = construct_yaml_implementation()

    with pytest.raises(ParseError):
        impl.load(rawdata)

    GITLAB_TRANSFORM.modify_yaml_implementation(impl)
    with pytest.raises(
        GitLabReferenceExpectationViolation,
        match=r"check-jsonschema rejects this gitlab \!reference tag: .*",
    ):
        impl.load(rawdata)