Differences Between: [Versions 310 and 311] [Versions 310 and 400] [Versions 310 and 401] [Versions 310 and 402] [Versions 310 and 403]
1 <?php 2 // This file is part of Moodle - https://moodle.org/ 3 // 4 // Moodle is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // Moodle is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 16 17 /** 18 * Provides the {@link mlbackend_python_processor_testcase} class. 19 * 20 * @package mlbackend_python 21 * @category test 22 * @copyright 2019 David Mudrák <david@moodle.com> 23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 24 */ 25 26 defined('MOODLE_INTERNAL') || die(); 27 28 /** 29 * Unit tests for the {@link \mlbackend_python\processor} class. 30 * 31 * @copyright 2019 David Mudrák <david@moodle.com> 32 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 33 */ 34 class mlbackend_python_processor_testcase extends advanced_testcase { 35 36 /** 37 * Test implementation of the {@link \mlbackend_python\processor::check_pip_package_version()} method. 38 * 39 * @dataProvider check_pip_package_versions 40 * @param string $actual A sample of the actual package version 41 * @param string $required A sample of the required package version 42 * @param int $result Expected value returned by the tested method 43 */ 44 public function test_check_pip_package_version($actual, $required, $result) { 45 $this->assertSame($result, \mlbackend_python\processor::check_pip_package_version($actual, $required)); 46 } 47 48 /** 49 * Check that the {@link \mlbackend_python\processor::check_pip_package_version()} can be called with single argument. 50 */ 51 public function test_check_pip_package_version_default() { 52 53 $this->assertSame(-1, \mlbackend_python\processor::check_pip_package_version('0.0.1')); 54 $this->assertSame(0, \mlbackend_python\processor::check_pip_package_version( 55 \mlbackend_python\processor::REQUIRED_PIP_PACKAGE_VERSION)); 56 } 57 58 /** 59 * Provides data samples for the {@link self::test_check_pip_package_version()}. 60 * 61 * @return array 62 */ 63 public function check_pip_package_versions() { 64 return [ 65 // Exact match. 66 [ 67 '0.0.5', 68 '0.0.5', 69 0, 70 ], 71 [ 72 '1.0.0', 73 '1.0.0', 74 0, 75 ], 76 // Actual version higher than required, yet still API compatible. 77 [ 78 '1.0.3', 79 '1.0.1', 80 0, 81 ], 82 [ 83 '2.1.3', 84 '2.0.0', 85 0, 86 ], 87 [ 88 '1.1.5', 89 '1.1', 90 0, 91 ], 92 [ 93 '2.0.3', 94 '2', 95 0, 96 ], 97 // Actual version not high enough to meet the requirements. 98 [ 99 '0.0.5', 100 '1.0.0', 101 -1, 102 ], 103 [ 104 '0.37.0', 105 '1.0.0', 106 -1, 107 ], 108 [ 109 '0.0.5', 110 '0.37.0', 111 -1, 112 ], 113 [ 114 '2.0.0', 115 '2.0.2', 116 -1, 117 ], 118 [ 119 '2.7.0', 120 '3.0', 121 -1, 122 ], 123 [ 124 '2.8.9-beta1', 125 '3.0', 126 -1, 127 ], 128 [ 129 '1.1.0-rc1', 130 '1.1.0', 131 -1, 132 ], 133 // Actual version too high and no longer API compatible. 134 [ 135 '2.0.0', 136 '1.0.0', 137 1, 138 ], 139 [ 140 '3.1.5', 141 '2.0', 142 1, 143 ], 144 [ 145 '3.0.0', 146 '1.0', 147 1, 148 ], 149 [ 150 '2.0.0', 151 '0.0.5', 152 1, 153 ], 154 [ 155 '3.0.2', 156 '0.37.0', 157 1, 158 ], 159 // Zero major version requirement is fulfilled with 1.x API (0.x are not considered stable APIs). 160 [ 161 '1.0.0', 162 '0.0.5', 163 0, 164 ], 165 [ 166 '1.8.6', 167 '0.37.0', 168 0, 169 ], 170 // Empty version is never good enough. 171 [ 172 '', 173 '1.0.0', 174 -1, 175 ], 176 [ 177 '0.0.0', 178 '0.37.0', 179 -1, 180 ], 181 ]; 182 } 183 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body