From 42d5add810932625335b9f675eb4e5a48c81560d Mon Sep 17 00:00:00 2001 From: Ad5001 Date: Fri, 11 Oct 2024 22:33:57 +0200 Subject: [PATCH] Fixing tests and LaTeX --- .../LogarithmPlotter/logarithmplotter.py | 33 ++++++++++++------- .../LogarithmPlotter/util/latex.py | 13 ++------ .../LogarithmPlotter/util/native.py | 4 +++ runtime-pyside6/tests/test_latex.py | 2 +- runtime-pyside6/tests/test_main.py | 11 +++---- runtime-pyside6/tests/test_update.py | 2 +- 6 files changed, 35 insertions(+), 30 deletions(-) diff --git a/runtime-pyside6/LogarithmPlotter/logarithmplotter.py b/runtime-pyside6/LogarithmPlotter/logarithmplotter.py index d620da8..115083a 100644 --- a/runtime-pyside6/LogarithmPlotter/logarithmplotter.py +++ b/runtime-pyside6/LogarithmPlotter/logarithmplotter.py @@ -17,9 +17,9 @@ """ from os import getcwd, chdir, environ, path -from platform import release as os_release +from platform import system as os_name, release as OS_RELEASE from sys import path as sys_path -from sys import platform, argv, exit +from sys import argv, exit from tempfile import TemporaryDirectory from time import time @@ -49,6 +49,18 @@ from LogarithmPlotter.util.helper import Helper from LogarithmPlotter.util.latex import Latex from LogarithmPlotter.util.js import PyJSValue +OS_NAME = os_name() + + +CACHE_PATH = { + "Linux": path.join(environ["XDG_CONFIG_HOME"], "LogarithmPlotter") + if "XDG_CONFIG_HOME" in environ else + path.join(path.expanduser("~"), ".cache", "LogarithmPlotter"), + "Windows": path.join(path.expandvars('%APPDATA%'), "LogarithmPlotter", "cache"), + "Darwin": path.join(path.expanduser("~"), "Library", "Caches", "LogarithmPlotter"), +}[OS_NAME] + + LINUX_THEMES = { # See https://specifications.freedesktop.org/menu-spec/latest/onlyshowin-registry.html "COSMIC": "Basic", "GNOME": "Basic", @@ -82,11 +94,10 @@ def get_linux_theme() -> str: def get_platform_qt_style(os) -> str: return { - "linux": get_linux_theme(), - "freebsd": get_linux_theme(), - "win32": "Universal" if os_release() in ["10", "11", "12", "13", "14"] else "Windows", - "cygwin": "Fusion", - "darwin": "macOS" + "Linux": get_linux_theme(), + "Windows": "Universal" if OS_RELEASE() in ["10", "11", "12", "13", "14"] else "Windows", + "Darwin": "macOS", + "Android": "Material" }[os] @@ -147,7 +158,7 @@ def run(): config.init() if not 'QT_QUICK_CONTROLS_STYLE' in environ: - QQuickStyle.setStyle(get_platform_qt_style(platform)) + QQuickStyle.setStyle(get_platform_qt_style(OS_NAME)) dep_time = time() print("Loaded dependencies in " + str((dep_time - start_time) * 1000) + "ms.") @@ -159,12 +170,12 @@ def run(): # Installing macOS file handler. macos_file_open_handler = None - if platform == "darwin": + if OS_NAME == "Darwin": macos_file_open_handler = native.MacOSFileOpenHandler() app.installEventFilter(macos_file_open_handler) helper = Helper(pwd, tmpfile) - latex = Latex() + latex = Latex(CACHE_PATH) engine, js_globals = create_engine(helper, latex, dep_time) if len(engine.rootObjects()) == 0: # No root objects loaded @@ -177,7 +188,7 @@ def run(): js_globals.Modules.IO.loadDiagram(argv[-1]) chdir(path.dirname(path.realpath(__file__))) - if platform == "darwin": + if OS_NAME == "Darwin": macos_file_open_handler.init_io(js_globals.Modules.IO) # Check for LaTeX installation if LaTeX support is enabled diff --git a/runtime-pyside6/LogarithmPlotter/util/latex.py b/runtime-pyside6/LogarithmPlotter/util/latex.py index 8f75aa8..df32d46 100644 --- a/runtime-pyside6/LogarithmPlotter/util/latex.py +++ b/runtime-pyside6/LogarithmPlotter/util/latex.py @@ -23,19 +23,10 @@ from PySide6.QtWidgets import QMessageBox from os import path, remove, environ, makedirs from string import Template from subprocess import Popen, TimeoutExpired, PIPE -from platform import system from hashlib import sha512 from shutil import which from sys import argv -CACHE_PATH = { - "Linux": path.join(environ["XDG_CONFIG_HOME"], "LogarithmPlotter") - if "XDG_CONFIG_HOME" in environ else - path.join(path.expanduser("~"), ".cache", "LogarithmPlotter"), - "Windows": path.join(path.expandvars('%APPDATA%'), "LogarithmPlotter", "cache"), - "Darwin": path.join(path.expanduser("~"), "Library", "Caches", "LogarithmPlotter"), -}[system()] - """ Searches for a valid Latex and DVIPNG (http://savannah.nongnu.org/projects/dvipng/) @@ -85,9 +76,9 @@ class Latex(QObject): dvipng to be installed on the system. """ - def __init__(self): + def __init__(self, cache_path): QObject.__init__(self) - self.tempdir = path.join(CACHE_PATH, "latex") + self.tempdir = path.join(cache_path, "latex") makedirs(self.tempdir, exist_ok=True) @Property(bool) diff --git a/runtime-pyside6/LogarithmPlotter/util/native.py b/runtime-pyside6/LogarithmPlotter/util/native.py index 7e32119..aefc310 100644 --- a/runtime-pyside6/LogarithmPlotter/util/native.py +++ b/runtime-pyside6/LogarithmPlotter/util/native.py @@ -49,3 +49,7 @@ class MacOSFileOpenHandler(QObject): else: # standard event processing return QObject.eventFilter(self, obj, event) + + + + diff --git a/runtime-pyside6/tests/test_latex.py b/runtime-pyside6/tests/test_latex.py index f02832e..d74f9f1 100644 --- a/runtime-pyside6/tests/test_latex.py +++ b/runtime-pyside6/tests/test_latex.py @@ -31,7 +31,7 @@ latex.SHOW_GUI_MESSAGES = False @pytest.fixture() def latex_obj(): directory = TemporaryDirectory() - obj = latex.Latex(directory) + obj = latex.Latex(directory.name) if not obj.checkLatexInstallation(): raise Exception("Cannot run LaTeX tests without a proper LaTeX installation. Make sure to install a LaTeX distribution, DVIPNG, and the calligra package, and run the tests again.") yield obj diff --git a/runtime-pyside6/tests/test_main.py b/runtime-pyside6/tests/test_main.py index d8a56b6..047e21f 100644 --- a/runtime-pyside6/tests/test_main.py +++ b/runtime-pyside6/tests/test_main.py @@ -39,11 +39,10 @@ THEMES = [ ] OS_PLATFORMS = [ - "linux", - "freebsd", - "win32", - "cygwin", - "darwin" + "Linux", + "Windows", + "Darwin", + "Android" ] @pytest.fixture() @@ -91,7 +90,7 @@ class TestMain: # Engine tmpfile, tempdir = temporary helper = Helper(".", tmpfile) - latex = Latex(tempdir) + latex = Latex(tempdir.name) engine, js_globals = create_engine(helper, latex, 0) assert len(engine.rootObjects()) > 0 # QML File loaded. assert type(engine.rootContext().contextProperty("TestBuild")) is bool diff --git a/runtime-pyside6/tests/test_update.py b/runtime-pyside6/tests/test_update.py index 9f65597..5e1a705 100644 --- a/runtime-pyside6/tests/test_update.py +++ b/runtime-pyside6/tests/test_update.py @@ -60,7 +60,7 @@ def test_update(qtbot): def test_update_checker(qtbot): update_info = check_for_updates('0.6.0', MockWindow()) - assert QThreadPool.globalInstance().activeThreadCount() == 1 + assert QThreadPool.globalInstance().activeThreadCount() >= 1 qtbot.waitSignal(update_info.got_update_info, timeout=10000) argv.append("--no-check-for-updates") update_info = check_for_updates('0.6.0', MockWindow())