MDL-84107 core_analytics: Switch PHPUnit to use Python backend

This commit is contained in:
Huong Nguyen
2025-03-05 12:01:23 +07:00
parent 2aeef38c7b
commit 5dc4290eba
10 changed files with 175 additions and 161 deletions
+31 -14
View File
@@ -26,6 +26,11 @@ namespace mlbackend_python;
defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once($CFG->dirroot . '/analytics/tests/classes/mlbackend_helper_trait.php');
use core_analytics\tests\mlbackend_helper_trait;
/**
* Python predictions processor.
*
@@ -35,6 +40,8 @@ defined('MOODLE_INTERNAL') || die();
*/
class processor implements \core_analytics\classifier, \core_analytics\regressor, \core_analytics\packable {
use mlbackend_helper_trait;
/**
* The required version of the python package that performs all calculations.
*/
@@ -90,21 +97,31 @@ class processor implements \core_analytics\classifier, \core_analytics\regresso
public function __construct() {
global $CFG;
$config = get_config('mlbackend_python');
$this->useserver = !empty($config->useserver);
if (!$this->useserver) {
// Set the python location if there is a value.
if (!empty($CFG->pathtopython)) {
$this->pathtopython = $CFG->pathtopython;
}
if ((defined('BEHAT_SITE_RUNNING') || (defined('PHPUNIT_TEST') && PHPUNIT_TEST)) &&
self::is_mlbackend_python_configured()) {
$this->useserver = true;
$this->host = TEST_MLBACKEND_PYTHON_HOST;
$this->port = TEST_MLBACKEND_PYTHON_PORT;
$this->secure = false;
$this->username = TEST_MLBACKEND_PYTHON_USERNAME;
$this->password = TEST_MLBACKEND_PYTHON_PASSWORD;
} else {
$this->host = $config->host ?? '';
$this->port = $config->port ?? '';
$this->secure = $config->secure ?? false;
$this->username = $config->username ?? '';
$this->password = $config->password ?? '';
$config = get_config('mlbackend_python');
$this->useserver = !empty($config->useserver);
if (!$this->useserver) {
// Set the python location if there is a value.
if (!empty($CFG->pathtopython)) {
$this->pathtopython = $CFG->pathtopython;
}
} else {
$this->host = $config->host ?? '';
$this->port = $config->port ?? '';
$this->secure = $config->secure ?? false;
$this->username = $config->username ?? '';
$this->password = $config->password ?? '';
}
}
}