Add a mock random number generator for testing
This commit is contained in:
+20
-21
@@ -24,8 +24,6 @@ import sys
|
|||||||
import pytest
|
import pytest
|
||||||
import shutil
|
import shutil
|
||||||
|
|
||||||
from dataclasses import dataclass
|
|
||||||
|
|
||||||
from mock import MockGuiMain
|
from mock import MockGuiMain
|
||||||
from tools import cleanProject
|
from tools import cleanProject
|
||||||
|
|
||||||
@@ -184,6 +182,26 @@ def nwGUI(qtbot, monkeypatch, fncDir, fncConf):
|
|||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
|
##
|
||||||
|
# Python Objects
|
||||||
|
##
|
||||||
|
|
||||||
|
@pytest.fixture(scope="function")
|
||||||
|
def mockRnd(monkeypatch):
|
||||||
|
"""Create a mock random number generator that just counts upwards
|
||||||
|
from 0. This one will generate status/importance flags and handles
|
||||||
|
in a predictable sequence.
|
||||||
|
"""
|
||||||
|
def rnd(n):
|
||||||
|
for x in range(n):
|
||||||
|
yield x
|
||||||
|
|
||||||
|
gen = rnd(1000)
|
||||||
|
monkeypatch.setattr("random.getrandbits", lambda *a: next(gen))
|
||||||
|
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
##
|
##
|
||||||
# Temp Project Folders
|
# Temp Project Folders
|
||||||
##
|
##
|
||||||
@@ -252,25 +270,6 @@ def nwOldProj(tmpDir):
|
|||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
##
|
|
||||||
# Data Fixtures
|
|
||||||
##
|
|
||||||
|
|
||||||
@dataclass
|
|
||||||
class TestConst:
|
|
||||||
|
|
||||||
statusKeys = ["sa3b179", "s1c8031", "s06671a", "sbdd640"]
|
|
||||||
importKeys = ["i466852", "i3eb13b", "i392456", "i23b8c1"]
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope="session")
|
|
||||||
def constData():
|
|
||||||
"""A named tuple of known contstant values. For those that depend on
|
|
||||||
the random number generator, they assume the seed is 42.
|
|
||||||
"""
|
|
||||||
return TestConst()
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope="session")
|
@pytest.fixture(scope="session")
|
||||||
def ipsumText():
|
def ipsumText():
|
||||||
"""Return five paragraphs of Lorem Ipsum text.
|
"""Return five paragraphs of Lorem Ipsum text.
|
||||||
|
|||||||
Reference in New Issue
Block a user