def test_write(tmp_path):
    tld = TEST_FONTS_DIR / "good"
    for f in tld.iterdir():
        ext = f.suffix
        if ext.lower() not in KNOWN_EXTENSIONS:
            continue

        out_file = tmp_path / f.name

        _ = pyots.sanitize(f, output=out_file)

        assert out_file.exists()
def test_ots_bad():

    tld = TEST_FONTS_DIR / "bad"

    count = 0
    for f in tld.iterdir():
        ext = f.suffix
        if ext.lower() not in KNOWN_EXTENSIONS:
            continue

        r = pyots.sanitize(f)

        if r.sanitized:
            count += 1
            print("[bad] unexpected success on", f, "\n".join(r.messages))

    assert not count, f"{count} file{'s were' if count != 1 else 'was'} sanitized when expected to be sanitized."  # noqa: E501
def test_ots_good():

    tld = TEST_FONTS_DIR / "good"

    count = 0
    for f in tld.iterdir():
        ext = f.suffix
        if ext.lower() not in KNOWN_EXTENSIONS:
            continue

        r = pyots.sanitize(f)

        if not r.sanitized:
            count += 1
            print("[good] unexpected failure on", f, "\n".join(r.messages))

    assert not count, f"{count} file{'s' if count != 1 else ''} failed when expected to be sanitized."  # noqa: E501
def test_ots_fuzzing():

    tld = TEST_FONTS_DIR / "fuzzing"

    count = 0
    for f in tld.iterdir():
        ext = f.suffix
        if ext.lower() not in KNOWN_EXTENSIONS:
            continue

        r = pyots.sanitize(f)

        if str(f.relative_to(TEST_FONTS_DIR)) in EXPECT_FAIL:
            if r.sanitized:
                count += 1
                print("[fuzzing] unexpected success on", f,
                      "\n".join(r.messages))
        else:
            if not r.sanitized:
                count += 1
                print("[fuzzing] unexpected failure on", f,
                      "\n".join(r.messages))

    assert not count, f"{count} file{'s' if count != 1 else ''} had an unexpected sanitization result."
Exemple #5
0
def _get_pyots_result(path):
    return pyots.sanitize(path)