Add a mock random number generator for testing

This commit is contained in:
Veronica Berglyd Olsen
2022-04-20 21:46:53 +02:00
parent 8320aab1bf
commit e32eb21fbf
+20 -21
View File
@@ -24,8 +24,6 @@ import sys
import pytest
import shutil
from dataclasses import dataclass
from mock import MockGuiMain
from tools import cleanProject
@@ -184,6 +182,26 @@ def nwGUI(qtbot, monkeypatch, fncDir, fncConf):
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
##
@@ -252,25 +270,6 @@ def nwOldProj(tmpDir):
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")
def ipsumText():
"""Return five paragraphs of Lorem Ipsum text.