diff options
author | Juergen Bocklage-Ryannel <juergen.bocklage-ryannel@pelagicore.com> | 2016-08-02 12:40:57 +0200 |
---|---|---|
committer | Juergen Ryannel <juergen.bocklage-ryannel@pelagicore.com> | 2016-11-30 10:01:19 +0100 |
commit | ada58821a68c61d9bc905ce793dd4d0f6b497645 (patch) | |
tree | 4f9dede65368fcb04155fc8298f3a2381b0705b9 /tests | |
parent | 6a3dd2248f24670ad70a28a70e848e33eac651c5 (diff) | |
download | qtivi-qface-ada58821a68c61d9bc905ce793dd4d0f6b497645.tar.gz |
initial commit
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_climate.py | 29 | ||||
-rw-r--r-- | tests/test_generator.py | 41 | ||||
-rw-r--r-- | tests/test_parser.py | 81 |
3 files changed, 151 insertions, 0 deletions
diff --git a/tests/test_climate.py b/tests/test_climate.py new file mode 100644 index 0000000..5e628e4 --- /dev/null +++ b/tests/test_climate.py @@ -0,0 +1,29 @@ +from qif.idl.domain import System +from qif.generator import FileSystem, Generator +import logging +import logging.config +from pathlib import Path + +# logging.config.fileConfig('logging.ini') +logging.basicConfig() + +log = logging.getLogger(__name__) + +examples = Path('./examples') +log.debug('examples folder: {0}'.format(examples.absolute())) + + +def load_system(): + path = examples / 'climate.qif' + return FileSystem.parse_document(path) + + +def test_service(): + system = load_system() + service = system.lookup_service('vehicle.climate.ClimateControl') + assert service.name == 'ClimateControl' + + + + + diff --git a/tests/test_generator.py b/tests/test_generator.py new file mode 100644 index 0000000..1f86ff2 --- /dev/null +++ b/tests/test_generator.py @@ -0,0 +1,41 @@ +from qif.idl.domain import System +from qif.generator import FileSystem, Generator +import logging +import logging.config +from pathlib import Path + +# logging.config.fileConfig('logging.ini') +logging.basicConfig() + +log = logging.getLogger(__name__) + +examples = Path('./examples') +log.debug('examples folder: {0}'.format(examples.absolute())) + + +def loadSystem(): + path = examples / 'tuner.qif' + return FileSystem.parse_document(path) + + +def test_gen_package(): + system = loadSystem() + gen = Generator() + template = "{{package}}" + package = system.lookup_package('entertainment.tuner') + text = gen.apply(template, {"package": package}) + assert text == 'entertainment.tuner' + + +def test_gen_service(): + system = loadSystem() + gen = Generator() + template = """ + {%- for service in package.services -%} + {{service}} + {%- endfor -%} + """ + package = system.lookup_package('entertainment.tuner') + text = gen.apply(template, {"package": package}) + assert text == 'Tuner' + diff --git a/tests/test_parser.py b/tests/test_parser.py new file mode 100644 index 0000000..b6796ee --- /dev/null +++ b/tests/test_parser.py @@ -0,0 +1,81 @@ +from qif.idl.domain import System +from qif.generator import FileSystem +import logging +import logging.config +from pathlib import Path + +# logging.config.fileConfig('logging.ini') +logging.basicConfig() + +log = logging.getLogger(__name__) + +examples = Path('./examples') +log.debug('examples folder: {0}'.format(examples.absolute())) + + +def test_parse(): + log.debug('test parse') + names = FileSystem.find_files(examples, '*.qif') + # import pdb; pdb.set_trace() + system = System() + for name in names: + log.debug('name: {0}'.format(name)) + FileSystem.parse_document(name, system) + + +def test_package(): + path = examples / 'tuner.qif' + system = FileSystem.parse_document(path) + assert len(system.packages) == 1 + package = system.lookup_package('entertainment.tuner') + assert package in system.packages.values() + + +def test_service(): + path = examples / 'tuner.qif' + system = FileSystem.parse_document(path) + package = system.lookup_package('entertainment.tuner') + service = system.lookup_service('entertainment.tuner.Tuner') + assert service in package.services.values() + assert service.comment == '/*! Service Tuner */' + + +def test_attribute(): + path = examples / 'tuner.qif' + system = FileSystem.parse_document(path) + service = system.lookup_service('entertainment.tuner.Tuner') + package = system.lookup_package('entertainment.tuner') + attr = service.attributes['currentStation'] + assert attr.type.name == 'Station' + assert attr.package == package + assert attr.type.qualifiedName == 'entertainment.tuner.Station' + assert attr.is_readonly + assert attr.comment == '/*! attribute currentStation */' + + + +def test_struct(): + path = examples / 'tuner.qif' + system = FileSystem.parse_document(path) + package = system.lookup_package('entertainment.tuner') + symbol = system.lookup_struct('entertainment.tuner.Station') + assert symbol.name == 'Station' + assert symbol.package == package + assert symbol.qualifiedName == 'entertainment.tuner.Station' + assert symbol.comment == '/*! struct Station */' + + +def test_enum(): + path = examples / 'tuner.qif' + system = FileSystem.parse_document(path) + definition = system.lookup_definition('entertainment.tuner.Waveband') + package = system.lookup_package('entertainment.tuner') + symbol = system.lookup_enum('entertainment.tuner.Waveband') + assert definition == symbol + assert symbol.name == 'Waveband' + assert symbol.package == package + assert symbol.qualifiedName == 'entertainment.tuner.Waveband' + assert symbol.comment == '/*! enum Waveband */' + + + |