Updated the Common tests to new format

This commit is contained in:
Veronica K. B. Olsen
2020-12-06 12:46:10 +01:00
parent 7c95e6dffa
commit 730b572d4f
2 changed files with 62 additions and 21 deletions
+1
View File
@@ -61,6 +61,7 @@ The commands for the respective test categories are listed below.
| Type | Test Target | Source File(s) | Marker | Filter | | Type | Test Target | Source File(s) | Marker | Filter |
| :--- | :----------------- | :-------------------- | :-------- | :-------------------- | | :--- | :----------------- | :-------------------- | :-------- | :-------------------- |
| Unit | Common functions | nw/common.py | `-m base` | `-k testBaseCommon` |
| Unit | Core functions | nw/core/tools.py | `-m core` | `-k testCoreTools` | | Unit | Core functions | nw/core/tools.py | `-m core` | `-k testCoreTools` |
| Unit | NWDoc class | nw/core/document.py | `-m core` | `-k testCoreDocument` | | Unit | NWDoc class | nw/core/document.py | `-m core` | `-k testCoreDocument` |
| Unit | NWIndex class | nw/core/index.py | `-m core` | `-k testCoreIndex` | | Unit | NWIndex class | nw/core/index.py | `-m core` | `-k testCoreIndex` |
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
"""novelWriter Common Class Tester """novelWriter Common Functions Tester
""" """
import time import time
@@ -11,8 +11,10 @@ from nw.common import (
) )
from tools import cmpList from tools import cmpList
@pytest.mark.core @pytest.mark.base
def testCheckString(): def testBaseCommon_CheckString():
"""Test the checkString function.
"""
assert checkString(None, "NotNone", True) is None assert checkString(None, "NotNone", True) is None
assert checkString("None", "NotNone", True) is None assert checkString("None", "NotNone", True) is None
assert checkString("None", "NotNone", False) == "None" assert checkString("None", "NotNone", False) == "None"
@@ -21,8 +23,12 @@ def testCheckString():
assert checkString(1.0, "NotNone", False) == "NotNone" assert checkString(1.0, "NotNone", False) == "NotNone"
assert checkString(True, "NotNone", False) == "NotNone" assert checkString(True, "NotNone", False) == "NotNone"
@pytest.mark.core # END Test testBaseCommon_CheckString
def testCheckInt():
@pytest.mark.base
def testBaseCommon_CheckInt():
"""Test the checkInt function.
"""
assert checkInt(None, 3, True) is None assert checkInt(None, 3, True) is None
assert checkInt("None", 3, True) is None assert checkInt("None", 3, True) is None
assert checkInt(None, 3, False) == 3 assert checkInt(None, 3, False) == 3
@@ -30,8 +36,12 @@ def testCheckInt():
assert checkInt(1.0, 3, False) == 1 assert checkInt(1.0, 3, False) == 1
assert checkInt(True, 3, False) == 1 assert checkInt(True, 3, False) == 1
@pytest.mark.core # END Test testBaseCommon_CheckInt
def testCheckBool():
@pytest.mark.base
def testBaseCommon_CheckBool():
"""Test the checkBool function.
"""
assert checkBool(None, 3, True) is None assert checkBool(None, 3, True) is None
assert checkBool("None", 3, True) is None assert checkBool("None", 3, True) is None
assert checkBool("True", False, False) assert checkBool("True", False, False)
@@ -44,8 +54,12 @@ def testCheckBool():
assert checkBool(1.0, None, False) is None assert checkBool(1.0, None, False) is None
assert checkBool(2.0, None, False) is None assert checkBool(2.0, None, False) is None
@pytest.mark.core # END Test testBaseCommon_CheckBool
def testCheckHandle():
@pytest.mark.base
def testBaseCommon_CheckHandle():
"""Test the checkHandle function.
"""
assert checkHandle("None", 1, True) is None assert checkHandle("None", 1, True) is None
assert checkHandle("None", 1, False) == 1 assert checkHandle("None", 1, False) == 1
assert checkHandle(None, 1, True) is None assert checkHandle(None, 1, True) is None
@@ -53,8 +67,12 @@ def testCheckHandle():
assert checkHandle("47666c91c7ccf", None, False) == "47666c91c7ccf" assert checkHandle("47666c91c7ccf", None, False) == "47666c91c7ccf"
assert checkHandle("h7666c91c7ccf", None, False) is None assert checkHandle("h7666c91c7ccf", None, False) is None
@pytest.mark.core # END Test testBaseCommon_CheckHandle
def testColRange():
@pytest.mark.base
def testBaseCommon_ColRange():
"""Test the colRange function.
"""
assert colRange([0, 0], [0, 0], 0) is None assert colRange([0, 0], [0, 0], 0) is None
assert cmpList( assert cmpList(
colRange([200, 50, 0], [50, 200, 0], 1), colRange([200, 50, 0], [50, 200, 0], 1),
@@ -77,14 +95,22 @@ def testColRange():
[[200, 50, 0], [162, 87, 0], [124, 124, 0], [86, 161, 0], [50, 200, 0]] [[200, 50, 0], [162, 87, 0], [124, 124, 0], [86, 161, 0], [50, 200, 0]]
) )
@pytest.mark.core # END Test testBaseCommon_ColRange
def testFormatTimeStamp():
@pytest.mark.base
def testBaseCommon_FormatTimeStamp():
"""Test the formatTimeStamp function.
"""
tTime = time.mktime(time.gmtime(0)) tTime = time.mktime(time.gmtime(0))
assert formatTimeStamp(tTime, False) == "1970-01-01 00:00:00" assert formatTimeStamp(tTime, False) == "1970-01-01 00:00:00"
assert formatTimeStamp(tTime, True) == "1970-01-01 00.00.00" assert formatTimeStamp(tTime, True) == "1970-01-01 00.00.00"
@pytest.mark.core # END Test testBaseCommon_FormatTimeStamp
def testFormatTime():
@pytest.mark.base
def testBaseCommon_FormatTime():
"""Test the formatTime function.
"""
assert formatTime("1") == "ERROR" assert formatTime("1") == "ERROR"
assert formatTime(1.0) == "ERROR" assert formatTime(1.0) == "ERROR"
assert formatTime(1) == "00:00:01" assert formatTime(1) == "00:00:01"
@@ -101,8 +127,12 @@ def testFormatTime():
assert formatTime(86400) == "1-00:00:00" assert formatTime(86400) == "1-00:00:00"
assert formatTime(360000) == "4-04:00:00" assert formatTime(360000) == "4-04:00:00"
@pytest.mark.core # END Test testBaseCommon_FormatTime
def testFormatInt():
@pytest.mark.base
def testBaseCommon_FormatInt():
"""Test the formatInt function.
"""
assert formatInt(1000) == "1000" assert formatInt(1000) == "1000"
assert formatInt(1234) == "1.23\u2009k" assert formatInt(1234) == "1.23\u2009k"
assert formatInt(12345) == "12.3\u2009k" assert formatInt(12345) == "12.3\u2009k"
@@ -112,8 +142,12 @@ def testFormatInt():
assert formatInt(123456789) == "123\u2009M" assert formatInt(123456789) == "123\u2009M"
assert formatInt(1234567890) == "1.23\u2009G" assert formatInt(1234567890) == "1.23\u2009G"
@pytest.mark.core # END Test testBaseCommon_FormatInt
def testTransferCase():
@pytest.mark.base
def testBaseCommon_TransferCase():
"""Test the transferCase function.
"""
assert transferCase(1, "TaRgEt") == "TaRgEt" assert transferCase(1, "TaRgEt") == "TaRgEt"
assert transferCase("source", 1) == 1 assert transferCase("source", 1) == 1
assert transferCase("", "TaRgEt") == "TaRgEt" assert transferCase("", "TaRgEt") == "TaRgEt"
@@ -122,8 +156,12 @@ def testTransferCase():
assert transferCase("SOURCE", "target") == "TARGET" assert transferCase("SOURCE", "target") == "TARGET"
assert transferCase("source", "TARGET") == "target" assert transferCase("source", "TARGET") == "target"
@pytest.mark.core # END Test testBaseCommon_TransferCase
def testFuzzyTime():
@pytest.mark.base
def testBaseCommon_FuzzyTime():
"""Test the fuzzyTime function.
"""
assert fuzzyTime(-1) == "in the future" assert fuzzyTime(-1) == "in the future"
assert fuzzyTime(0) == "just now" assert fuzzyTime(0) == "just now"
assert fuzzyTime(29) == "just now" assert fuzzyTime(29) == "just now"
@@ -152,3 +190,5 @@ def testFuzzyTime():
assert fuzzyTime(29808000) == "a year ago" assert fuzzyTime(29808000) == "a year ago"
assert fuzzyTime(47336399) == "a year ago" assert fuzzyTime(47336399) == "a year ago"
assert fuzzyTime(47336400) == "2 years ago" assert fuzzyTime(47336400) == "2 years ago"
# END Test testBaseCommon_FuzzyTime