Refactoring
This commit is contained in:
parent
a3fece8096
commit
6dbe3b6fc9
54
test/fixtures/page_generation/page.py
vendored
54
test/fixtures/page_generation/page.py
vendored
@ -43,7 +43,11 @@ random_seed = random.randint(0, 2**32 - 1)
|
|||||||
# random_seed = 273244862 # empty large table
|
# random_seed = 273244862 # empty large table
|
||||||
# random_seed = 3717442900
|
# random_seed = 3717442900
|
||||||
# random_seed = 2508340737
|
# random_seed = 2508340737
|
||||||
# random_seed = 2212357755
|
|
||||||
|
|
||||||
|
random_seed = 2212357755
|
||||||
|
# random_seed = 3400335399
|
||||||
|
|
||||||
rnd = random.Random(random_seed)
|
rnd = random.Random(random_seed)
|
||||||
logger.info(f"Random seed: {random_seed}")
|
logger.info(f"Random seed: {random_seed}")
|
||||||
|
|
||||||
@ -318,6 +322,7 @@ def tinted_blank_page(size, color, color_intensity):
|
|||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def blank_page(size, color, color_intensity):
|
def blank_page(size, color, color_intensity):
|
||||||
|
rnd.seed(random_seed)
|
||||||
page = Image.new("RGBA", size, color=(255, 255, 255, 0))
|
page = Image.new("RGBA", size, color=(255, 255, 255, 0))
|
||||||
return page
|
return page
|
||||||
|
|
||||||
@ -429,7 +434,7 @@ def compute_pasting_coordinates(smaller: Image, larger: Image.Image):
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def page_with_content(blank_page, tinted_blank_page, texture, texture_fn) -> np.ndarray:
|
def page_with_opaque_content(blank_page, tinted_blank_page, texture, texture_fn) -> np.ndarray:
|
||||||
"""Creates a page with content"""
|
"""Creates a page with content"""
|
||||||
page_partitioner = rnd.choice(
|
page_partitioner = rnd.choice(
|
||||||
[
|
[
|
||||||
@ -438,17 +443,29 @@ def page_with_content(blank_page, tinted_blank_page, texture, texture_fn) -> np.
|
|||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
###############################
|
texture = random_flip(texture)
|
||||||
# texture = random_flip(texture)
|
texture = texture_fn(texture)
|
||||||
# texture = texture_fn(texture)
|
|
||||||
#
|
boxes = page_partitioner(texture)
|
||||||
# boxes = page_partitioner(texture)
|
content_generator = ContentGenerator()
|
||||||
# content_generator = ContentGenerator()
|
boxes = content_generator(boxes)
|
||||||
# boxes = content_generator(boxes)
|
page = paste_contents(texture, boxes)
|
||||||
# page = paste_contents(texture, boxes)
|
|
||||||
###############################
|
return page, boxes
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def page_with_translucent_content(
|
||||||
|
blank_page, tinted_blank_page, texture, texture_fn
|
||||||
|
) -> Tuple[np.ndarray, List[Rectangle]]:
|
||||||
|
"""Creates a page with content"""
|
||||||
|
page_partitioner = rnd.choice(
|
||||||
|
[
|
||||||
|
TwoColumnPagePartitioner(),
|
||||||
|
# RandomPagePartitioner(),
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
################################
|
|
||||||
boxes = page_partitioner(blank_page)
|
boxes = page_partitioner(blank_page)
|
||||||
content_generator = ContentGenerator()
|
content_generator = ContentGenerator()
|
||||||
boxes = content_generator(boxes)
|
boxes = content_generator(boxes)
|
||||||
@ -459,7 +476,18 @@ def page_with_content(blank_page, tinted_blank_page, texture, texture_fn) -> np.
|
|||||||
|
|
||||||
page_content = multiply_alpha_where_alpha_channel_is_nonzero(page_content, factor=0.6)
|
page_content = multiply_alpha_where_alpha_channel_is_nonzero(page_content, factor=0.6)
|
||||||
page = superimpose_texture_with_transparency(texture, page_content, crop_to_content=False)
|
page = superimpose_texture_with_transparency(texture, page_content, crop_to_content=False)
|
||||||
################################
|
|
||||||
|
return page, boxes
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def page_with_content(
|
||||||
|
# page_with_translucent_content,
|
||||||
|
page_with_opaque_content,
|
||||||
|
) -> np.ndarray:
|
||||||
|
|
||||||
|
# page, boxes = page_with_translucent_content
|
||||||
|
page, boxes = page_with_opaque_content
|
||||||
|
|
||||||
draw_boxes(page, boxes)
|
draw_boxes(page, boxes)
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user