summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorjryannel <juergen@ryannel.org>2017-04-19 10:33:51 +0200
committerGitHub <noreply@github.com>2017-04-19 10:33:51 +0200
commit80c7b9cedabb7db5356981cada2561f6d29b7b99 (patch)
tree8584b59be413e964f63595fb6939df119cc43817 /tests
parent7a9f38795010772e117de6ad4b3b32ed442234e7 (diff)
downloadqtivi-qface-80c7b9cedabb7db5356981cada2561f6d29b7b99.tar.gz
Added support for JSON serialization (#43)
Added jsonify filter
Diffstat (limited to 'tests')
-rw-r--r--tests/test_json.py51
1 files changed, 51 insertions, 0 deletions
diff --git a/tests/test_json.py b/tests/test_json.py
new file mode 100644
index 0000000..b4fea24
--- /dev/null
+++ b/tests/test_json.py
@@ -0,0 +1,51 @@
+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]
+ interface = module['interfaces'][0]
+ assert interface['name'] == 'Tuner'
+