aboutsummaryrefslogtreecommitdiffstats
path: root/tests/test_json.py
blob: 785680ad59a05c64e3cfb16273b47d28d60741a1 (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
from qface.generator import FileSystem
import logging
from path import Path
import json

# logging.config.fileConfig('logging.ini')
logging.basicConfig()

log = logging.getLogger(__name__)

inputPath = Path('tests/in')


def loadEcho():
    path = inputPath / 'org.example.echo.qface'
    return FileSystem.parse_document(path)


def load_tuner():
    path = inputPath / 'com.pelagicore.ivi.tuner.qface'
    return FileSystem.parse_document(path)


def test_echo_json():
    system = loadEcho()
    data = system.toJson()
    text = json.dumps(data)
    data = json.loads(text)
    assert len(data['modules']) == 1
    module = data['modules'][0]
    assert module['name'] == 'org.example.echo'
    assert module['version'] == '1.0'
    assert len(module['interfaces']) == 1
    interface = module['interfaces'][0]
    assert interface['name'] == 'Echo'
    assert len(interface['operations']) == 1
    # string echo(string msg);
    operation = interface['operations'][0]
    assert operation['parameters'][0]['name'] == 'msg'
    assert operation['parameters'][0]['type']['name'] == 'string'


def test_tuner_json():
    system = load_tuner()
    data = system.toJson()
    text = json.dumps(data)
    data = json.loads(text)
    module = data['modules'][0]
    assert len(module['interfaces']) == 3
    interface = module['interfaces'][0]
    assert interface['name'] == 'BaseTuner'
    interface = module['interfaces'][1]
    assert interface['name'] == 'Tuner'