slint/api/python/tests/test_compiler.py
Aurindam Jana 0cfeec1a31
Update Slint Community License (#4994)
Updated the version from 1.1 to 1.2 
Renamed the header to "Slint Royalty-free Desktop, Mobile, and Web Applications License"
Added definition of "Mobile Application" and grant of right
Moved "Limitations" to 3rd section and "License Conditions - Attributions" to 2nd section
Added flexibility to choose between showing "MadeWithSlint" as a dialog/splash screen or on a public webpage
Moved the para on copyright notices to section under "Limitations"
2024-04-15 15:18:55 +02:00

66 lines
2.3 KiB
Python

# Copyright © SixtyFPS GmbH <info@slint.dev>
# SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-1.2 OR LicenseRef-Slint-commercial
import pytest
from slint import slint as native
from slint.slint import ValueType;
def test_basic_compiler():
compiler = native.ComponentCompiler()
assert compiler.include_paths == []
compiler.include_paths = ["testing"]
assert compiler.include_paths == ["testing"]
assert compiler.build_from_source("Garbage", "") == None
compdef = compiler.build_from_source("""
export global TestGlobal {
in property <string> theglobalprop;
callback globallogic();
}
export component Test {
in property <string> strprop;
in property <int> intprop;
in property <float> floatprop;
in property <bool> boolprop;
in property <image> imgprop;
in property <brush> brushprop;
in property <color> colprop;
in property <[string]> modelprop;
callback test-callback();
}
""", "")
assert compdef != None
assert compdef.name == "Test"
props = [(name, type) for name, type in compdef.properties.items()]
assert props == [('boolprop', ValueType.Bool), ('brushprop', ValueType.Brush), ('colprop', ValueType.Brush), ('floatprop', ValueType.Number), ('imgprop', ValueType.Image), ('intprop', ValueType.Number), ('modelprop', ValueType.Model), ('strprop', ValueType.String)]
assert compdef.callbacks == ["test-callback"]
assert compdef.globals == ["TestGlobal"]
assert compdef.global_properties("Garbage") == None
assert [(name, type) for name, type in compdef.global_properties("TestGlobal").items()] == [('theglobalprop', ValueType.String)]
assert compdef.global_callbacks("Garbage") == None
assert compdef.global_callbacks("TestGlobal") == ["globallogic"]
instance = compdef.create()
assert instance != None
def test_compiler_build_from_path():
compiler = native.ComponentCompiler()
assert len(compiler.diagnostics) == 0
assert compiler.build_from_path("Nonexistent.slint") == None
diags = compiler.diagnostics
assert len(diags) == 1
assert diags[0].level == native.DiagnosticLevel.Error
assert diags[0].message.startswith("Could not load Nonexistent.slint:")