from pathlib import Path


def test_rerun_with_special_paths(project, renku_cli, source, output):
    """Test rerun with unicode/whitespace filenames."""
    cwd = Path(project)
    source = cwd / source
    output = cwd / output

    assert 0 == renku_cli("run", "python", "-S", "-c", "import random; print(random.random())", stdout=source).exit_code
    assert 0 == renku_cli("run", "cat", source, stdout=output).exit_code

    content = output.read_text().strip()

    def rerun():
        assert 0 == renku_cli("rerun", output).exit_code
        return output.read_text().strip()

    for _ in range(10):
        new_content = rerun()
        if content != new_content:
            break

    assert content != output.read_text().strip(), "The output should have changed."