Python: rework the load_file API, part 2

Take arguments for configuring style, etc., throw an exception on errors, and log warning diagnostics.
This commit is contained in:
Simon Hausmann 2024-03-06 11:24:54 +01:00 committed by Simon Hausmann
parent 280f314eeb
commit 765c773b90
3 changed files with 47 additions and 5 deletions

View file

@ -1,13 +1,22 @@
# Copyright © SixtyFPS GmbH <info@slint.dev>
# SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-1.1 OR LicenseRef-Slint-commercial
from slint import load_file
import pytest
from slint import load_file, CompileError
import os
def test_load_file():
def test_load_file(caplog):
module = load_file(os.path.join(os.path.dirname(
__spec__.origin), "test_load_file.slint"))
__spec__.origin), "test_load_file.slint"), quiet=False)
assert "The property 'color' has been deprecated. Please use 'background' instead" in caplog.text
assert list(module.__dict__.keys()) == ["App"]
instance = module.App()
del instance
def test_load_file_fail():
with pytest.raises(CompileError, match="Could not compile non-existent.slint"):
load_file("non-existent.slint")