This repository has been archived by the owner on Oct 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: test Python scripts against different Qt dependencies
- Loading branch information
1 parent
b1aec1e
commit adf7eb1
Showing
17 changed files
with
230 additions
and
111 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
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
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
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
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 |
---|---|---|
@@ -1,6 +1,29 @@ | ||
import argparse | ||
import importlib.util | ||
import sys | ||
import typing | ||
|
||
QT_DEPENDENCY_ARG = "vscode_extension_qt_dependency" | ||
|
||
SupportedQtDependencies = typing.Optional[ | ||
typing.Literal["PySide6", "PySide2", "PyQt6", "PyQt5"] | ||
] | ||
|
||
|
||
def is_installed(name: str) -> bool: | ||
return name in sys.modules or importlib.util.find_spec(name) is not None | ||
|
||
|
||
def parse_qt_dependency() -> SupportedQtDependencies: | ||
parser = argparse.ArgumentParser(add_help=False) | ||
parser.add_argument( | ||
f"--{QT_DEPENDENCY_ARG}", | ||
required=False, | ||
) | ||
|
||
if dep := vars(parser.parse_known_args()[0])[QT_DEPENDENCY_ARG]: | ||
sys.argv.remove(f"--{QT_DEPENDENCY_ARG}") | ||
sys.argv.remove(dep) | ||
|
||
return dep | ||
return None |
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 |
---|---|---|
@@ -1,7 +1,39 @@ | ||
import os | ||
import platform | ||
import subprocess | ||
import typing | ||
|
||
from scripts.utils import QT_DEPENDENCY_ARG, SupportedQtDependencies | ||
|
||
TESTS_DIR = os.path.dirname(os.path.realpath(__file__)) | ||
|
||
SCRIPTS_DIR = os.path.join(TESTS_DIR, os.pardir, "scripts") | ||
|
||
ASSETS_DIR = os.path.join(TESTS_DIR, "assets") | ||
|
||
SupportedScripts = typing.Literal["designer", "lupdate", "qml", "qmlls", "rcc", "uic"] | ||
|
||
|
||
def filter_available_qt_dependencies( | ||
deps: list[SupportedQtDependencies], | ||
) -> list[SupportedQtDependencies]: | ||
if platform.system() == "Darwin" and platform.machine() == "arm64": | ||
return [None] + list(filter(lambda d: d in ("PySide2", "PyQt5"), deps)) | ||
return [None] + deps | ||
|
||
|
||
def invoke_script( | ||
name: SupportedScripts, | ||
args: list[str], | ||
qt_dependency: SupportedQtDependencies, | ||
): | ||
if qt_dependency is not None: | ||
args.append(f"--{QT_DEPENDENCY_ARG}") | ||
args.append(qt_dependency) | ||
|
||
return subprocess.run( | ||
["poetry", "run", "python", f"{name}.py", *args], | ||
cwd=SCRIPTS_DIR, | ||
capture_output=True, | ||
check=False, | ||
) |
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 |
---|---|---|
@@ -1,27 +1,21 @@ | ||
import os | ||
import subprocess | ||
|
||
import pytest | ||
|
||
from tests import ASSETS_DIR, SCRIPTS_DIR | ||
from scripts.utils import SupportedQtDependencies | ||
from tests import ASSETS_DIR, filter_available_qt_dependencies, invoke_script | ||
|
||
|
||
@pytest.mark.skip(reason="a GUI app cannot be closed gracefully") | ||
def test_designer_sample_ui(): | ||
@pytest.mark.parametrize( | ||
"qt_dependency", filter_available_qt_dependencies(["PySide6", "PySide2"]) | ||
) | ||
def test_designer_sample_ui(qt_dependency: SupportedQtDependencies): | ||
filename = "sample.ui" | ||
result = invoke_designer_py([get_assets_path(filename)]) | ||
result = invoke_script("designer", [get_assets_path(filename)], qt_dependency) | ||
assert result.returncode == 0 | ||
assert len(result.stdout.decode("utf-8")) > 0 | ||
|
||
|
||
def invoke_designer_py(args: list[str]): | ||
return subprocess.run( | ||
["poetry", "run", "python", "designer.py", *args], | ||
cwd=SCRIPTS_DIR, | ||
capture_output=True, | ||
check=True, | ||
) | ||
|
||
|
||
def get_assets_path(filename: str) -> str: | ||
return os.path.join(ASSETS_DIR, "ui", filename) |
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 |
---|---|---|
@@ -1,35 +1,48 @@ | ||
import os | ||
import subprocess | ||
|
||
from tests import ASSETS_DIR, SCRIPTS_DIR | ||
import pytest | ||
|
||
from scripts.utils import SupportedQtDependencies | ||
from tests import ASSETS_DIR, filter_available_qt_dependencies, invoke_script | ||
|
||
def test_lupdate_help(): | ||
result = invoke_lupdate_py(["-help"]) | ||
|
||
@pytest.mark.parametrize( | ||
"qt_dependency", | ||
filter_available_qt_dependencies(["PySide6", "PySide2", "PyQt6", "PyQt5"]), | ||
) | ||
def test_lupdate_help(qt_dependency: SupportedQtDependencies): | ||
help_arg = "--help" if qt_dependency == "PyQt6" else "-help" | ||
|
||
result = invoke_script("lupdate", [help_arg], qt_dependency) | ||
assert result.returncode == 0 | ||
assert len(result.stdout.decode("utf-8")) > 0 | ||
|
||
if qt_dependency in ("PySide2", "PyQt5"): | ||
assert len(result.stderr.decode("utf-8")) > 0 | ||
else: | ||
assert len(result.stdout.decode("utf-8")) > 0 | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"qt_dependency", | ||
filter_available_qt_dependencies(["PySide6", "PySide2", "PyQt6", "PyQt5"]), | ||
) | ||
def test_lupdate_sample_py(qt_dependency: str): | ||
try: | ||
os.remove(get_assets_path("sample.ts")) | ||
except FileNotFoundError: | ||
pass | ||
|
||
def test_lupdate_sample_py(): | ||
filename = "sample.py" | ||
result = invoke_lupdate_py( | ||
[get_assets_path(filename), "-ts", get_assets_path("sample.ts")] | ||
result = invoke_script( | ||
"lupdate", | ||
[get_assets_path(filename), "-ts", get_assets_path("sample.ts")], | ||
qt_dependency, | ||
) | ||
assert result.returncode == 0 | ||
assert len(result.stdout.decode("utf-8")) > 0 | ||
assert os.path.exists(get_assets_path("sample.ts")) | ||
|
||
os.remove(get_assets_path("sample.ts")) | ||
|
||
|
||
def invoke_lupdate_py(args: list[str]): | ||
return subprocess.run( | ||
["poetry", "run", "python", "lupdate.py", *args], | ||
cwd=SCRIPTS_DIR, | ||
capture_output=True, | ||
check=True, | ||
) | ||
|
||
|
||
def get_assets_path(filename: str) -> str: | ||
return os.path.join(ASSETS_DIR, "linguist", filename) |
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 |
---|---|---|
@@ -1,20 +1,15 @@ | ||
import subprocess | ||
|
||
import pytest | ||
from tests import SCRIPTS_DIR | ||
|
||
from scripts.utils import SupportedQtDependencies | ||
from tests import filter_available_qt_dependencies, invoke_script | ||
|
||
|
||
@pytest.mark.skip(reason="Ubuntu on GitHub Actions does not have libGL.so.1") | ||
def test_qml_help(): | ||
result = invoke_qml_py(["--help"]) | ||
@pytest.mark.parametrize( | ||
"qt_dependency", | ||
filter_available_qt_dependencies(["PySide6"]), | ||
) | ||
def test_qml_help(qt_dependency: SupportedQtDependencies): | ||
result = invoke_script("qml", ["--help"], qt_dependency) | ||
assert result.returncode == 0 | ||
assert len(result.stdout.decode("utf-8")) > 0 | ||
|
||
|
||
def invoke_qml_py(args: list[str]): | ||
return subprocess.run( | ||
["poetry", "run", "python", "qml.py", *args], | ||
cwd=SCRIPTS_DIR, | ||
capture_output=True, | ||
check=True, | ||
) |
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 |
---|---|---|
@@ -1,18 +1,14 @@ | ||
import subprocess | ||
import pytest | ||
|
||
from tests import SCRIPTS_DIR | ||
from scripts.utils import SupportedQtDependencies | ||
from tests import filter_available_qt_dependencies, invoke_script | ||
|
||
|
||
def test_qmlls_help(): | ||
result = invoke_qmlls_py(["--help"]) | ||
@pytest.mark.parametrize( | ||
"qt_dependency", | ||
filter_available_qt_dependencies(["PySide6"]), | ||
) | ||
def test_qmlls_help(qt_dependency: SupportedQtDependencies): | ||
result = invoke_script("qmlls", ["--help"], qt_dependency) | ||
assert result.returncode == 0 | ||
assert len(result.stdout.decode("utf-8")) > 0 | ||
|
||
|
||
def invoke_qmlls_py(args: list[str]): | ||
return subprocess.run( | ||
["poetry", "run", "python", "qmlls.py", *args], | ||
cwd=SCRIPTS_DIR, | ||
capture_output=True, | ||
check=True, | ||
) |
Oops, something went wrong.