summaryrefslogtreecommitdiff
path: root/grc/tests/test_yaml_checker.py
blob: 0b658a1087134622590b554f339829ad39890346 (plain)
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
# Copyright 2016 Free Software Foundation, Inc.
# This file is part of GNU Radio
#
# SPDX-License-Identifier: GPL-2.0-or-later
#

import yaml

from grc.core.schema_checker import Validator, BLOCK_SCHEME


BLOCK1 = """
id: block_key
label: testname

parameters:
-   id: vlen
    label: Vec Length
    dtype: int
    default: 1
-   id: out_type
    label: Vec Length
    dtype: string
    default: complex
-   id: a
    label: Alpha
    dtype: ${ out_type }
    default: '0'

inputs:
-   label: in
    domain: stream
    dtype: complex
    vlen: ${ 2 * vlen }
-   name: in2
    domain: message
    id: in2

outputs:
-   label: out
    domain: stream
    dtype: ${ out_type }
    vlen: ${ vlen }

templates:
    make: blocks.complex_to_mag_squared(${ vlen })

file_format: 1
"""


def test_min():
    checker = Validator(BLOCK_SCHEME)
    assert checker.run({'id': 'test', 'file_format': 1}), checker.messages
    assert not checker.run({'name': 'test', 'file_format': 1})


def test_extra_keys():
    checker = Validator(BLOCK_SCHEME)
    assert checker.run({'id': 'test', 'abcdefg': 'nonsense', 'file_format': 1})
    assert checker.messages == [('block', 'warn', "Ignoring extra key 'abcdefg'")]


def test_checker():
    checker = Validator(BLOCK_SCHEME)
    data = yaml.safe_load(BLOCK1)
    passed = checker.run(data)
    if not passed:
        print()
        for msg in checker.messages:
            print(msg)

    assert passed, checker.messages