summaryrefslogtreecommitdiff
path: root/tests/test_generator.py
blob: 04d46fb7d36fb4b91645930676f6958d368b8e58 (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
from qface.generator import FileSystem, Generator
import logging
import logging.config
from pathlib import Path

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

log = logging.getLogger(__name__)

inputPath = Path('tests/in')
log.debug('input path folder: {0}'.format(inputPath.absolute()))


def loadSystem():
    path = inputPath / 'tuner.qdl'
    return FileSystem.parse_document(path)


def test_gen_module():
    system = loadSystem()
    gen = Generator(searchpath='tests/templates')
    template = "{{module}}"
    module = system.lookup('entertainment.tuner')
    text = gen.apply(template, {"module": module})
    assert text == 'entertainment.tuner'


def test_gen_interface():
    system = loadSystem()
    gen = Generator(searchpath='tests/templates')
    template = """
        {%- for interface in module.interfaces -%}
            {{interface}}
        {%- endfor -%}
    """
    module = system.lookup('entertainment.tuner')
    text = gen.apply(template, {"module": module})
    assert text == 'Tuner'