-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d7480c6
commit 148e269
Showing
4 changed files
with
114 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# pylint: disable=import-error,ungrouped-imports | ||
|
||
import sys | ||
|
||
from utils import is_installed, parse_qt_dependency | ||
|
||
if __name__ == "__main__": | ||
dep = parse_qt_dependency() | ||
if dep == "PySide6": | ||
from PySide6.scripts.pyside_tool import qmlformat | ||
|
||
elif is_installed("PySide6"): | ||
from PySide6.scripts.pyside_tool import qmlformat | ||
else: | ||
ERR_MSG = ( | ||
"No qmlformat can be found in the current Python environment. " | ||
"Make sure the latest PySide6 is installed. " | ||
"Update configuration to disable qmlformat integration if you don't need it." | ||
) | ||
sys.exit(ERR_MSG) | ||
sys.exit(qmlformat()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import QtQuick | ||
Rectangle { | ||
width: 200 | ||
height: 100 | ||
color: "red" | ||
|
||
|
||
Text{anchors.centerIn: parent | ||
text: "Hello, World!" | ||
}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import os | ||
|
||
import pytest | ||
|
||
from scripts.utils import SupportedQtDependencies | ||
from tests import ASSETS_DIR, filter_available_qt_dependencies, invoke_script | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"qt_dependency", | ||
filter_available_qt_dependencies(["PySide6"]), | ||
) | ||
def test_qmlformat_version(qt_dependency: SupportedQtDependencies): | ||
result = invoke_script("qmlformat", ["--version"], qt_dependency) | ||
|
||
assert result.returncode == 0 | ||
assert len(result.stdout.decode("utf-8")) > 0 | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"qt_dependency", | ||
filter_available_qt_dependencies(["PySide6"]), | ||
) | ||
def test_qmlformat_format_file(qt_dependency: SupportedQtDependencies): | ||
filename = "unformatted.qml" | ||
reset_unformatted_qml_file(filename) | ||
|
||
result = invoke_script( | ||
"qmlformat", [get_assets_path(filename), "--inplace"], qt_dependency | ||
) | ||
|
||
assert result.returncode == 0 | ||
|
||
with open(get_assets_path(filename), "r", encoding="utf-8") as file: | ||
assert file.read() == ( | ||
"import QtQuick\n" | ||
"\n" | ||
"Rectangle {\n" | ||
" width: 200\n" | ||
" height: 100\n" | ||
' color: "red"\n' | ||
"\n" | ||
" Text {\n" | ||
" anchors.centerIn: parent\n" | ||
' text: "Hello, World!"\n' | ||
" }\n" | ||
"}\n" | ||
) | ||
|
||
reset_unformatted_qml_file(filename) | ||
|
||
|
||
def reset_unformatted_qml_file(filename: str): | ||
with open(get_assets_path(filename), "w", encoding="utf-8") as file: | ||
file.write( | ||
"import QtQuick\n" | ||
"Rectangle {\n" | ||
"width: 200\n" | ||
"height: 100\n" | ||
'color: "red"\n' | ||
" \n" | ||
" \n" | ||
" Text{anchors.centerIn: parent\n" | ||
'text: "Hello, World!"\n' | ||
"}}\n" | ||
) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"qt_dependency", | ||
filter_available_qt_dependencies(["PySide6"]), | ||
) | ||
def test_qmlformat_format_invalid_file(qt_dependency: SupportedQtDependencies): | ||
filename = "syntax_error.qml" | ||
|
||
result = invoke_script("qmlformat", [get_assets_path(filename)], qt_dependency) | ||
|
||
assert result.returncode != 0 | ||
|
||
|
||
def get_assets_path(filename: str) -> str: | ||
return os.path.join(ASSETS_DIR, "qml", filename) |