MDL-84107 core_analytics: Skip tests if mlbackend_python not configured

This commit is contained in:
David Woloszyn
2025-03-06 11:48:41 +07:00
committed by Huong Nguyen
parent 42c2b70505
commit 2aeef38c7b
6 changed files with 95 additions and 0 deletions
@@ -0,0 +1,40 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
namespace core_analytics\tests;
/**
* A trait to check machine learning configurations.
*
* @package core_analytics
* @category test
* @copyright 2024 David Woloszyn <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
trait mlbackend_configuration_trait {
/**
* Check if mlbackend_python is configured.
*
* @return bool
*/
public static function is_mlbackend_python_configured(): bool {
if (defined('TEST_MLBACKEND_PYTHON_HOST') && defined('TEST_MLBACKEND_PYTHON_PORT')
&& defined('TEST_MLBACKEND_PYTHON_USERNAME') && defined('TEST_MLBACKEND_PYTHON_USERNAME')) {
return true;
}
return false;
}
}
+12
View File
@@ -16,6 +16,8 @@
namespace core_analytics;
use core_analytics\tests\mlbackend_configuration_trait;
defined('MOODLE_INTERNAL') || die();
require_once(__DIR__ . '/fixtures/test_indicator_max.php');
@@ -32,12 +34,18 @@ require_once(__DIR__ . '/fixtures/test_target_course_level_shortname.php');
* @covers \core_analytics\manager
*/
final class manager_test extends \advanced_testcase {
use mlbackend_configuration_trait;
/**
* test_deleted_context
*/
public function test_deleted_context(): void {
global $DB;
if (!self::is_mlbackend_python_configured()) {
$this->markTestSkipped('mlbackend_python is not configured.');
}
$this->resetAfterTest(true);
$this->setAdminuser();
set_config('enabled_stores', 'logstore_standard', 'tool_log');
@@ -115,6 +123,10 @@ final class manager_test extends \advanced_testcase {
public function test_deleted_analysable(): void {
global $DB;
if (!self::is_mlbackend_python_configured()) {
$this->markTestSkipped('mlbackend_python is not configured.');
}
$this->resetAfterTest(true);
$this->setAdminuser();
set_config('enabled_stores', 'logstore_standard', 'tool_log');
+19
View File
@@ -24,6 +24,8 @@
namespace core_analytics;
use core_analytics\tests\mlbackend_configuration_trait;
defined('MOODLE_INTERNAL') || die();
require_once(__DIR__ . '/fixtures/test_indicator_max.php');
@@ -42,6 +44,7 @@ require_once(__DIR__ . '/fixtures/test_analysis.php');
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
final class model_test extends \advanced_testcase {
use mlbackend_configuration_trait;
/** @var model Store Model. */
protected $model;
@@ -95,6 +98,10 @@ final class model_test extends \advanced_testcase {
public function test_delete(): void {
global $DB;
if (!self::is_mlbackend_python_configured()) {
$this->markTestSkipped('mlbackend_python is not configured.');
}
$this->resetAfterTest(true);
set_config('enabled_stores', 'logstore_standard', 'tool_log');
@@ -140,6 +147,10 @@ final class model_test extends \advanced_testcase {
public function test_clear(): void {
global $DB;
if (!self::is_mlbackend_python_configured()) {
$this->markTestSkipped('mlbackend_python is not configured.');
}
$this->resetAfterTest(true);
set_config('enabled_stores', 'logstore_standard', 'tool_log');
@@ -379,6 +390,10 @@ final class model_test extends \advanced_testcase {
* Test that import_model import models' configurations.
*/
public function test_import_model_config(): void {
if (!self::is_mlbackend_python_configured()) {
$this->markTestSkipped('mlbackend_python is not configured.');
}
$this->resetAfterTest(true);
$this->model->enable('\\core\\analytics\\time_splitting\\quarters');
@@ -421,6 +436,10 @@ final class model_test extends \advanced_testcase {
* Test export_config
*/
public function test_export_config(): void {
if (!self::is_mlbackend_python_configured()) {
$this->markTestSkipped('mlbackend_python is not configured.');
}
$this->resetAfterTest(true);
$this->model->enable('\\core\\analytics\\time_splitting\\quarters');
@@ -28,6 +28,7 @@ use core_privacy\local\request\transform;
use core_privacy\local\request\writer;
use core_privacy\local\request\approved_contextlist;
use core_privacy\local\request\approved_userlist;
use core_analytics\tests\mlbackend_configuration_trait;
defined('MOODLE_INTERNAL') || die();
@@ -44,6 +45,7 @@ require_once(__DIR__ . '/../fixtures/test_target_course_users.php');
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
final class provider_test extends \core_privacy\tests\provider_testcase {
use mlbackend_configuration_trait;
/** @var \core_analytics\model Store Model 1. */
protected $model1;
@@ -88,6 +90,10 @@ final class provider_test extends \core_privacy\tests\provider_testcase {
protected $c2;
public function setUp(): void {
if (!self::is_mlbackend_python_configured()) {
$this->markTestSkipped('mlbackend_python is not configured.');
}
parent::setUp();
$this->resetAfterTest(true);
+11
View File
@@ -16,6 +16,8 @@
namespace core_analytics;
use core_analytics\tests\mlbackend_configuration_trait;
defined('MOODLE_INTERNAL') || die();
require_once(__DIR__ . '/fixtures/test_indicator_fullname.php');
@@ -30,6 +32,7 @@ require_once(__DIR__ . '/fixtures/test_target_shortname.php');
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
final class stats_test extends \advanced_testcase {
use mlbackend_configuration_trait;
/**
* Set up the test environment.
@@ -70,6 +73,9 @@ final class stats_test extends \advanced_testcase {
* Test the {@link \core_analytics\stats::predictions()} implementation.
*/
public function test_predictions(): void {
if (!self::is_mlbackend_python_configured()) {
$this->markTestSkipped('mlbackend_python is not configured.');
}
$this->resetAfterTest(true);
@@ -116,6 +122,11 @@ final class stats_test extends \advanced_testcase {
*/
public function test_actions(): void {
global $DB;
if (!self::is_mlbackend_python_configured()) {
$this->markTestSkipped('mlbackend_python is not configured.');
}
$this->resetAfterTest(true);
$model = \core_analytics\model::create(
@@ -16,6 +16,8 @@
namespace core_course\analytics;
use core_analytics\tests\mlbackend_configuration_trait;
defined('MOODLE_INTERNAL') || die();
global $CFG;
@@ -32,6 +34,7 @@ require_once(__DIR__ . '/../../../analytics/tests/fixtures/test_target_course_us
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
final class indicators_test extends \advanced_testcase {
use mlbackend_configuration_trait;
/**
* test_no_teacher
@@ -316,6 +319,10 @@ final class indicators_test extends \advanced_testcase {
public function test_activities_due(): void {
global $DB;
if (!self::is_mlbackend_python_configured()) {
$this->markTestSkipped('mlbackend_python is not configured.');
}
$this->resetAfterTest(true);
$this->setAdminuser();