Skip to content

Commit 0c042d9

Browse files
committed
Convert test_codecs.py to pytest
Now used as test-command for cibuildwheel
1 parent 83e3abb commit 0c042d9

3 files changed

Lines changed: 18 additions & 22 deletions

File tree

python_bindings/MANIFEST.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ include pyfastpfor.cc
22
include pyproject.toml
33
recursive-include ./fastpfor/src *.cpp *.c
44
recursive-include ./fastpfor/headers *.h
5+
recursive-include tests *.py
56
include requirements.txt
67

78
global-exclude fastpfor/src/benchbitpacking.cpp

python_bindings/pyproject.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,9 @@ build-frontend = "build"
5151
# Published wheels must run on any CPU of the target architecture, so build with
5252
# a portable SIMD baseline rather than -march=native (see setup.py:simd_flags).
5353
environment = { PYFASTPFOR_PORTABLE = "1" }
54-
# Smoke-test every built wheel: import it and exercise the codec factory.
55-
test-command = 'python -c "import pyfastpfor; assert pyfastpfor.getCodecList(); print(pyfastpfor.__version__, len(pyfastpfor.getCodecList()), \"codecs\")"'
54+
# Test every built wheel: round-trip every codec (see tests/test_codecs.py).
55+
test-requires = "pytest"
56+
test-command = "pytest {package}/tests -v"
5657

5758
[tool.cibuildwheel.linux]
5859
archs = ["native"]

python_bindings/tests/test_codecs.py

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,22 @@
22

33
from pyfastpfor import *
44
import numpy as np
5+
import pytest
56
import random
67
import time
78
random.seed(0)
89

10+
# Be careful changing these numbers: If the array size
11+
# is too large there will be an integer overflow.
12+
ARRAY_SIZES = [1, 8, 64, 1024, 1024 * 1024 * 4]
13+
MAX_VALUES = [256, 512, 2048]
14+
15+
16+
@pytest.mark.parametrize("maxVal", MAX_VALUES)
17+
@pytest.mark.parametrize("arrSize", ARRAY_SIZES)
18+
def test_codecs_roundtrip(arrSize, maxVal):
19+
codecList = getCodecList()
920

10-
def oneTest(arrSize, maxVal, codecList):
1121
inpSmall = np.array(np.random.randint(
1222
0, maxVal, arrSize), dtype=np.uint32).ravel()
1323
inpPrefSum = np.array(inpSmall, dtype=np.uint32, copy=True).ravel()
@@ -38,9 +48,9 @@ def oneTest(arrSize, maxVal, codecList):
3848
for diffType in range(3):
3949

4050
if diffType == 0:
41-
inp = np.array([e for e in inpSmall], dtype=np.uint32).ravel()
51+
inp = np.array(inpSmall, dtype=np.uint32, copy=True).ravel()
4252
else:
43-
inp = np.array([e for e in inpPrefSum], dtype=np.uint32).ravel()
53+
inp = np.array(inpPrefSum, dtype=np.uint32, copy=True).ravel()
4454

4555
if diffType == 1:
4656
delta1(inp, arrSize)
@@ -77,20 +87,4 @@ def oneTest(arrSize, maxVal, codecList):
7787

7888

7989
if __name__ == '__main__':
80-
81-
codecList = getCodecList()
82-
83-
# Be careful changing these numbers: If the array size
84-
# is too large there will be an integer overflow.
85-
arraySizes = [1, 8, 64, 1024, 1024 * 1024 * 4]
86-
maxValues = [256, 512, 2048]
87-
88-
i = 0
89-
for arraySize in arraySizes:
90-
for maxValue in maxValues:
91-
print("--------------------------------------------------------------------------------")
92-
print(" Test Case %d/%d" % (i, len(arraySizes)*len(maxValues)))
93-
print("--------------------------------------------------------------------------------")
94-
oneTest(arraySize, maxValue, codecList)
95-
print("\n")
96-
i += 1
90+
raise SystemExit(pytest.main([__file__, "-v"]))

0 commit comments

Comments
 (0)