Skip to content

Commit 2d9946b

Browse files
Merge pull request #364 from KhiopsML/run-runner-init-test-in-conda-ci
Run runner initialization test in conda CI
2 parents 7cf8c15 + b2bf3b8 commit 2d9946b

File tree

4 files changed

+62
-50
lines changed

4 files changed

+62
-50
lines changed

.github/workflows/conda.yml

Lines changed: 46 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ jobs:
117117
PATH=$(echo $PATH | sed "s#$CONDA_PREFIX/bin:##g")
118118
119119
# Unset *CONDA* environment variables
120-
# As a corrolary, CONDA_PREFIX is unset
120+
# As a corollary, CONDA_PREFIX is unset
121121
# Note: There is no way to remove these variables from GITHUB_ENV
122122
# (see https://github.com/actions/runner/issues/1126)
123123
for CONDA_VAR in $(env | grep CONDA)
@@ -131,17 +131,17 @@ jobs:
131131
run: |
132132
kh-download-datasets \
133133
--version ${{ inputs.khiops-samples-version || env.DEFAULT_SAMPLES_VERSION }}
134-
- name: Test Conda Package on Samples
134+
- name: Run Samples
135135
env:
136136
# Force > 2 CPU cores to launch mpiexec
137137
KHIOPS_PROC_NUMBER: 4
138138
run: |
139-
kh-samples core -i train_predictor -e
139+
kh-samples core -i deploy_model -e
140+
kh-samples core -i deploy_coclustering -e
140141
kh-samples core -i train_predictor_error_handling -e
141-
kh-samples core -i train_coclustering -e
142142
kh-samples sklearn -i khiops_classifier -e
143143
kh-samples sklearn -i khiops_coclustering -e
144-
- name: Test Conda Package on Some Samples (Conda-Based Environments)
144+
- name: Run Samples (Conda-Based Environments)
145145
env:
146146
# Force > 2 CPU cores to launch mpiexec
147147
KHIOPS_PROC_NUMBER: 4
@@ -153,18 +153,57 @@ jobs:
153153
PATH=$(echo $PATH | sed "s#$CONDA_PREFIX/bin:##g")
154154
155155
# Unset *CONDA* environment variables
156-
# As a corrolary, CONDA_PREFIX is unset
156+
# As a corollary, CONDA_PREFIX is unset
157157
# Note: There is no way to remove these variables from GITHUB_ENV
158158
# (see https://github.com/actions/runner/issues/1126)
159159
for CONDA_VAR in $(env | grep CONDA)
160160
do
161161
unset $(echo $CONDA_VAR | cut -d '=' -f 1)
162162
done
163163
164-
# Execute some Khiops and Khiops Coclustering samples
164+
# Run samples
165165
# Note: kh-samples is not reachable as it is not in PATH
166166
$PYTHON -m khiops.samples.samples -i deploy_model -e
167167
$PYTHON -m khiops.samples.samples -i deploy_coclustering -e
168+
$PYTHON -m khiops.samples.samples -i train_predictor_error_handling -e
169+
$PYTHON -m khiops.samples.samples_sklearn -i khiops_classifier -e
170+
$PYTHON -m khiops.samples.samples_sklearn -i khiops_coclustering -e
171+
# Checkout the sources to obtain the tests
172+
# Note: The `sparse-checkout` option of this action is bugged so we checkout all the sources
173+
# See https://github.com/actions/checkout/issues/1628
174+
- name: Checkout Sources
175+
uses: actions/checkout@v4
176+
with:
177+
fetch-depth: 1
178+
# This is needed so python does not retrieve the khiops module from PWD
179+
- name: Remove the khiops Module from the Sources
180+
run: rm -rf khiops
181+
- name: Install the Test Requirements
182+
run: conda install -y --file test-requirements.txt
183+
- name: Run the Runner Initialization Integration Test
184+
run: |
185+
python -m unittest -v \
186+
tests.test_khiops_integrations.KhiopsRunnerEnvironmentTests.test_runner_environment_initialization
187+
- name: Run the Runner Initialization Integration Test (Conda-Based Environments)
188+
run: |
189+
# Set `python` to the current Conda Python executable
190+
PYTHON="$(type -P python)"
191+
192+
# Remove $CONDA_PREFIX/bin from PATH
193+
PATH=$(echo $PATH | sed "s#$CONDA_PREFIX/bin:##g")
194+
195+
# Unset *CONDA* environment variables
196+
# As a corolary, CONDA_PREFIX is unset
197+
# Note: There is no way to remove these variables from GITHUB_ENV
198+
# (see https://github.com/actions/runner/issues/1126)
199+
for CONDA_VAR in $(env | grep CONDA)
200+
do
201+
unset $(echo $CONDA_VAR | cut -d '=' -f 1)
202+
done
203+
204+
# Execute the runner initialization integration test
205+
$PYTHON -m unittest -v \
206+
tests.test_khiops_integrations.KhiopsRunnerEnvironmentTests.test_runner_environment_initialization
168207
169208
# Release is only executed on tags
170209
# Note: For this job to work the secrets variables KHIOPS_ANACONDA_CHANNEL_TOKEN and

.github/workflows/tests.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,9 @@ jobs:
109109
$CONDA install -y -n "$CONDA_ENV" `grep -v "^\[" khiops.egg-info/requires.txt`
110110
rm -rf khiops.egg-info
111111
done
112-
- name: Prepare Tests Environment
113-
if: github.ref != 'dev' && github.rev != 'dev-v10' && github.ref != 'main' && ! inputs.run-expensive-tests
112+
- name: Configure Expensive Tests Setting
113+
# Skip expensive tests by default, unless on the `dev`, `dev-v10` or `main` branches
114+
if: github.ref != 'dev' && github.ref != 'dev-v10' && github.ref != 'main' && ! inputs.run-expensive-tests
114115
run: echo "SKIP_EXPENSIVE_TESTS=true" >> "$GITHUB_ENV"
115116
- name: Prepare Integration Tests on remote files
116117
env:

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ tests/resources/scenario_generation/api/*/output
4848
tests/resources/scenario_generation/general_options/output
4949
tests/resources/scenario_generation/runner_version/output
5050
tests/resources/*/copy_output_kdic
51+
tests/resources/scenario_generation/system_settings/output
5152

5253
# File generated by documentation scripts/notebooks
5354
kh_samples

tests/test_khiops_integrations.py

Lines changed: 12 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -167,42 +167,14 @@ def test_environment_error_on_bogus_khiops_env_script(self):
167167
output_msg = str(context.exception)
168168
self.assertEqual(output_msg, expected_msg)
169169

170-
def test_runner_with_conda_based_environment(self):
171-
"""Test that local runner works in non-Conda, Conda-based environments"""
172-
173-
# Emulate Conda-based environment:
174-
# - remove $CONDA_PREFIX/bin from $PATH
175-
# - unset `CONDA_PREFIX`
176-
# - create new KhiopsLocalRunner and initialize its Khiops binary
177-
# directory
178-
# - check that the Khiops binary directory contains the MODL* binaries
179-
# and `mpiexec` (which should be its default location)
180-
conda_prefix = None
181-
if "CONDA_PREFIX" in os.environ:
182-
# Remove `CONDA_PREFIX/bin` from `PATH`
183-
conda_prefix_bin = os.path.join(os.environ["CONDA_PREFIX"], "bin")
184-
os.environ["PATH"] = os.pathsep.join(
185-
path_fragment
186-
for path_fragment in os.environ["PATH"].split(os.pathsep)
187-
if path_fragment != conda_prefix_bin
188-
)
189-
190-
# Store existing CONDA_PREFIX
191-
conda_prefix = os.environ["CONDA_PREFIX"]
192-
193-
# Unset `CONDA_PREFIX`
194-
del os.environ["CONDA_PREFIX"]
195-
196-
# Create a fresh local runner
197-
runner = KhiopsLocalRunner()
198-
199-
# Restore CONDA_PREFIX
200-
if conda_prefix is not None:
201-
os.environ["CONDA_PREFIX"] = conda_prefix
170+
def test_runner_environment_initialization(self):
171+
"""Test that local runner initializes/ed its environment properly
202172
203-
# Restore `CONDA_PREFIX/bin` into `PATH`
204-
conda_prefix_bin = os.path.join(conda_prefix, "bin")
205-
os.environ["PATH"] = os.pathsep.join([conda_prefix_bin, os.environ["PATH"]])
173+
.. note::
174+
To test a real initialization this test should be executed alone.
175+
"""
176+
# Obtain the current runner
177+
runner = kh.get_runner()
206178

207179
# Check that MODL* files as set in the runner exist and are executable
208180
self.assertTrue(os.path.isfile(runner.khiops_path))
@@ -211,12 +183,11 @@ def test_runner_with_conda_based_environment(self):
211183
self.assertTrue(os.access(runner.khiops_coclustering_path, os.X_OK))
212184

213185
# Check that mpiexec is set correctly in the runner:
214-
mpi_command_args = runner.mpi_command_args
215-
self.assertTrue(len(mpi_command_args) > 0)
216-
mpiexec_path = runner.mpi_command_args[0]
217-
self.assertTrue(os.path.exists(mpiexec_path))
218-
self.assertTrue(os.path.isfile(mpiexec_path))
219-
self.assertTrue(os.access(mpiexec_path, os.X_OK))
186+
if runner.mpi_command_args:
187+
mpiexec_path = runner.mpi_command_args[0]
188+
self.assertTrue(os.path.exists(mpiexec_path))
189+
self.assertTrue(os.path.isfile(mpiexec_path))
190+
self.assertTrue(os.access(mpiexec_path, os.X_OK))
220191

221192

222193
class KhiopsMultitableFitTests(unittest.TestCase):

0 commit comments

Comments
 (0)