Fixing tests and LaTeX
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Adsooi 2024-10-11 22:33:57 +02:00
parent e2d259f866
commit 42d5add810
Signed by: Ad5001
GPG key ID: EF45F9C6AFE20160
6 changed files with 35 additions and 30 deletions

View file

@ -17,9 +17,9 @@
""" """
from os import getcwd, chdir, environ, path 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 path as sys_path
from sys import platform, argv, exit from sys import argv, exit
from tempfile import TemporaryDirectory from tempfile import TemporaryDirectory
from time import time from time import time
@ -49,6 +49,18 @@ from LogarithmPlotter.util.helper import Helper
from LogarithmPlotter.util.latex import Latex from LogarithmPlotter.util.latex import Latex
from LogarithmPlotter.util.js import PyJSValue 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 LINUX_THEMES = { # See https://specifications.freedesktop.org/menu-spec/latest/onlyshowin-registry.html
"COSMIC": "Basic", "COSMIC": "Basic",
"GNOME": "Basic", "GNOME": "Basic",
@ -82,11 +94,10 @@ def get_linux_theme() -> str:
def get_platform_qt_style(os) -> str: def get_platform_qt_style(os) -> str:
return { return {
"linux": get_linux_theme(), "Linux": get_linux_theme(),
"freebsd": get_linux_theme(), "Windows": "Universal" if OS_RELEASE() in ["10", "11", "12", "13", "14"] else "Windows",
"win32": "Universal" if os_release() in ["10", "11", "12", "13", "14"] else "Windows", "Darwin": "macOS",
"cygwin": "Fusion", "Android": "Material"
"darwin": "macOS"
}[os] }[os]
@ -147,7 +158,7 @@ def run():
config.init() config.init()
if not 'QT_QUICK_CONTROLS_STYLE' in environ: 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() dep_time = time()
print("Loaded dependencies in " + str((dep_time - start_time) * 1000) + "ms.") print("Loaded dependencies in " + str((dep_time - start_time) * 1000) + "ms.")
@ -159,12 +170,12 @@ def run():
# Installing macOS file handler. # Installing macOS file handler.
macos_file_open_handler = None macos_file_open_handler = None
if platform == "darwin": if OS_NAME == "Darwin":
macos_file_open_handler = native.MacOSFileOpenHandler() macos_file_open_handler = native.MacOSFileOpenHandler()
app.installEventFilter(macos_file_open_handler) app.installEventFilter(macos_file_open_handler)
helper = Helper(pwd, tmpfile) helper = Helper(pwd, tmpfile)
latex = Latex() latex = Latex(CACHE_PATH)
engine, js_globals = create_engine(helper, latex, dep_time) engine, js_globals = create_engine(helper, latex, dep_time)
if len(engine.rootObjects()) == 0: # No root objects loaded if len(engine.rootObjects()) == 0: # No root objects loaded
@ -177,7 +188,7 @@ def run():
js_globals.Modules.IO.loadDiagram(argv[-1]) js_globals.Modules.IO.loadDiagram(argv[-1])
chdir(path.dirname(path.realpath(__file__))) chdir(path.dirname(path.realpath(__file__)))
if platform == "darwin": if OS_NAME == "Darwin":
macos_file_open_handler.init_io(js_globals.Modules.IO) macos_file_open_handler.init_io(js_globals.Modules.IO)
# Check for LaTeX installation if LaTeX support is enabled # Check for LaTeX installation if LaTeX support is enabled

View file

@ -23,19 +23,10 @@ from PySide6.QtWidgets import QMessageBox
from os import path, remove, environ, makedirs from os import path, remove, environ, makedirs
from string import Template from string import Template
from subprocess import Popen, TimeoutExpired, PIPE from subprocess import Popen, TimeoutExpired, PIPE
from platform import system
from hashlib import sha512 from hashlib import sha512
from shutil import which from shutil import which
from sys import argv 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/) 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. dvipng to be installed on the system.
""" """
def __init__(self): def __init__(self, cache_path):
QObject.__init__(self) QObject.__init__(self)
self.tempdir = path.join(CACHE_PATH, "latex") self.tempdir = path.join(cache_path, "latex")
makedirs(self.tempdir, exist_ok=True) makedirs(self.tempdir, exist_ok=True)
@Property(bool) @Property(bool)

View file

@ -49,3 +49,7 @@ class MacOSFileOpenHandler(QObject):
else: else:
# standard event processing # standard event processing
return QObject.eventFilter(self, obj, event) return QObject.eventFilter(self, obj, event)

View file

@ -31,7 +31,7 @@ latex.SHOW_GUI_MESSAGES = False
@pytest.fixture() @pytest.fixture()
def latex_obj(): def latex_obj():
directory = TemporaryDirectory() directory = TemporaryDirectory()
obj = latex.Latex(directory) obj = latex.Latex(directory.name)
if not obj.checkLatexInstallation(): 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.") 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 yield obj

View file

@ -39,11 +39,10 @@ THEMES = [
] ]
OS_PLATFORMS = [ OS_PLATFORMS = [
"linux", "Linux",
"freebsd", "Windows",
"win32", "Darwin",
"cygwin", "Android"
"darwin"
] ]
@pytest.fixture() @pytest.fixture()
@ -91,7 +90,7 @@ class TestMain:
# Engine # Engine
tmpfile, tempdir = temporary tmpfile, tempdir = temporary
helper = Helper(".", tmpfile) helper = Helper(".", tmpfile)
latex = Latex(tempdir) latex = Latex(tempdir.name)
engine, js_globals = create_engine(helper, latex, 0) engine, js_globals = create_engine(helper, latex, 0)
assert len(engine.rootObjects()) > 0 # QML File loaded. assert len(engine.rootObjects()) > 0 # QML File loaded.
assert type(engine.rootContext().contextProperty("TestBuild")) is bool assert type(engine.rootContext().contextProperty("TestBuild")) is bool

View file

@ -60,7 +60,7 @@ def test_update(qtbot):
def test_update_checker(qtbot): def test_update_checker(qtbot):
update_info = check_for_updates('0.6.0', MockWindow()) 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) qtbot.waitSignal(update_info.got_update_info, timeout=10000)
argv.append("--no-check-for-updates") argv.append("--no-check-for-updates")
update_info = check_for_updates('0.6.0', MockWindow()) update_info = check_for_updates('0.6.0', MockWindow())