From c3a29142b5ec556f71f2d22f6e02751a77ff54bd Mon Sep 17 00:00:00 2001 From: moe-ad Date: Mon, 6 Jan 2025 09:50:19 +0100 Subject: [PATCH 1/7] feat: first commit --- tox.ini | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 tox.ini diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000000..a3b03339b1 --- /dev/null +++ b/tox.ini @@ -0,0 +1,43 @@ +# This is work in progress +# Testing workflow in CI is gradually being transferred to tox + +[tox] +description = Default tox enviroment list and core configurations + +envlist = + +isolated_build_env = build + +[testenv] +description = default configuration for test environments, unless overriden + +pass_env = + PACKAGE_NAME + MODULE + ANSYS_DPF_ACCEPT_LA + ANSYSLMD_LICENSE_FILE + +package = external # To allow custom wheel builds + +[testenv:build_external] +description = Environment for custom build of package wheels, solves PyDPF custom wheel building requirement + +allowlist_externals = + bash + +package_glob = {toxinidir}{/}dist{/}ansys_dpf_core* + +commands = + # Build the wheel + bash -c '\ + if [ {on_platform} == "linux" ]; then \ + export platform="manylinux_2_17"; \ + elif [ {on_platform} == "win32" ]; then \ + export platform="win"; \ + else \ + echo "Unknown OS"; \ + fi; \ + echo $platform; \ + python .ci/build_wheel.py -p $platform -w' + +[testenv:test-{launcher,server,server,multi_server,remote_workflow,remote_operator,workflow,service,operators}] \ No newline at end of file From 5eb81dcb06d49b4da2e6f0545d6b8945a0b613e6 Mon Sep 17 00:00:00 2001 From: moe-ad Date: Mon, 6 Jan 2025 14:32:31 +0100 Subject: [PATCH 2/7] feat: more modification --- tox.ini | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 53 insertions(+), 4 deletions(-) diff --git a/tox.ini b/tox.ini index a3b03339b1..d273931c03 100644 --- a/tox.ini +++ b/tox.ini @@ -2,14 +2,16 @@ # Testing workflow in CI is gradually being transferred to tox [tox] -description = Default tox enviroment list and core configurations +description = Default tox environment list and core configurations -envlist = +# To allow running all tests with a single label, will be handy later on +labels = + test = test-api,test-launcher,test-server,test-local_server,test-multi_server,test-remote_workflow,test-remote_operator,test-workflow,test-service,test-operators isolated_build_env = build [testenv] -description = default configuration for test environments, unless overriden +description = Default configuration for test environments, unless overridden pass_env = PACKAGE_NAME @@ -40,4 +42,51 @@ commands = echo $platform; \ python .ci/build_wheel.py -p $platform -w' -[testenv:test-{launcher,server,server,multi_server,remote_workflow,remote_operator,workflow,service,operators}] \ No newline at end of file +[testenv:runtests] +description = Environment to allow executing some commands before test run, and after test run +# In PyDPF, test files are organized prior to testing. Creating this environment helps to achieve the same effect, ensuring +# test files are organized before running tests and reverted after the tests finish running. + +skip_install = True + +[testenv:test-{api,launcher,server,local_server,multi_server,remote_workflow,remote_operator,workflow,service,operators}] +description = Environment where project testing configuration is defined + +setenv = + # Pytest extra arguments + COVERAGE = --cov=ansys.dpf.core --cov-report=xml --cov-report=html --log-level=ERROR --cov-append + RERUNS = -reruns 2 --reruns-delay 1 + DEBUG = -v -s --durations=10 --durations-min=1.0 + + api: JUNITXML = --junitxml=tests/junit/test-results.xml + launcher: JUNITXML = --junitxml=tests/junit/test-results2.xml + server: JUNITXML = --junitxml=tests/junit/test-results3.xml + local_server: JUNITXML = --junitxml=tests/junit/test-results4.xml + multi_server: JUNITXML = --junitxml=tests/junit/test-results5.xml + remote_workflow: JUNITXML = --junitxml=tests/junit/test-results6.xml + remote_operator: JUNITXML = --junitxml=tests/junit/test-results7.xml + workflow: JUNITXML = test_workflow--junitxml=tests/junit/test-results8.xml + service: JUNITXML = --junitxml=tests/junit/test-results9.xml + operators: JUNITXML = --junitxml=../tests/junit/test-results12.xml + + # Tests sets + api: PYTEST_PYTHON_FILES = tests + launcher: PYTEST_PYTHON_FILES = test_launcher + server: PYTEST_PYTHON_FILES = test_server + local_server: PYTEST_PYTHON_FILES = test_local_server + multi_server: PYTEST_PYTHON_FILES = test_multi_server + remote_workflow: PYTEST_PYTHON_FILES = test_remote_workflow + remote_operator: PYTEST_PYTHON_FILES = test_remote_operator + workflow: PYTEST_PYTHON_FILES = test_workflow + service: PYTEST_PYTHON_FILES = test_service + operators: PYTEST_PYTHON_FILES = tests/operators + +deps = + -r requirements/requirements_test.txt + +commands_pre = + +commands = + pytest {env:DEBUG} {env:COVERAGE} {env:RERUNS} {env:JUNITXML} {env:PYTEST_PYTHON_FILES} + +commands_post = \ No newline at end of file From 78fb2cdec3bb55299d4c86b973a5825dd0dec623 Mon Sep 17 00:00:00 2001 From: moe-ad Date: Tue, 7 Jan 2025 04:19:16 +0100 Subject: [PATCH 3/7] feat: added more config --- tox.ini | 53 +++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 43 insertions(+), 10 deletions(-) diff --git a/tox.ini b/tox.ini index d273931c03..7dfbf8003f 100644 --- a/tox.ini +++ b/tox.ini @@ -4,9 +4,9 @@ [tox] description = Default tox environment list and core configurations -# To allow running all tests with a single label, will be handy later on +# List all tests to run in parallel or sequential mode here labels = - test = test-api,test-launcher,test-server,test-local_server,test-multi_server,test-remote_workflow,test-remote_operator,test-workflow,test-service,test-operators + tests = test-api,test-launcher,test-server,test-local_server,test-multi_server,test-remote_workflow,test-remote_operator,test-workflow,test-service,test-operators isolated_build_env = build @@ -18,6 +18,7 @@ pass_env = MODULE ANSYS_DPF_ACCEPT_LA ANSYSLMD_LICENSE_FILE + AWP_ROOT242 package = external # To allow custom wheel builds @@ -42,20 +43,56 @@ commands = echo $platform; \ python .ci/build_wheel.py -p $platform -w' -[testenv:runtests] +[testenv:runtests-{sequential,parallel}] description = Environment to allow executing some commands before test run, and after test run -# In PyDPF, test files are organized prior to testing. Creating this environment helps to achieve the same effect, ensuring +# In PyDPF, test files are organized prior to testing. This environment helps to achieve the same effect, ensuring # test files are organized before running tests and reverted after the tests finish running. +# Servers can always be killed before test runs to ensure a clean state. skip_install = True +allowlist_externals = + tox + +deps = + psutil + +commands_pre = + # Clear any running servers that may be locking resources + python -c "import psutil; proc_name = 'Ans.Dpf.Grpc'; nb_procs = len([proc.kill() for proc in psutil.process_iter() if proc_name in proc.name()]); \ + print(f'Killed \{nb_procs} \{proc_name} processes.')" + + # Organize test files + python -c "\ + import os, shutil; \ + test_data=['test_launcher','test_server','test_local_server','test_multi_server','test_workflow','test_remote_workflow','test_remote_operator','test_service','test_custom_type_field']; \ + [(os.makedirs(d, exist_ok=True), shutil.copy('tests/conftest.py', d), shutil.copy(f'tests/\{d}.py', d) if os.path.exists(f'tests/\{d}.py') else None) for d in test_data]; \ + [os.remove(f'tests/\{d}.py') for d in test_data if os.path.exists(f'tests/\{d}.py')]" + +# Run tests +commands = + sequential: tox -m tests + parallel: tox --parallel -m tests + +commands_post = + # Revert project layout to previous state + python -c "\ + import os, shutil; \ + test_data=['test_launcher','test_server','test_local_server','test_multi_server','test_workflow','test_remote_workflow','test_remote_operator','test_service', 'test_custom_type_field']; \ + [shutil.move(f'\{d}/\{d}.py', f'tests/\{d}.py') for d in test_data if os.path.exists(f'\{d}/\{d}.py')]; \ + [shutil.rmtree(d) for d in test_data if os.path.exists(d)]" + + # Clear any running servers that may be locking resources + python -c "import psutil; proc_name = 'Ans.Dpf.Grpc'; nb_procs = len([proc.kill() for proc in psutil.process_iter() if proc_name in proc.name()]); \ + print(f'Killed \{nb_procs} \{proc_name} processes.')" + [testenv:test-{api,launcher,server,local_server,multi_server,remote_workflow,remote_operator,workflow,service,operators}] description = Environment where project testing configuration is defined setenv = # Pytest extra arguments COVERAGE = --cov=ansys.dpf.core --cov-report=xml --cov-report=html --log-level=ERROR --cov-append - RERUNS = -reruns 2 --reruns-delay 1 + RERUNS = -reruns=2 --reruns-delay=1 DEBUG = -v -s --durations=10 --durations-min=1.0 api: JUNITXML = --junitxml=tests/junit/test-results.xml @@ -84,9 +121,5 @@ setenv = deps = -r requirements/requirements_test.txt -commands_pre = - commands = - pytest {env:DEBUG} {env:COVERAGE} {env:RERUNS} {env:JUNITXML} {env:PYTEST_PYTHON_FILES} - -commands_post = \ No newline at end of file + pytest {env:PYTEST_PYTHON_FILES} {env:DEBUG} {env:COVERAGE} {env:RERUNS} {env:JUNITXML} \ No newline at end of file From ca395971de91a64efb1677bd97656276a0c81297 Mon Sep 17 00:00:00 2001 From: moe-ad Date: Wed, 8 Jan 2025 04:09:08 +0100 Subject: [PATCH 4/7] feat: fixed some mistakes --- tox.ini | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tox.ini b/tox.ini index 7dfbf8003f..d44ab57225 100644 --- a/tox.ini +++ b/tox.ini @@ -92,7 +92,7 @@ description = Environment where project testing configuration is defined setenv = # Pytest extra arguments COVERAGE = --cov=ansys.dpf.core --cov-report=xml --cov-report=html --log-level=ERROR --cov-append - RERUNS = -reruns=2 --reruns-delay=1 + RERUNS = --reruns=2 --reruns-delay=1 DEBUG = -v -s --durations=10 --durations-min=1.0 api: JUNITXML = --junitxml=tests/junit/test-results.xml @@ -102,7 +102,7 @@ setenv = multi_server: JUNITXML = --junitxml=tests/junit/test-results5.xml remote_workflow: JUNITXML = --junitxml=tests/junit/test-results6.xml remote_operator: JUNITXML = --junitxml=tests/junit/test-results7.xml - workflow: JUNITXML = test_workflow--junitxml=tests/junit/test-results8.xml + workflow: JUNITXML = --junitxml=tests/junit/test-results8.xml service: JUNITXML = --junitxml=tests/junit/test-results9.xml operators: JUNITXML = --junitxml=../tests/junit/test-results12.xml From 71568c539c005a0f9391165eca7e3cedce5615a7 Mon Sep 17 00:00:00 2001 From: moe-ad Date: Wed, 8 Jan 2025 05:30:52 +0100 Subject: [PATCH 5/7] feat: overhauled initial configuration --- tox.ini | 45 +++++++++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/tox.ini b/tox.ini index d44ab57225..702390bdc9 100644 --- a/tox.ini +++ b/tox.ini @@ -1,12 +1,16 @@ -# This is work in progress -# Testing workflow in CI is gradually being transferred to tox +# This is work in progress, testing workflow in local/CI is gradually being transferred to tox + +# Usage instructions: +# `tox` will run all tests sequentially, `tox --parallel` will run all tests in parallel (much faster). +# Run specific selection of tests with `tox -e pretest,,posttest` e.g., `tox -e pretest,test-api,test-launcher,posttest` +# `--parallel` flag can be passed when running specific selections [tox] description = Default tox environment list and core configurations # List all tests to run in parallel or sequential mode here -labels = - tests = test-api,test-launcher,test-server,test-local_server,test-multi_server,test-remote_workflow,test-remote_operator,test-workflow,test-service,test-operators +# So invocation can be specified as `tox`/`tox --parallel` to run all tests in sequential/parallel mode +envlist = pretest,test-{api,launcher,server,local_server,multi_server,remote_workflow,remote_operator,workflow,service,operators},posttest isolated_build_env = build @@ -43,21 +47,15 @@ commands = echo $platform; \ python .ci/build_wheel.py -p $platform -w' -[testenv:runtests-{sequential,parallel}] -description = Environment to allow executing some commands before test run, and after test run -# In PyDPF, test files are organized prior to testing. This environment helps to achieve the same effect, ensuring -# test files are organized before running tests and reverted after the tests finish running. -# Servers can always be killed before test runs to ensure a clean state. - -skip_install = True - -allowlist_externals = - tox +[testenv:pretest] +description = Environment to kill servers and organize test files prior to testing deps = psutil -commands_pre = +skip_install = True + +commands = # Clear any running servers that may be locking resources python -c "import psutil; proc_name = 'Ans.Dpf.Grpc'; nb_procs = len([proc.kill() for proc in psutil.process_iter() if proc_name in proc.name()]); \ print(f'Killed \{nb_procs} \{proc_name} processes.')" @@ -69,12 +67,17 @@ commands_pre = [(os.makedirs(d, exist_ok=True), shutil.copy('tests/conftest.py', d), shutil.copy(f'tests/\{d}.py', d) if os.path.exists(f'tests/\{d}.py') else None) for d in test_data]; \ [os.remove(f'tests/\{d}.py') for d in test_data if os.path.exists(f'tests/\{d}.py')]" -# Run tests -commands = - sequential: tox -m tests - parallel: tox --parallel -m tests +[testenv:posttest] +description = Environment to kill servers and revert test files to original state after testing -commands_post = +depends = pretest, test-{api,launcher,server,local_server,multi_server,remote_workflow,remote_operator,workflow,service,operators} + +deps = + psutil + +skip_install = True + +commands = # Revert project layout to previous state python -c "\ import os, shutil; \ @@ -89,6 +92,8 @@ commands_post = [testenv:test-{api,launcher,server,local_server,multi_server,remote_workflow,remote_operator,workflow,service,operators}] description = Environment where project testing configuration is defined +depends = pretest + setenv = # Pytest extra arguments COVERAGE = --cov=ansys.dpf.core --cov-report=xml --cov-report=html --log-level=ERROR --cov-append From 44a48dd3889ae3865e23900752b0a712d057ca90 Mon Sep 17 00:00:00 2001 From: moe-ad Date: Wed, 8 Jan 2025 12:57:30 +0100 Subject: [PATCH 6/7] feat: cross-platform detection logic --- .ci/build_wheel.py | 3 +++ tox.ini | 13 ++----------- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/.ci/build_wheel.py b/.ci/build_wheel.py index 6acac20032..260c796c1e 100644 --- a/.ci/build_wheel.py +++ b/.ci/build_wheel.py @@ -15,6 +15,9 @@ "win": "win_amd64", "manylinux1": "manylinux1_x86_64", "manylinux_2_17": "manylinux_2_17_x86_64", + "linux": "manylinux_2_17_x86_64", # Accommodate tox.ini platform substitutions + "win32": "win_amd64", + "darwin": "any", } argParser = argparse.ArgumentParser() diff --git a/tox.ini b/tox.ini index 702390bdc9..83dd0f88e4 100644 --- a/tox.ini +++ b/tox.ini @@ -34,18 +34,9 @@ allowlist_externals = package_glob = {toxinidir}{/}dist{/}ansys_dpf_core* +# {on_platform} substitution to automatically detect os type. commands = - # Build the wheel - bash -c '\ - if [ {on_platform} == "linux" ]; then \ - export platform="manylinux_2_17"; \ - elif [ {on_platform} == "win32" ]; then \ - export platform="win"; \ - else \ - echo "Unknown OS"; \ - fi; \ - echo $platform; \ - python .ci/build_wheel.py -p $platform -w' + python .ci/build_wheel.py -p {on_platform} -w [testenv:pretest] description = Environment to kill servers and organize test files prior to testing From cf74a02ea6637cbed2186881324f7b3bd590930b Mon Sep 17 00:00:00 2001 From: moe-ad Date: Wed, 8 Jan 2025 14:31:44 +0100 Subject: [PATCH 7/7] feat: removed allowlist_externals --- tox.ini | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/tox.ini b/tox.ini index 83dd0f88e4..697a6eab17 100644 --- a/tox.ini +++ b/tox.ini @@ -3,7 +3,7 @@ # Usage instructions: # `tox` will run all tests sequentially, `tox --parallel` will run all tests in parallel (much faster). # Run specific selection of tests with `tox -e pretest,,posttest` e.g., `tox -e pretest,test-api,test-launcher,posttest` -# `--parallel` flag can be passed when running specific selections +# `--parallel` flag can be passed when running specific selections. [tox] description = Default tox environment list and core configurations @@ -29,9 +29,6 @@ package = external # To allow custom wheel builds [testenv:build_external] description = Environment for custom build of package wheels, solves PyDPF custom wheel building requirement -allowlist_externals = - bash - package_glob = {toxinidir}{/}dist{/}ansys_dpf_core* # {on_platform} substitution to automatically detect os type.