From 63c15f6c58f150b8543b4b9b8ca506fa4874e342 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Monlla=C3=B3?= Date: Thu, 3 Oct 2019 09:45:57 +0800 Subject: [PATCH] MDL-66004 mlbackend_python: Purge testing output dirs properly --- analytics/tests/prediction_test.php | 24 +++++++++++++++++++++- lib/mlbackend/python/classes/processor.php | 2 +- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/analytics/tests/prediction_test.php b/analytics/tests/prediction_test.php index b0471f2ef8e..2b437f6270c 100644 --- a/analytics/tests/prediction_test.php +++ b/analytics/tests/prediction_test.php @@ -54,6 +54,23 @@ require_once(__DIR__ . '/../../course/lib.php'); */ class core_analytics_prediction_testcase extends advanced_testcase { + /** + * Purge all the mlbackend outputs. + * + * This is done automatically for mlbackends using the web server dataroot but + * other mlbackends may store files elsewhere and these files need to be removed. + * + * @return null + */ + public function tearDown() { + $this->setAdminUser(); + + $models = \core_analytics\manager::get_all_models(); + foreach ($models as $model) { + $model->delete(); + } + } + /** * test_static_prediction * @@ -414,7 +431,8 @@ class core_analytics_prediction_testcase extends advanced_testcase { // Training should work correctly if at least 1 sample of each class is included. $dir = make_request_directory(); - $result = $predictionsprocessor->train_classification('whatever' . microtime(), $dataset, $dir); + $modeluniqueid = 'whatever' . microtime(); + $result = $predictionsprocessor->train_classification($modeluniqueid, $dataset, $dir); switch ($success) { case 'yes': @@ -429,6 +447,10 @@ class core_analytics_prediction_testcase extends advanced_testcase { // what we really want to check is that an exception was not thrown. $this->assertInstanceOf(\stdClass::class, $result); } + + // Purge the directory used in this test (useful in case the mlbackend is storing files + // somewhere out of the default moodledata/models dir. + $predictionsprocessor->delete_output_dir($dir, $modeluniqueid); } /** diff --git a/lib/mlbackend/python/classes/processor.php b/lib/mlbackend/python/classes/processor.php index 25861cead21..c0729bdc44c 100644 --- a/lib/mlbackend/python/classes/processor.php +++ b/lib/mlbackend/python/classes/processor.php @@ -38,7 +38,7 @@ class processor implements \core_analytics\classifier, \core_analytics\regresso /** * The required version of the python package that performs all calculations. */ - const REQUIRED_PIP_PACKAGE_VERSION = '2.2.0'; + const REQUIRED_PIP_PACKAGE_VERSION = '2.2.1'; /** * The python package is installed in a server.