Adding new python
This commit is contained in:
parent
c66d08b352
commit
5bdf81b2ed
3 changed files with 120 additions and 4 deletions
|
@ -39,7 +39,3 @@ if not is_release and which('git') is not None:
|
||||||
# Date cannot be parsed, not git root?
|
# Date cannot be parsed, not git root?
|
||||||
pass
|
pass
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
from .logarithmplotter import run
|
|
||||||
|
|
||||||
run()
|
|
||||||
|
|
57
tests/python/test_native.py
Normal file
57
tests/python/test_native.py
Normal 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):
|
||||||
|
super(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))
|
||||||
|
|
63
tests/python/test_update.py
Normal file
63
tests/python/test_update.py
Normal file
|
@ -0,0 +1,63 @@
|
||||||
|
"""
|
||||||
|
* 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():
|
||||||
|
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()
|
||||||
|
runnable = UpdateCheckerRunnable('0.1.0', update_info_older)
|
||||||
|
runnable.run()
|
||||||
|
runnable = UpdateCheckerRunnable('0.5.0+dev0+git20240101', update_info_older)
|
||||||
|
runnable.run()
|
||||||
|
|
||||||
|
def test_update_checker():
|
||||||
|
check_for_updates('0.6.0', MockWindow())
|
||||||
|
assert QThreadPool.globalInstance().activeThreadCount() == 1
|
||||||
|
argv.append("--no-check-for-updates")
|
||||||
|
check_for_updates('0.6.0', MockWindow())
|
||||||
|
assert QThreadPool.globalInstance().activeThreadCount() < 2 # No new update checks where added
|
Loading…
Reference in a new issue