|
4 | 4 | # which is available at https://spdx.org/licenses/BSD-3-Clause-Clear.html or # |
5 | 5 | # see the "LICENSE.md" file for more details. # |
6 | 6 | ###################################################################################### |
7 | | -"""Tests for executing fit multiple times on multi-table data""" |
| 7 | +"""Various integration tests""" |
8 | 8 |
|
| 9 | +import contextlib |
| 10 | +import io |
9 | 11 | import os |
10 | 12 | import platform |
11 | 13 | import shutil |
|
15 | 17 | import unittest |
16 | 18 |
|
17 | 19 | import khiops.core as kh |
| 20 | +import khiops.core.internals.filesystems as fs |
18 | 21 | from khiops.core.exceptions import KhiopsEnvironmentError |
19 | 22 | from khiops.core.internals.runner import KhiopsLocalRunner |
20 | 23 | from khiops.extras.docker import KhiopsDockerRunner |
@@ -208,6 +211,53 @@ def test_runner_environment_initialization(self): |
208 | 211 |
|
209 | 212 | self.assertEqual(env_khiops_api_mode, "true") |
210 | 213 |
|
| 214 | + def test_khiops_and_khiops_coclustering_are_run_with_mpi(self): |
| 215 | + """Test that MODL and MODL_Coclustering are run with MPI""" |
| 216 | + |
| 217 | + # Get current runner |
| 218 | + runner = kh.get_runner() |
| 219 | + |
| 220 | + # Get path to the Iris dataset |
| 221 | + iris_data_dir = fs.get_child_path(runner.samples_dir, "Iris") |
| 222 | + |
| 223 | + quote = '"' if platform.system() == "Windows" else "'" |
| 224 | + |
| 225 | + # Run Khiops through an API function and test its stdout |
| 226 | + with contextlib.redirect_stdout(io.StringIO()) as khiops_stdout: |
| 227 | + kh.check_database( |
| 228 | + fs.get_child_path(iris_data_dir, "Iris.kdic"), |
| 229 | + "Iris", |
| 230 | + fs.get_child_path(iris_data_dir, "Iris.txt"), |
| 231 | + trace=True, |
| 232 | + ) |
| 233 | + expected_khiops_command = ( |
| 234 | + f"{' '.join(runner.mpi_command_args)} {runner.khiops_path}" |
| 235 | + ) |
| 236 | + self.assertTrue( |
| 237 | + expected_khiops_command in khiops_stdout.getvalue().replace(quote, "") |
| 238 | + ) |
| 239 | + |
| 240 | + # Run Khiops Coclustering through an API function and test its stdout |
| 241 | + with ( |
| 242 | + contextlib.redirect_stdout(io.StringIO()) as khiops_coclustering_stdout, |
| 243 | + tempfile.TemporaryDirectory() as temp_dir, |
| 244 | + ): |
| 245 | + kh.train_coclustering( |
| 246 | + fs.get_child_path(iris_data_dir, "Iris.kdic"), |
| 247 | + "Iris", |
| 248 | + fs.get_child_path(iris_data_dir, "Iris.txt"), |
| 249 | + ["SepalLength", "PetalLength"], |
| 250 | + fs.get_child_path(temp_dir, "IrisCoclusteringResults.khcj"), |
| 251 | + trace=True, |
| 252 | + ) |
| 253 | + expected_khiops_coclustering_command = ( |
| 254 | + f"{' '.join(runner.mpi_command_args)} {runner.khiops_coclustering_path}" |
| 255 | + ) |
| 256 | + self.assertTrue( |
| 257 | + expected_khiops_coclustering_command |
| 258 | + in khiops_coclustering_stdout.getvalue().replace(quote, "") |
| 259 | + ) |
| 260 | + |
211 | 261 |
|
212 | 262 | class KhiopsMultitableFitTests(unittest.TestCase): |
213 | 263 | """Test if Khiops estimator can be fitted on multi-table data""" |
|
0 commit comments