Reorganizing paths

This commit is contained in:
Adsooi 2024-09-30 00:23:39 +02:00
parent e9d204daab
commit 34cb856dd4
Signed by: Ad5001
GPG key ID: EF45F9C6AFE20160
249 changed files with 118 additions and 294 deletions

View file

@ -0,0 +1,20 @@
"""
* LogarithmPlotter - 2D plotter software to make BODE plots, sequences and distribution functions.
* Copyright (C) 2021-2024 Ad5001
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
"""
from LogarithmPlotter.logarithmplotter import create_qapp
app = create_qapp()

View file

@ -0,0 +1,42 @@
import pytest
from LogarithmPlotter.util import config
from tempfile import TemporaryDirectory
from os.path import join
@pytest.fixture()
def resource():
directory = TemporaryDirectory()
config.CONFIG_FILE = join(directory.name, "config.json")
config.init()
yield config.CONFIG_FILE
directory.cleanup()
class TestConfig:
def test_init(self, resource):
assert config.current_config == config.DEFAULT_SETTINGS
def test_get(self, resource):
assert config.getSetting("expression_editor.autoclose") == True
with pytest.raises(config.UnknownNamespaceError):
config.getSetting("unknown_setting")
def test_set(self, resource):
assert config.setSetting("expression_editor.autoclose", False) is None
assert config.getSetting("expression_editor.autoclose") == False # Ensure set is working.
with pytest.raises(config.UnknownNamespaceError):
config.setSetting("unknown_dict.unknown_setting", False)
def test_reinit(self, resource):
default_value = config.getSetting("expression_editor.autoclose")
config.setSetting("expression_editor.autoclose", not default_value)
config.init()
assert config.getSetting("expression_editor.autoclose") != default_value # Ensure setting has been reset.
def test_save(self, resource):
config.setSetting("expression_editor.autoclose", False)
config.save(resource)
config.init()
assert config.getSetting("expression_editor.autoclose") == False # Ensure setting has been saved.

View file

@ -0,0 +1,68 @@
"""
* LogarithmPlotter - 2D plotter software to make BODE plots, sequences and distribution functions.
* Copyright (C) 2021-2024 Ad5001
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
"""
import pytest
from os.path import exists
from PySide6.QtCore import QtMsgType, QMessageLogContext
from LogarithmPlotter.util import debug
def test_setup():
sourcemap_installed = False
try:
import sourcemap
sourcemap_installed = True
except:
pass
if sourcemap_installed:
file = debug.SOURCEMAP_PATH
debug.SOURCEMAP_PATH = None
debug.setup() # Nothing could be setup.
debug.SOURCEMAP_PATH = file
debug.setup()
assert (sourcemap_installed and exists(debug.SOURCEMAP_PATH)) == (debug.SOURCEMAP_INDEX is not None)
def test_map_source():
sourcemap_available = debug.SOURCEMAP_INDEX is not None
if sourcemap_available:
assert debug.map_javascript_source("js/index.mjs", 22) != ("js/module/index.mjs", 22)
assert debug.map_javascript_source("js/index.mjs", 100000) == ("js/index.mjs", 100000) # Too long, not found
debug.SOURCEMAP_INDEX = None
assert debug.map_javascript_source("js/index.mjs", 21) == ("js/index.mjs", 21)
def test_log_terminal_message():
msg1 = debug.create_log_terminal_message(
QtMsgType.QtWarningMsg, QMessageLogContext(),
"a long and random message"
)
assert "[WARNING]" in msg1
assert "a long and random message" in msg1
msg2 = debug.create_log_terminal_message(
QtMsgType.QtCriticalMsg,
QMessageLogContext("LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/Index.qml", 15, "anotherFunctionName",
"aCategoryDifferent"),
"LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/Index.qml:15: a potentially potential error message"
)
assert "[CRITICAL]" in msg2
assert "Index.qml" in msg2
assert "a potentially potential error message" in msg2
assert "anotherFunctionName" in msg2

View file

@ -0,0 +1,182 @@
"""
* LogarithmPlotter - 2D plotter software to make BODE plots, sequences and distribution functions.
* Copyright (C) 2021-2024 Ad5001
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
"""
import pytest
from os import getcwd, remove
from os.path import join
from tempfile import TemporaryDirectory
from json import loads
from shutil import copy2
from PySide6.QtCore import QObject, Signal, QThreadPool
from PySide6.QtGui import QImage
from PySide6.QtWidgets import QApplication
from LogarithmPlotter import __VERSION__ as version
from LogarithmPlotter.util import config, helper
from LogarithmPlotter.util.helper import ChangelogFetcher, Helper, InvalidFileException
pwd = getcwd()
helper.SHOW_GUI_MESSAGES = False
@pytest.fixture()
def temporary():
directory = TemporaryDirectory()
config.CONFIG_PATH = join(directory.name, "config.json")
tmpfile = join(directory.name, "graph.png")
yield tmpfile, directory
directory.cleanup()
class MockHelperSignals(QObject):
changelogFetched = Signal(str)
def __init__(self, expect_404):
QObject.__init__(self)
self.expect_404 = expect_404
self.changelogFetched.connect(self.changelog_fetched)
self.changelog = None
def changelog_fetched(self, changelog):
self.changelog = changelog
class TestChangelog:
def test_exists(self, qtbot):
helper.CHANGELOG_VERSION = '0.5.0'
mock_helper = MockHelperSignals(False)
fetcher = ChangelogFetcher(mock_helper)
fetcher.run() # Does not raise an exception
qtbot.waitSignal(mock_helper.changelogFetched, timeout=10000)
assert type(mock_helper.changelog) == str
assert '404' not in mock_helper.changelog
def tests_no_exist(self, qtbot):
mock_helper = MockHelperSignals(True)
helper.CHANGELOG_VERSION = '1.0.0'
fetcher = ChangelogFetcher(mock_helper)
fetcher.run()
qtbot.waitSignal(mock_helper.changelogFetched, timeout=10000)
assert type(mock_helper.changelog) == str
assert '404' in mock_helper.changelog
class TestHelper:
def test_read(self, temporary):
# Test file reading and information loading.
tmpfile, directory = temporary
obj = Helper(pwd, tmpfile)
data = obj.load("ci/test1.lpf")
assert type(data) == str
data = loads(data)
assert data['type'] == "logplotv1"
# Checking data['types'] of valid file.
# See https://git.ad5001.eu/Ad5001/LogarithmPlotter/wiki/LogarithmPlotter-file-format-v1.0
assert type(data['width']) == int
assert type(data['height']) == int
assert type(data['xzoom']) in (int, float)
assert type(data['yzoom']) in (int, float)
assert type(data['xmin']) in (int, float)
assert type(data['ymax']) in (int, float)
assert type(data['xaxisstep']) == str
assert type(data['yaxisstep']) == str
assert type(data['xaxislabel']) == str
assert type(data['yaxislabel']) == str
assert type(data['logscalex']) == bool
assert type(data['linewidth']) in (int, float)
assert type(data['showxgrad']) == bool
assert type(data['showygrad']) == bool
assert type(data['textsize']) in (int, float)
assert type(data['history']) == list and len(data['history']) == 2
assert type(data['history'][0]) == list
assert type(data['history'][1]) == list
for action_list in data['history']:
for action in action_list:
assert type(action[0]) == str
assert type(action[1]) == list
assert type(data['objects']) == dict
for obj_type, objects in data['objects'].items():
assert type(obj_type) == str
assert type(objects) == list
for obj in objects:
assert type(obj) == list
def test_read_newer(self, temporary):
tmpfile, directory = temporary
obj = Helper(pwd, tmpfile)
newer_file_path = join(directory.name, "newer.lpf")
with open(newer_file_path, "w") as f:
f.write("LPFv2[other invalid data]")
with pytest.raises(InvalidFileException):
obj.load(newer_file_path)
def test_read_invalid_file(self, temporary):
tmpfile, directory = temporary
obj = Helper(pwd, tmpfile)
with pytest.raises(InvalidFileException):
obj.load("./inexistant.lpf")
with pytest.raises(InvalidFileException):
obj.load("./pyproject.toml")
def test_write(self, temporary):
tmpfile, directory = temporary
obj = Helper(pwd, tmpfile)
target = join(directory.name, "target.lpf")
data = "example_data"
obj.write(target, data)
with open(target, "r") as f:
read_data = f.read()
# Ensure data has been written.
assert read_data == "LPFv1" + data
def test_tmp_graphic(self, temporary):
tmpfile, directory = temporary
obj = Helper(pwd, tmpfile)
assert obj.gettmpfile() == tmpfile
obj.copyImageToClipboard()
clipboard = QApplication.clipboard()
assert type(clipboard.image()) == QImage
def test_strings(self, temporary):
tmpfile, directory = temporary
obj = Helper(pwd, tmpfile)
assert obj.getVersion() == version
assert type(obj.getDebugInfos()) == str
assert type(obj.getSetting("check_for_updates")) == str
assert type(obj.getSettingInt("check_for_updates")) == float
assert type(obj.getSettingBool("check_for_updates")) == bool
def test_set_config(self, temporary):
tmpfile, directory = temporary
obj = Helper(pwd, tmpfile)
obj.setSetting("last_install_greet", obj.getSetting("last_install_greet"))
obj.setSettingBool("check_for_updates", obj.getSettingBool("check_for_updates"))
obj.setSettingInt("default_graph.xzoom", obj.getSettingInt("default_graph.xzoom"))
def test_fetch_changelog(self, temporary, qtbot):
tmpfile, directory = temporary
obj = Helper(pwd, tmpfile)
copy2("../../CHANGELOG.md", "../../LogarithmPlotter/util/CHANGELOG.md")
obj.fetchChangelog()
assert QThreadPool.globalInstance().activeThreadCount() == 0
qtbot.waitSignal(obj.changelogFetched, timeout=10000)
remove("../../LogarithmPlotter/util/CHANGELOG.md")
obj.fetchChangelog()
assert QThreadPool.globalInstance().activeThreadCount() > 0
qtbot.waitSignal(obj.changelogFetched, timeout=10000)

View file

@ -0,0 +1,86 @@
"""
* LogarithmPlotter - 2D plotter software to make BODE plots, sequences and distribution functions.
* Copyright (C) 2021-2024 Ad5001
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
"""
import pytest
from tempfile import TemporaryDirectory
from shutil import which
from os.path import exists
from re import match
from PySide6.QtGui import QColor
from LogarithmPlotter.util import latex
latex.SHOW_GUI_MESSAGES = False
@pytest.fixture()
def latex_obj():
directory = TemporaryDirectory()
obj = latex.Latex(directory)
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
directory.cleanup()
class TestLatex:
def test_check_install(self, latex_obj: latex.Latex) -> None:
assert latex_obj.latexSupported == True
assert latex_obj.checkLatexInstallation() == True
bkp = [latex.DVIPNG_PATH, latex.LATEX_PATH]
# Check what happens when one is missing.
latex.DVIPNG_PATH = None
assert latex_obj.latexSupported == False
assert latex_obj.checkLatexInstallation() == False
latex.DVIPNG_PATH = bkp[0]
latex.LATEX_PATH = None
assert latex_obj.latexSupported == False
assert latex_obj.checkLatexInstallation() == False
# Reset
[latex.DVIPNG_PATH, latex.LATEX_PATH] = bkp
def test_render(self, latex_obj: latex.Latex) -> None:
result = latex_obj.render(r"\frac{d\sqrt{\mathrm{f}(x \times 2.3)}}{dx}", 14, QColor(0, 0, 0, 255))
# Ensure result format
assert type(result) == str
[path, width, height] = result.split(",")
assert exists(path)
assert match(r"\d+", width)
assert match(r"\d+", height)
# Ensure it returns errors on invalid latex.
with pytest.raises(latex.RenderError):
latex_obj.render(r"\nonexistant", 14, QColor(0, 0, 0, 255))
# Replace latex bin with one that returns errors
bkp = latex.LATEX_PATH
latex.LATEX_PATH = which("false")
with pytest.raises(latex.RenderError):
latex_obj.render(r"\mathrm{f}(x)", 14, QColor(0, 0, 0, 255))
latex.LATEX_PATH = bkp
def test_prerendered(self, latex_obj: latex.Latex) -> None:
args = [r"\frac{d\sqrt{\mathrm{f}(x \times 2.3)}}{dx}", 14, QColor(0, 0, 0, 255)]
latex_obj.render(*args)
prerendered = latex_obj.findPrerendered(*args)
assert type(prerendered) == str
[path, width, height] = prerendered.split(",")
assert exists(path)
assert match(r"\d+", width)
assert match(r"\d+", height)
prerendered2 = latex_obj.findPrerendered(args[0], args[1]+2, args[2])
assert prerendered2 == ""

View file

@ -0,0 +1,108 @@
"""
* LogarithmPlotter - 2D plotter software to make BODE plots, sequences and distribution functions.
* Copyright (C) 2021-2024 Ad5001
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
"""
import pytest
from os import environ
from os.path import exists, join
from PySide6.QtGui import QIcon
from tempfile import TemporaryDirectory
from LogarithmPlotter.logarithmplotter import get_linux_theme, LINUX_THEMES, get_platform_qt_style, \
register_icon_directories, install_translation, create_engine
from LogarithmPlotter.util import config
from LogarithmPlotter.util.helper import Helper
from LogarithmPlotter.util.latex import Latex
from globals import app
THEMES = [
"Basic",
"Universal",
"Material",
"Fusion",
"Windows",
"macOS"
]
OS_PLATFORMS = [
"linux",
"freebsd",
"win32",
"cygwin",
"darwin"
]
@pytest.fixture()
def temporary():
directory = TemporaryDirectory()
config.CONFIG_PATH = join(directory.name, "config.json")
tmpfile = join(directory.name, "graph.png")
yield tmpfile, directory
directory.cleanup()
class TestMain:
def test_linux_themes(self):
# Check without a desktop
if "XDG_SESSION_DESKTOP" in environ:
del environ["XDG_SESSION_DESKTOP"]
assert get_linux_theme() in THEMES
# Test various environments.
environ["XDG_SESSION_DESKTOP"] = "GNOME"
assert get_linux_theme() in THEMES
# Test various environments.
environ["XDG_SESSION_DESKTOP"] = "NON-EXISTENT"
assert get_linux_theme() in THEMES
# Check all linux themes are in list
for desktop, theme in LINUX_THEMES.items():
assert theme in THEMES
def test_os_themes(self):
for platform in OS_PLATFORMS:
assert get_platform_qt_style(platform) in THEMES
def test_icon_directories(self):
base_paths = QIcon.fallbackSearchPaths()
register_icon_directories()
# Check if registered
assert len(base_paths) < len(QIcon.fallbackSearchPaths())
# Check if all exists
for p in QIcon.fallbackSearchPaths():
assert exists(p)
def test_app(self, temporary):
assert not app.windowIcon().isNull()
# Translations
translator = install_translation(app)
assert not translator.isEmpty()
# Engine
tmpfile, tempdir = temporary
helper = Helper(".", tmpfile)
latex = Latex(tempdir)
engine, js_globals = create_engine(helper, latex, 0)
assert len(engine.rootObjects()) > 0 # QML File loaded.
assert type(engine.rootContext().contextProperty("TestBuild")) is bool
assert engine.rootContext().contextProperty("StartTime") == 0
assert js_globals.Latex.type() is not None
assert js_globals.Helper.type() is not None
assert js_globals.Modules.type() is not None
# Check if modules have loaded
assert js_globals.Modules.History.type() is not None
assert js_globals.Modules.Latex.type() is not None
assert js_globals.Modules.Canvas.type() is not None
assert js_globals.Modules.IO.type() is not None
assert js_globals.Modules.Objects.type() is not None
assert js_globals.Modules.Preferences.type() is not None

View file

@ -0,0 +1,57 @@
"""
* LogarithmPlotter - 2D plotter software to make BODE plots, sequences and distribution functions.
* Copyright (C) 2021-2024 Ad5001
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
"""
import pytest
from os.path import exists
from PySide6.QtCore import QEvent, QObject, QUrl
from PySide6.QtGui import QActionEvent, QFileOpenEvent
from LogarithmPlotter.util.native import MacOSFileOpenHandler
class LoadDiagramCalledSuccessfully(Exception): pass
class MockIO:
def loadDiagram(self, file_name):
assert type(file_name) == str
raise LoadDiagramCalledSuccessfully()
class MockFileOpenEvent(QEvent):
def __init__(self, file):
QEvent.__init__(self, QEvent.FileOpen)
self._file = file
def file(self):
return self._file
def test_native():
event_filter = MacOSFileOpenHandler()
# Nothing should happen here. The module hasn't been initialized
event_filter.eventFilter(None, QFileOpenEvent(QUrl.fromLocalFile("ci/test1.lpf")))
with pytest.raises(LoadDiagramCalledSuccessfully):
event_filter.init_io(MockIO()) # Now that we've initialized, the loadDiagram function should be called.
with pytest.raises(LoadDiagramCalledSuccessfully):
# And now it will do so every time an event is loaded.
event_filter.eventFilter(None, QFileOpenEvent(QUrl.fromLocalFile("ci/test1.lpf")))
# Check what happens when a non file open qevent is launched against it.
event_filter.eventFilter(QObject(), QEvent(QEvent.ActionAdded))

View file

@ -0,0 +1,77 @@
"""
* LogarithmPlotter - 2D plotter software to make BODE plots, sequences and distribution functions.
* Copyright (C) 2021-2024 Ad5001
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
"""
import pytest
from re import Pattern
from PySide6.QtQml import QJSEngine, QJSValue
from LogarithmPlotter.util.js import PyJSValue, InvalidAttributeValueException, NotAPrimitiveException
from globals import app
@pytest.fixture()
def data():
engine = QJSEngine()
obj = PyJSValue(engine.globalObject())
yield engine, obj
class TestPyJS:
def test_set(self, data):
engine, obj = data
obj.num1 = 2
obj.num2 = QJSValue(2)
obj.num3 = PyJSValue(QJSValue(2))
with pytest.raises(InvalidAttributeValueException):
obj.num3 = object()
def test_eq(self, data):
engine, obj = data
obj.num = QJSValue(2)
assert obj.num == 2
assert obj.num == QJSValue(2)
assert obj.num == PyJSValue(QJSValue(2))
assert obj.num != object()
def test_function(self, data):
engine, obj = data
function = PyJSValue(engine.evaluate("(function(argument) {return argument*2})"))
assert function(3) == 6
assert function(10) == 20
function2 = PyJSValue(engine.evaluate("(function(argument) {return argument+3})"), obj.qjs_value)
assert function2(3) == 6
assert function2(10) == 13
function3 = PyJSValue(engine.evaluate("2+2"))
with pytest.raises(InvalidAttributeValueException):
function3()
def test_type(self, data):
engine, obj = data
assert PyJSValue(engine.evaluate("[]")).type() == list
assert PyJSValue(engine.evaluate("undefined")).type() is None
assert PyJSValue(engine.evaluate("/[a-z]/g")).type() == Pattern
assert PyJSValue(QJSValue(2)).type() == float
assert PyJSValue(QJSValue("3")).type() == str
assert PyJSValue(QJSValue(True)).type() == bool
def test_primitive(self, data):
engine, obj = data
assert PyJSValue(QJSValue(2)).primitive() == 2
assert PyJSValue(QJSValue("string")).primitive() == "string"
assert PyJSValue(QJSValue(True)).primitive() == True
assert PyJSValue(engine.evaluate("undefined")).primitive() is None
with pytest.raises(NotAPrimitiveException):
assert PyJSValue(engine.evaluate("[]")).primitive() == []

View file

@ -0,0 +1,67 @@
"""
* LogarithmPlotter - 2D plotter software to make BODE plots, sequences and distribution functions.
* Copyright (C) 2021-2024 Ad5001
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
"""
from sys import argv
import pytest
from PySide6.QtCore import QThreadPool
from LogarithmPlotter import __VERSION__ as version
from LogarithmPlotter.util.update import UpdateInformation, UpdateCheckerRunnable, check_for_updates
class MockWindow:
def showAlert(self, msg): raise Exception(msg)
def showUpdateMenu(self, msg): pass
def check_update_callback_type(show_alert, msg_text, update_available):
assert type(show_alert) == bool
assert type(msg_text) == str
assert type(update_available) == bool
def test_update(qtbot):
def check_older(show_alert, msg_text, update_available):
check_update_callback_type(show_alert, msg_text, update_available)
assert update_available
assert show_alert
def check_newer(show_alert, msg_text, update_available):
check_update_callback_type(show_alert, msg_text, update_available)
assert not update_available
assert not show_alert
update_info_older = UpdateInformation()
update_info_older.got_update_info.connect(check_older)
update_info_newer = UpdateInformation()
update_info_newer.got_update_info.connect(check_newer)
runnable = UpdateCheckerRunnable('1.0.0', update_info_newer)
runnable.run()
qtbot.waitSignal(update_info_newer.got_update_info, timeout=10000)
runnable = UpdateCheckerRunnable('0.1.0', update_info_older)
runnable.run()
qtbot.waitSignal(update_info_older.got_update_info, timeout=10000)
runnable = UpdateCheckerRunnable('0.5.0+dev0+git20240101', update_info_older)
runnable.run()
qtbot.waitSignal(update_info_older.got_update_info, timeout=10000)
def test_update_checker(qtbot):
update_info = check_for_updates('0.6.0', MockWindow())
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())
assert QThreadPool.globalInstance().activeThreadCount() < 2 # No new update checks where added