def test_unicode_filenames(assert_pixels_equal, tmp_path):
    """Test non-ASCII filenames both in Unicode or bytes form."""
    # Replicate pattern.png in CSS so that base_url does not matter.
    html = b'''
        <style>
            @page { margin: 2px; size: 8px }
            html { background: #00f; }
            body { background: #f00; width: 1px; height: 1px }
        </style>
        <body>
    '''
    png_bytes = FakeHTML(string=html).write_png()
    check_png_pattern(assert_pixels_equal, png_bytes)
    unicode_filename = 'Unicödé'
    if sys.platform.startswith('darwin'):  # pragma: no cover
        unicode_filename = unicodedata.normalize('NFD', unicode_filename)

    with chdir(tmp_path):
        (tmp_path / unicode_filename).write_bytes(html)
        bytes_file, = tuple(tmp_path.iterdir())
        assert bytes_file.name == unicode_filename

        assert FakeHTML(unicode_filename).write_png() == png_bytes
        assert FakeHTML(bytes_file).write_png() == png_bytes

        os.remove(unicode_filename)
        assert not tuple(tmp_path.iterdir())

        FakeHTML(string=html).write_png(unicode_filename)
        assert bytes_file.read_bytes() == png_bytes
Test non-ASCII filenames both in Unicode or bytes form.
tests/test_api.py