mirror of
https://github.com/olivierkes/manuskript.git
synced 2024-05-13 09:22:32 +12:00
Adds unit tests for functions
This commit is contained in:
parent
84466b90e3
commit
1a5fdc7b1f
|
@ -366,4 +366,3 @@ def inspect():
|
|||
s.lineno,
|
||||
s.function))
|
||||
print(" " + "".join(s.code_context))
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@ def run():
|
|||
app.setOrganizationDomain("www.theologeek.ch")
|
||||
app.setApplicationName("manuskript")
|
||||
app.setApplicationVersion(getVersion())
|
||||
|
||||
|
||||
print("Running manuskript version {}.".format(getVersion()))
|
||||
icon = QIcon()
|
||||
for i in [16, 32, 64, 128, 256, 512]:
|
||||
|
@ -65,7 +65,7 @@ def run():
|
|||
|
||||
|
||||
def launch():
|
||||
from .mainWindow import MainWindow
|
||||
from manuskript.mainWindow import MainWindow
|
||||
|
||||
main = MainWindow()
|
||||
# We store the system default cursor flash time to be able to restore it
|
||||
|
|
|
@ -2,3 +2,24 @@
|
|||
# --!-- coding: utf8 --!--
|
||||
|
||||
"""Tests."""
|
||||
|
||||
import pytest
|
||||
|
||||
# We need a qApplication to be running, or all the calls to qApp
|
||||
# will throw a seg fault.
|
||||
from PyQt5.QtWidgets import QApplication
|
||||
app = QApplication([])
|
||||
|
||||
@pytest.yield_fixture(scope='session', autouse=True)
|
||||
def MW():
|
||||
|
||||
# Creates a mainWindow that can be used for the tests
|
||||
# Either with functions.mainWindow or by passing argument
|
||||
# MW to the test
|
||||
from manuskript.mainWindow import MainWindow
|
||||
mw = MainWindow()
|
||||
|
||||
yield
|
||||
|
||||
# Properly destructed after. Otherwise: seg fault.
|
||||
mw.deleteLater()
|
||||
|
|
4
manuskript/tests/models/__init__.py
Normal file
4
manuskript/tests/models/__init__.py
Normal file
|
@ -0,0 +1,4 @@
|
|||
#!/usr/bin/env python
|
||||
# --!-- coding: utf8 --!--
|
||||
|
||||
"""Tests for models."""
|
|
@ -3,10 +3,27 @@
|
|||
|
||||
"""Tests for outlineItem"""
|
||||
|
||||
import pytest
|
||||
|
||||
def square(i):
|
||||
return i*i
|
||||
from manuskript.models.outlineItem import outlineItem
|
||||
|
||||
def test_square():
|
||||
assert square(2) == 4
|
||||
assert square(-2) == 4
|
||||
@pytest.fixture
|
||||
def outlineItemFolder():
|
||||
'''Returns a folder outlineItem title "Folder".'''
|
||||
return outlineItem(title="Folder")
|
||||
|
||||
@pytest.fixture
|
||||
def outlineItemText():
|
||||
'''Returns a text outlineItem title "Text".'''
|
||||
return outlineItem(title="Text", _type="md")
|
||||
|
||||
def test_outlineItemsProperties(outlineItemFolder, outlineItemText):
|
||||
|
||||
# Simplification
|
||||
folder = outlineItemFolder
|
||||
text = outlineItemText
|
||||
|
||||
# Basic tests
|
||||
assert folder.isFolder() == True
|
||||
assert text.isFolder() == False
|
||||
assert text.isText() == True
|
||||
|
|
100
manuskript/tests/test_functions.py
Normal file
100
manuskript/tests/test_functions.py
Normal file
|
@ -0,0 +1,100 @@
|
|||
#!/usr/bin/env python
|
||||
# --!-- coding: utf8 --!--
|
||||
|
||||
"""Tests for functions"""
|
||||
|
||||
from manuskript import functions as F
|
||||
|
||||
def test_wordCount():
|
||||
assert F.wordCount("In the beginning was the word.") == 6
|
||||
assert F.wordCount("") == 0
|
||||
|
||||
def test_convert():
|
||||
|
||||
# toInt
|
||||
assert F.toInt("9") == 9
|
||||
assert F.toInt("a") == 0
|
||||
assert F.toInt("") == 0
|
||||
|
||||
# toFloat
|
||||
assert F.toFloat("9.4") == 9.4
|
||||
assert F.toFloat("") == 0.
|
||||
|
||||
# toString
|
||||
assert F.toString(None) == ""
|
||||
assert F.toString("None") == ""
|
||||
assert F.toString("Joy") == "Joy"
|
||||
|
||||
def test_several():
|
||||
|
||||
from PyQt5.QtGui import QPainter, QPixmap, QIcon, QColor
|
||||
from PyQt5.QtCore import QRect
|
||||
|
||||
# drawProgress
|
||||
px = QPixmap(10, 10)
|
||||
F.drawProgress(QPainter(px), QRect(0, 0, 100, 100), 0.5)
|
||||
|
||||
# colorFromProgress
|
||||
a = F.colorFromProgress(0.1)
|
||||
b = F.colorFromProgress(0.5)
|
||||
c = F.colorFromProgress(1.0)
|
||||
d = F.colorFromProgress(1.5)
|
||||
assert a != b != c != d
|
||||
|
||||
# mainWindow
|
||||
# assert F.mainWindow() == None # Because there is no MW
|
||||
|
||||
# iconColor & iconFromColor & iconFromColorString
|
||||
icon = F.iconFromColorString("#ff0000")
|
||||
assert F.iconColor(icon).name().lower() == "#ff0000"
|
||||
|
||||
# themeIcon
|
||||
assert F.themeIcon("text") is not None
|
||||
assert F.themeIcon("nonexistingname") is not None
|
||||
|
||||
# randomColor
|
||||
c1 = F.randomColor()
|
||||
c2 = F.randomColor(c1)
|
||||
assert c1.name() != c2.name()
|
||||
|
||||
# mixColors
|
||||
c1 = QColor("#FFF")
|
||||
c2 = QColor("#000")
|
||||
assert F.mixColors(c1, c2).name() == "#7f7f7f"
|
||||
|
||||
# colorifyPixmap
|
||||
assert F.colorifyPixmap(px, c1) != None
|
||||
|
||||
def test_outlineItemColors():
|
||||
|
||||
from manuskript.models import outlineItem
|
||||
item = outlineItem(title="Test")
|
||||
|
||||
r = F.outlineItemColors(item)
|
||||
for i in ["POV", "Label", "Progress", "Compile"]:
|
||||
assert i in r
|
||||
from PyQt5.QtGui import QColor
|
||||
assert r["Compile"].name(QColor.HexArgb) == "#00000000"
|
||||
|
||||
def test_paths():
|
||||
|
||||
assert F.appPath() is not None
|
||||
assert F.writablePath is not None
|
||||
assert len(F.allPaths("suffix")) == 2
|
||||
assert F.tempFile("yop") is not None
|
||||
f = F.findBackground("spacedreams.jpg")
|
||||
assert "resources/backgrounds/spacedreams.jpg" in f
|
||||
assert len(F.customIcons()) > 1
|
||||
|
||||
# def test_mainWindow():
|
||||
#
|
||||
# from manuskript.mainWindow import MainWindow
|
||||
# m = MainWindow()
|
||||
#
|
||||
# assert F.mainWindow() is not None
|
||||
# assert F.MW is not None
|
||||
#
|
||||
# F.statusMessage("Test")
|
||||
# F.printObjects()
|
||||
#
|
||||
# m.deleteLater()
|
Loading…
Reference in a new issue