Skip to content

Commit 615e7e7

Browse files
authored
Merge pull request #2298 from Shaikh-Ubaid/ci_python_3_9
CI: Test integration_tests with Python 3.9, 3.10 and 3.11
2 parents c8b1ba9 + c5ef1af commit 615e7e7

File tree

5 files changed

+111
-80
lines changed

5 files changed

+111
-80
lines changed

.github/workflows/CI.yml

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -445,9 +445,13 @@ jobs:
445445
./run_tests.py -b c_sym cpython_sym llvm_sym
446446
./run_tests.py -b c_sym cpython_sym llvm_sym -f
447447
448-
python_3_11:
449-
name: Run Integration tests with Python 3.11
448+
integration_tests_cpython:
449+
name: Run Integration tests with Python ${{ matrix.python-version }}
450450
runs-on: ubuntu-latest
451+
strategy:
452+
fail-fast: false
453+
matrix:
454+
python-version: ["3.9", "3.10", "3.11"]
451455
steps:
452456
- uses: actions/checkout@v3
453457
with:
@@ -466,16 +470,20 @@ jobs:
466470
zlib
467471
cmake
468472
make
469-
python=3.11.4
473+
python=${{ matrix.python-version }}
470474
numpy
471475
472476
- uses: hendrikmuhs/ccache-action@main
473477
with:
474-
key: ${{ github.job }}-${{ matrix.os }}
478+
key: ${{ github.job }}-${{ matrix.python-version }}
475479

476-
- name: Show Python version
480+
- name: Show Python Info
477481
shell: bash -e -l {0}
478-
run: python --version
482+
run: |
483+
which python
484+
python -m pip -V
485+
python -m pip list
486+
python --version
479487
480488
- name: Build
481489
shell: bash -e -l {0}
@@ -498,4 +506,4 @@ jobs:
498506
shell: bash -e -l {0}
499507
run: |
500508
cd integration_tests
501-
./run_tests.py -b cpython
509+
./run_tests.py -b cpython c_py

integration_tests/CMakeLists.txt

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ endmacro(RUN_UTIL)
312312

313313
macro(RUN)
314314
set(options FAIL NOFAST NOMOD ENABLE_CPYTHON LINK_NUMPY)
315-
set(oneValueArgs NAME IMPORT_PATH COPY_TO_BIN)
315+
set(oneValueArgs NAME IMPORT_PATH COPY_TO_BIN REQ_PY_VER)
316316
set(multiValueArgs LABELS EXTRAFILES)
317317
cmake_parse_arguments(RUN "${options}" "${oneValueArgs}"
318318
"${multiValueArgs}" ${ARGN} )
@@ -334,6 +334,18 @@ macro(RUN)
334334
set(RUN_EXTRA_ARGS ${RUN_EXTRA_ARGS} -I${CMAKE_CURRENT_SOURCE_DIR}/${RUN_IMPORT_PATH})
335335
endif()
336336

337+
if (RUN_REQ_PY_VER)
338+
string(REGEX REPLACE "([0-9]+)\\.([0-9]+)\\.([0-9]+)" "\\1" PY_MAJOR_VERSION "${Python_VERSION}")
339+
string(REGEX REPLACE "([0-9]+)\\.([0-9]+)\\.([0-9]+)" "\\2" PY_MINOR_VERSION "${Python_VERSION}")
340+
string(REGEX REPLACE "([0-9]+)\\.([0-9]+)" "\\1" REQ_PY_MAJOR_VERSION "${RUN_REQ_PY_VER}")
341+
string(REGEX REPLACE "([0-9]+)\\.([0-9]+)" "\\2" REQ_PY_MINOR_VERSION "${RUN_REQ_PY_VER}")
342+
343+
if (PY_MINOR_VERSION LESS REQ_PY_MINOR_VERSION)
344+
# remove backends from the test that depend on CPython
345+
list(REMOVE_ITEM RUN_LABELS cpython cpython_sym c_py c_sym llvm_sym llvm_py)
346+
endif()
347+
endif()
348+
337349
if (NOT FAST)
338350
RUN_UTIL(RUN_FAIL RUN_NAME RUN_FILE_NAME RUN_LABELS RUN_EXTRAFILES RUN_NOMOD RUN_EXTRA_ARGS RUN_COPY_TO_BIN)
339351
endif()
@@ -623,7 +635,7 @@ RUN(NAME bindpy_01 LABELS cpython c_py ENABLE_CPYTHON NOFAST COPY_TO_B
623635
RUN(NAME bindpy_02 LABELS cpython c_py LINK_NUMPY COPY_TO_BIN bindpy_02_module.py)
624636
RUN(NAME bindpy_03 LABELS cpython c_py LINK_NUMPY NOFAST COPY_TO_BIN bindpy_03_module.py)
625637
RUN(NAME bindpy_04 LABELS cpython c_py LINK_NUMPY NOFAST COPY_TO_BIN bindpy_04_module.py)
626-
RUN(NAME bindpy_05 LABELS llvm_py c_py ENABLE_CPYTHON COPY_TO_BIN bindpy_05_module.py)
638+
RUN(NAME bindpy_05 LABELS llvm_py c_py ENABLE_CPYTHON COPY_TO_BIN bindpy_05_module.py REQ_PY_VER 3.10)
627639
RUN(NAME test_generics_01 LABELS cpython llvm c NOFAST)
628640
RUN(NAME test_cmath LABELS cpython llvm c NOFAST)
629641
RUN(NAME test_complex_01 LABELS cpython llvm c wasm wasm_x64)
@@ -741,7 +753,8 @@ RUN(NAME generics_array_01 LABELS cpython llvm c)
741753
RUN(NAME generics_array_02 LABELS cpython llvm c)
742754
RUN(NAME generics_array_03 LABELS cpython llvm c)
743755
RUN(NAME generics_list_01 LABELS cpython llvm c)
744-
RUN(NAME test_statistics LABELS cpython llvm NOFAST)
756+
RUN(NAME test_statistics_01 LABELS cpython llvm NOFAST)
757+
RUN(NAME test_statistics_02 LABELS cpython llvm NOFAST REQ_PY_VER 3.10)
745758
RUN(NAME test_str_attributes LABELS cpython llvm c)
746759
RUN(NAME kwargs_01 LABELS cpython llvm c NOFAST)
747760

integration_tests/run_tests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def main():
6262
DEFAULT_THREADS_TO_USE = args.no_of_threads or DEFAULT_THREADS_TO_USE
6363
fast_tests = "yes" if args.fast else "no"
6464
for backend in args.backends:
65-
python_libs_req = "yes" if backend in ["c_py", "c_sym", "llvm_sym", 'llvm_py'] else "no"
65+
python_libs_req = "yes" if backend in ["cpython", "c_py", "c_sym", "llvm_sym", 'llvm_py'] else "no"
6666
test_backend(backend)
6767

6868

integration_tests/test_statistics.py renamed to integration_tests/test_statistics_01.py

Lines changed: 2 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from statistics import (mean, fmean, geometric_mean, harmonic_mean, variance,
2-
stdev, pvariance, pstdev, correlation, covariance,
3-
linear_regression, mode)
4-
from lpython import i32, f64, i64, f32
2+
stdev, pvariance, pstdev, mode)
3+
from lpython import i32, f64, i64
54

65

76
eps: f64
@@ -126,69 +125,6 @@ def test_pstdev():
126125
k = pstdev(b)
127126
assert abs(k - 0.37537181567080935) < eps
128127

129-
130-
def test_covariance():
131-
a: list[i32]
132-
a = [1, 2, 3, 4, 5, 6, 7, 8, 9]
133-
b: list[i32]
134-
b = [1, 2, 3, 1, 2, 3, 1, 2, 3]
135-
j: f64
136-
j = covariance(a, b)
137-
assert abs(j - 0.75) < eps
138-
139-
c: list[f64]
140-
c = [2.74, 1.23, 2.63, 2.22, 3.0, 1.98]
141-
d: list[f64]
142-
d = [9.4, 1.23, 2.63, 22.4, 1.9, 13.98]
143-
k: f64
144-
k = covariance(c, d)
145-
assert abs(k + 0.24955999999999934) < eps
146-
147-
148-
def test_correlation():
149-
a: list[i32]
150-
a = [11, 2, 7, 4, 15, 6, 10, 8, 9, 1, 11, 5, 13, 6, 15]
151-
b: list[i32]
152-
b = [2, 5, 17, 6, 10, 8, 13, 4, 6, 9, 11, 2, 5, 4, 7]
153-
154-
j: f64
155-
j = correlation(a, b)
156-
assert abs(j - 0.11521487988958108) < eps
157-
158-
c: list[f64]
159-
c = [2.0, 23.0, 24.55, 64.436, 5403.23]
160-
d: list[f64]
161-
d = [26.9, 75.6, 34.06, 356.89, 759.26]
162-
163-
j = correlation(c, c)
164-
assert abs(j - 1.0) < eps
165-
166-
j = correlation(c, d)
167-
assert abs(j - 0.9057925526720572) < eps
168-
169-
def test_linear_regression():
170-
c: list[f64]
171-
c = [2.74, 1.23, 2.63, 2.22, 3.0, 1.98]
172-
d: list[f64]
173-
d = [9.4, 1.23, 2.63, 22.4, 1.9, 13.98]
174-
175-
slope: f64
176-
intercept: f64
177-
slope, intercept = linear_regression(c, d)
178-
179-
assert abs(slope + 0.6098133124816717) < eps
180-
assert abs(intercept - 9.992570618707845) < eps
181-
182-
a: list[i32]
183-
b: list[i32]
184-
a = [12, 24, 2, 1, 43, 53, 23]
185-
b = [2, 13, 14, 63, 49, 7, 3]
186-
187-
slope, intercept = linear_regression(a, b)
188-
189-
assert abs(slope + 0.18514007308160782) < eps
190-
assert abs(intercept - 25.750304506699152) < eps
191-
192128
def test_mode():
193129
a: list[i32]
194130
a = [3, 1, 12, 4, 0]
@@ -228,9 +164,6 @@ def check():
228164
test_stdev()
229165
test_pvariance()
230166
test_pstdev()
231-
test_linear_regression()
232-
test_correlation()
233-
test_covariance()
234167
test_mode()
235168

236169
check()
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
from statistics import (covariance, correlation,
2+
linear_regression)
3+
from lpython import i32, f64
4+
5+
6+
eps: f64
7+
eps = 1e-12
8+
9+
def test_covariance():
10+
a: list[i32]
11+
a = [1, 2, 3, 4, 5, 6, 7, 8, 9]
12+
b: list[i32]
13+
b = [1, 2, 3, 1, 2, 3, 1, 2, 3]
14+
j: f64
15+
j = covariance(a, b)
16+
assert abs(j - 0.75) < eps
17+
18+
c: list[f64]
19+
c = [2.74, 1.23, 2.63, 2.22, 3.0, 1.98]
20+
d: list[f64]
21+
d = [9.4, 1.23, 2.63, 22.4, 1.9, 13.98]
22+
k: f64
23+
k = covariance(c, d)
24+
assert abs(k + 0.24955999999999934) < eps
25+
26+
27+
def test_correlation():
28+
a: list[i32]
29+
a = [11, 2, 7, 4, 15, 6, 10, 8, 9, 1, 11, 5, 13, 6, 15]
30+
b: list[i32]
31+
b = [2, 5, 17, 6, 10, 8, 13, 4, 6, 9, 11, 2, 5, 4, 7]
32+
33+
j: f64
34+
j = correlation(a, b)
35+
assert abs(j - 0.11521487988958108) < eps
36+
37+
c: list[f64]
38+
c = [2.0, 23.0, 24.55, 64.436, 5403.23]
39+
d: list[f64]
40+
d = [26.9, 75.6, 34.06, 356.89, 759.26]
41+
42+
j = correlation(c, c)
43+
assert abs(j - 1.0) < eps
44+
45+
j = correlation(c, d)
46+
assert abs(j - 0.9057925526720572) < eps
47+
48+
def test_linear_regression():
49+
c: list[f64]
50+
c = [2.74, 1.23, 2.63, 2.22, 3.0, 1.98]
51+
d: list[f64]
52+
d = [9.4, 1.23, 2.63, 22.4, 1.9, 13.98]
53+
54+
slope: f64
55+
intercept: f64
56+
slope, intercept = linear_regression(c, d)
57+
58+
assert abs(slope + 0.6098133124816717) < eps
59+
assert abs(intercept - 9.992570618707845) < eps
60+
61+
a: list[i32]
62+
b: list[i32]
63+
a = [12, 24, 2, 1, 43, 53, 23]
64+
b = [2, 13, 14, 63, 49, 7, 3]
65+
66+
slope, intercept = linear_regression(a, b)
67+
68+
assert abs(slope + 0.18514007308160782) < eps
69+
assert abs(intercept - 25.750304506699152) < eps
70+
71+
72+
def check():
73+
test_linear_regression()
74+
test_correlation()
75+
test_covariance()
76+
77+
check()

0 commit comments

Comments
 (0)