From a1c6b5edf738f834cac268587eadf4c0d55df2e4 Mon Sep 17 00:00:00 2001 From: Hugo Date: Tue, 22 Oct 2019 16:37:04 +0300 Subject: [PATCH 1/6] Cover tests https://nedbatchelder.com/blog/201908/dont_omit_tests_from_coverage.html --- .appveyor.yml | 2 +- .github/workflows/test-windows.yml | 2 +- .travis/test.sh | 2 +- Tests/README.rst | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.appveyor.yml b/.appveyor.yml index 3183c3d1b..edfc75101 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -77,7 +77,7 @@ test_script: - cd c:\pillow - '%PYTHON%\%PIP_DIR%\pip.exe install pytest pytest-cov' - c:\"Program Files (x86)"\"Windows Kits"\10\Debuggers\x86\gflags.exe /p /enable %PYTHON%\%EXECUTABLE% -- '%PYTHON%\%EXECUTABLE% -m pytest -vx --cov PIL --cov-report term --cov-report xml Tests' +- '%PYTHON%\%EXECUTABLE% -m pytest -vx --cov PIL --cov Tests --cov-report term --cov-report xml Tests' #- '%PYTHON%\%EXECUTABLE% test-installed.py -v -s %TEST_OPTIONS%' TODO TEST_OPTIONS with pytest? after_test: diff --git a/.github/workflows/test-windows.yml b/.github/workflows/test-windows.yml index 075707bf6..05a04ca02 100644 --- a/.github/workflows/test-windows.yml +++ b/.github/workflows/test-windows.yml @@ -346,7 +346,7 @@ jobs: rem Add libraqm.dll (copied to INCLIB) to PATH. path %INCLIB%;%PATH% cd /D %GITHUB_WORKSPACE% - %PYTHON%\python.exe -m pytest -vx --cov PIL --cov-report term --cov-report xml Tests + %PYTHON%\python.exe -m pytest -vx --cov PIL --cov Tests --cov-report term --cov-report xml Tests shell: cmd - name: Upload errors diff --git a/.travis/test.sh b/.travis/test.sh index a65e620b8..91dae9f8d 100755 --- a/.travis/test.sh +++ b/.travis/test.sh @@ -2,7 +2,7 @@ set -e -python -m pytest -v -x --cov PIL --cov-report term Tests +python -m pytest -v -x --cov PIL --cov Tests --cov-report term Tests # Docs if [ "$TRAVIS_PYTHON_VERSION" == "3.7" ]; then make doccheck; fi diff --git a/Tests/README.rst b/Tests/README.rst index da3297bce..9c959a4bf 100644 --- a/Tests/README.rst +++ b/Tests/README.rst @@ -27,6 +27,6 @@ Run all the tests from the root of the Pillow source distribution:: Or with coverage:: - pytest --cov PIL --cov-report term + pytest --cov PIL --cov Tests --cov-report term coverage html open htmlcov/index.html From cccc535f66a306059f919dbb1f64547adc152490 Mon Sep 17 00:00:00 2001 From: Hugo Date: Sun, 27 Oct 2019 12:20:54 +0200 Subject: [PATCH 2/6] Omit Tests/check_ files from coverage --- .coveragerc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.coveragerc b/.coveragerc index ea79190ae..e93a2a426 100644 --- a/.coveragerc +++ b/.coveragerc @@ -12,3 +12,7 @@ exclude_lines = # Don't complain about debug code if Image.DEBUG: if DEBUG: + +[run] +omit = + Tests/check_*.py From b33df562b8a212bf499ee304efc847bc4d476503 Mon Sep 17 00:00:00 2001 From: Hugo Date: Sun, 27 Oct 2019 18:23:28 +0200 Subject: [PATCH 3/6] Matches 'omit:' from .coveragerc --- .codecov.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.codecov.yml b/.codecov.yml index a93095486..033786a49 100644 --- a/.codecov.yml +++ b/.codecov.yml @@ -9,3 +9,7 @@ codecov: token: 6dafc396-e7f5-4221-a38a-8b07a49fbdae comment: off + +# Matches 'omit:' in .coveragerc +ignore: + - "Tests/check_*.py" From 106fc4085f19c4c40a7c482d5c57a4fb86143e71 Mon Sep 17 00:00:00 2001 From: Hugo Date: Mon, 18 Nov 2019 13:48:37 +0200 Subject: [PATCH 4/6] Remove redundant files --- Tests/bench_get.py | 23 ----------------------- 1 file changed, 23 deletions(-) delete mode 100644 Tests/bench_get.py diff --git a/Tests/bench_get.py b/Tests/bench_get.py deleted file mode 100644 index 8a54ff921..000000000 --- a/Tests/bench_get.py +++ /dev/null @@ -1,23 +0,0 @@ -import sys -import timeit - -from . import helper - -sys.path.insert(0, ".") - - -def bench(mode): - im = helper.hopper(mode) - get = im.im.getpixel - xy = 50, 50 # position shouldn't really matter - t0 = timeit.default_timer() - for _ in range(1000000): - get(xy) - print(mode, timeit.default_timer() - t0, "us") - - -bench("L") -bench("I") -bench("I;16") -bench("F") -bench("RGB") From ebed90c228e4c88b8bf7303a267e2714a5e3cd57 Mon Sep 17 00:00:00 2001 From: Hugo Date: Mon, 2 Dec 2019 15:26:51 +0200 Subject: [PATCH 5/6] Remove redundant files --- Tests/import_all.py | 14 --------- Tests/make_hash.py | 66 ------------------------------------------ Tests/threaded_save.py | 57 ------------------------------------ Tests/versions.py | 26 ----------------- 4 files changed, 163 deletions(-) delete mode 100644 Tests/import_all.py delete mode 100644 Tests/make_hash.py delete mode 100644 Tests/threaded_save.py delete mode 100644 Tests/versions.py diff --git a/Tests/import_all.py b/Tests/import_all.py deleted file mode 100644 index 33b07f9a2..000000000 --- a/Tests/import_all.py +++ /dev/null @@ -1,14 +0,0 @@ -import glob -import os -import sys -import traceback - -sys.path.insert(0, ".") - -for file in glob.glob("src/PIL/*.py"): - module = os.path.basename(file)[:-3] - try: - exec("from PIL import " + module) - except (ImportError, SyntaxError): - print("===", "failed to import", module) - traceback.print_exc() diff --git a/Tests/make_hash.py b/Tests/make_hash.py deleted file mode 100644 index 7199f8c7f..000000000 --- a/Tests/make_hash.py +++ /dev/null @@ -1,66 +0,0 @@ -# brute-force search for access descriptor hash table - -modes = [ - "1", - "L", - "LA", - "La", - "I", - "I;16", - "I;16L", - "I;16B", - "I;32L", - "I;32B", - "F", - "P", - "PA", - "RGB", - "RGBA", - "RGBa", - "RGBX", - "CMYK", - "YCbCr", - "LAB", - "HSV", -] - - -def hash(s, i): - # djb2 hash: multiply by 33 and xor character - for c in s: - i = (((i << 5) + i) ^ ord(c)) & 0xFFFFFFFF - return i - - -def check(size, i0): - h = [None] * size - for m in modes: - i = hash(m, i0) - i = i % size - if h[i]: - return 0 - h[i] = m - return h - - -min_start = 0 - -# 1) find the smallest table size with no collisions -for min_size in range(len(modes), 16384): - if check(min_size, 0): - print(len(modes), "modes fit in", min_size, "slots") - break - -# 2) see if we can do better with a different initial value -for i0 in range(65556): - for size in range(1, min_size): - if check(size, i0): - if size < min_size: - print(len(modes), "modes fit in", size, "slots with start", i0) - min_size = size - min_start = i0 - -print() - -print("#define ACCESS_TABLE_SIZE", min_size) -print("#define ACCESS_TABLE_HASH", min_start) diff --git a/Tests/threaded_save.py b/Tests/threaded_save.py deleted file mode 100644 index d47c2cf99..000000000 --- a/Tests/threaded_save.py +++ /dev/null @@ -1,57 +0,0 @@ -import io -import queue -import sys -import threading -import time - -from PIL import Image - -test_format = sys.argv[1] if len(sys.argv) > 1 else "PNG" - -im = Image.open("Tests/images/hopper.ppm") -im.load() - -queue = queue.Queue() - -result = [] - - -class Worker(threading.Thread): - def run(self): - while True: - im = queue.get() - if im is None: - queue.task_done() - sys.stdout.write("x") - break - f = io.BytesIO() - im.save(f, test_format, optimize=1) - data = f.getvalue() - result.append(len(data)) - im = Image.open(io.BytesIO(data)) - im.load() - sys.stdout.write(".") - queue.task_done() - - -t0 = time.time() - -threads = 20 -jobs = 100 - -for i in range(threads): - w = Worker() - w.start() - -for i in range(jobs): - queue.put(im) - -for i in range(threads): - queue.put(None) - -queue.join() - -print() -print(time.time() - t0) -print(len(result), sum(result)) -print(result) diff --git a/Tests/versions.py b/Tests/versions.py deleted file mode 100644 index d6433b063..000000000 --- a/Tests/versions.py +++ /dev/null @@ -1,26 +0,0 @@ -from PIL import Image - - -def version(module, version): - v = getattr(module.core, version + "_version", None) - if v: - print(version, v) - - -version(Image, "jpeglib") -version(Image, "zlib") -version(Image, "libtiff") - -try: - from PIL import ImageFont -except ImportError: - pass -else: - version(ImageFont, "freetype2") - -try: - from PIL import ImageCms -except ImportError: - pass -else: - version(ImageCms, "littlecms") From ce382e7858c32ef5e336509fd9e2375dc5412a1a Mon Sep 17 00:00:00 2001 From: Hugo Date: Mon, 2 Dec 2019 15:37:20 +0200 Subject: [PATCH 6/6] Omit from coverage --- .codecov.yml | 3 +++ .coveragerc | 3 +++ 2 files changed, 6 insertions(+) diff --git a/.codecov.yml b/.codecov.yml index 033786a49..d348345dc 100644 --- a/.codecov.yml +++ b/.codecov.yml @@ -12,4 +12,7 @@ comment: off # Matches 'omit:' in .coveragerc ignore: + - "Tests/32bit_segfault_check.py" + - "Tests/bench_cffi_access.py" - "Tests/check_*.py" + - "Tests/createfontdatachunk.py" diff --git a/.coveragerc b/.coveragerc index e93a2a426..f1f095806 100644 --- a/.coveragerc +++ b/.coveragerc @@ -15,4 +15,7 @@ exclude_lines = [run] omit = + Tests/32bit_segfault_check.py + Tests/bench_cffi_access.py Tests/check_*.py + Tests/createfontdatachunk.py