Continuing python tests
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Adsooi 2024-09-18 00:31:17 +02:00
parent 9072e94d14
commit 4759bdcd33
Signed by: Ad5001
GPG key ID: EF45F9C6AFE20160
3 changed files with 85 additions and 6 deletions

View file

@ -1,10 +1,42 @@
import unittest
import pytest
from LogarithmPlotter.util import config
from tempfile import TemporaryDirectory
from os.path import join
class MyTestCase(unittest.TestCase):
def test_something(self):
self.assertEqual(True, False) # add assertion here
@pytest.fixture()
def resource():
directory = TemporaryDirectory()
config.CONFIG_FILE = join(directory.name, "config.json")
config.init()
yield config.CONFIG_FILE
directory.cleanup()
if __name__ == '__main__':
unittest.main()
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,13 @@
import pytest
from os.path import join
from tempfile import TemporaryDirectory
from LogarithmPlotter.util import config
@pytest.fixture()
def resource():
directory = TemporaryDirectory()
config.CONFIG_PATH = join(directory.name, "config.json")
tmpfile = join(directory.name, 'graph.png')
yield tmpfile
directory.cleanup()

View file

@ -0,0 +1,34 @@
import pytest
from PySide6.QtQml import QJSEngine, QJSValue
from PySide6.QtWidgets import QApplication
from LogarithmPlotter.util.js import PyJSValue, InvalidAttributeValueException
app = QApplication()
engine = QJSEngine()
obj = PyJSValue(engine.globalObject())
class TestPyJS:
def test_set(self):
obj.num1 = 2
obj.num2 = QJSValue(2)
with pytest.raises(InvalidAttributeValueException):
obj.num3 = object()
def test_eq(self):
obj.num = QJSValue(2)
assert obj.num == 2
assert obj.num == QJSValue(2)
assert obj.num != object()
def test_function(self):
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()