import pytest
from .exemplar_generators import EXEMPLAR_CUSTOM_GENERATORS


@pytest.mark.xfail(reason="Spawning doesn't currently transfer the random state correctly")
@pytest.mark.parametrize("g", EXEMPLAR_CUSTOM_GENERATORS)
def test_spawn_custom_generators(g):
    """
    Test that custom generators can be spawned and the spawned versions produce the same elements.
    """
    num_items = 50
    seed = 12345
    g.reset(seed)

    # Let g generate a few items
    items_g_pre_spawn = list(g.generate(num_items))

    # Spawn g and let both generate a few more items
    h = g.spawn()
    items_g_post_spawn = list(g.generate(num_items))
    items_h_post_spawn = list(h.generate(num_items))

    # Reset h and re-generate the full list of items
    h.reset(seed)
    items_h_all = list(h.generate(2*num_items))

    # Verify that the items generated by h after spawning
    # as well as the full sets of items are identical.
    assert items_h_post_spawn == items_g_post_spawn
    assert items_h_all == items_g_pre_spawn + items_g_post_spawn
import pytest
from .exemplar_generators import EXEMPLAR_CUSTOM_GENERATORS


@pytest.mark.parametrize("g", EXEMPLAR_CUSTOM_GENERATORS)
def test_spawn_custom_generators(g):
    """
    Test that custom generators can be spawned and the spawned versions produce the same elements.
    """
    num_items = 50
    seed = 12345
    g.reset(seed)

    # Let g generate a few items
    items_g_pre_spawn = list(g.generate(num_items))

    # Spawn g and let both generate a few more items
    h = g.spawn()
    items_g_post_spawn = list(g.generate(num_items))
    items_h_post_spawn = list(h.generate(num_items))

    # Reset h and re-generate the full list of items
    h.reset(seed)
    items_h_all = list(h.generate(2*num_items))

    # Verify that the items generated by h after spawning
    # as well as the full sets of items are identical.
    assert items_h_post_spawn == items_g_post_spawn
    assert items_h_all == items_g_pre_spawn + items_g_post_spawn

Test now passes