diff --git a/synthesis/random.py b/synthesis/random.py index 761d695..110f970 100644 --- a/synthesis/random.py +++ b/synthesis/random.py @@ -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) diff --git a/synthesis/segment/plot.py b/synthesis/segment/plot.py index f3fe510..b32e5c9 100644 --- a/synthesis/segment/plot.py +++ b/synthesis/segment/plot.py @@ -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 diff --git a/synthesis/segment/random_content_rectangle.py b/synthesis/segment/random_content_rectangle.py index e3b9cde..309b6bd 100644 --- a/synthesis/segment/random_content_rectangle.py +++ b/synthesis/segment/random_content_rectangle.py @@ -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) diff --git a/synthesis/segment/table/table.py b/synthesis/segment/table/table.py index 7c380ba..b52e6d5 100644 --- a/synthesis/segment/table/table.py +++ b/synthesis/segment/table/table.py @@ -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}") diff --git a/test/fixtures/page_generation/page.py b/test/fixtures/page_generation/page.py index 4de18ed..6c3f33a 100644 --- a/test/fixtures/page_generation/page.py +++ b/test/fixtures/page_generation/page.py @@ -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: