clear color map cache per pytest parameter combination

This commit is contained in:
Matthias Bisping 2023-02-01 18:56:16 +01:00
parent 21a9db25cd
commit a1e6c9e553
5 changed files with 25 additions and 14 deletions

View File

@ -1,4 +1,5 @@
import random
from functools import lru_cache
from loguru import logger
@ -26,3 +27,8 @@ def possibly():
def probably():
return rnd.random() > 0.4
@lru_cache(maxsize=None)
def get_random_seed():
return rnd.randint(0, 2**32 - 1)

View File

@ -2,6 +2,7 @@ import io
import random
from functools import lru_cache, partial
import loguru
import numpy as np
from PIL import Image
from matplotlib import pyplot as plt
@ -175,6 +176,7 @@ def pick_colormap() -> ListedColormap:
"cividis",
],
)
loguru.logger.info(f"Using colormap {cmap_name}")
cmap = plt.get_cmap(cmap_name)
return cmap

View File

@ -1,7 +1,6 @@
import random
from functools import lru_cache
from synthesis.random import rnd
from synthesis.random import get_random_seed
from synthesis.segment.content_rectangle import ContentRectangle
@ -10,8 +9,3 @@ class RandomContentRectangle(ContentRectangle):
super().__init__(x1, y1, x2, y2, content)
self.seed = seed or get_random_seed()
self.random = random.Random(self.seed)
@lru_cache(maxsize=None)
def get_random_seed():
return rnd.randint(0, 2**32 - 1)

View File

@ -52,8 +52,6 @@ class RecursiveRandomTable(RandomContentRectangle):
self.background_color = get_random_background_color()
logger.info(f"Background color: {self.background_color}")
self.layout = layout or self.pick_random_layout()
logger.debug(f"Layout: {self.layout}")

View File

@ -28,8 +28,8 @@ logger.add(sys.stderr, level="INFO")
@pytest.fixture(
params=[
# "rough_grain",
# "plain",
"rough_grain",
"plain",
# "digital",
"crumpled",
]
@ -66,8 +66,8 @@ def dpi(request):
# "sepia",
# "gray",
"white",
# "light_red",
# "light_blue",
"light_red",
"light_blue",
]
)
def color_name(request):
@ -77,7 +77,7 @@ def color_name(request):
@pytest.fixture(
params=[
# "smooth",
# "coarse",
"coarse",
"neutral",
]
)
@ -243,8 +243,19 @@ def blend_by_multiply(page_content, texture):
return page
@pytest.fixture(scope="function")
def random_seeding():
from synthesis.segment.plot import pick_colormap
seed = str(rnd.randint(0, 2**32 - 1))
logger.info(f"Random seed: {seed}")
rnd.seed(seed)
pick_colormap.cache_clear()
@pytest.fixture
def page_with_content(
random_seeding,
page_with_translucent_content,
# page_with_opaque_content,
) -> np.ndarray: