Proyectos de Subversion Moodle

Rev

Rev 11 | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 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
namespace mlbackend_python;
18
 
19
/**
20
 * Unit tests for the {@link \mlbackend_python\processor} class.
21
 *
22
 * @package   mlbackend_python
23
 * @category  test
24
 * @copyright 2019 David Mudrák <david@moodle.com>
25
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
1441 ariadna 26
 * @covers \mlbackend_python\processor
1 efrain 27
 */
1441 ariadna 28
final class processor_test extends \advanced_testcase {
1 efrain 29
    /**
30
     * Test implementation of the {@link \mlbackend_python\processor::check_pip_package_version()} method.
31
     *
32
     * @dataProvider check_pip_package_versions
33
     * @param string $actual A sample of the actual package version
34
     * @param string $required A sample of the required package version
35
     * @param int $result Expected value returned by the tested method
36
     */
11 efrain 37
    public function test_check_pip_package_version($actual, $required, $result): void {
1 efrain 38
        $this->assertSame($result, \mlbackend_python\processor::check_pip_package_version($actual, $required));
39
    }
40
 
41
    /**
42
     * Check that the {@link \mlbackend_python\processor::check_pip_package_version()} can be called with single argument.
43
     */
11 efrain 44
    public function test_check_pip_package_version_default(): void {
1 efrain 45
        $this->assertSame(-1, \mlbackend_python\processor::check_pip_package_version('0.0.1'));
1441 ariadna 46
        $this->assertSame(
47
            0,
48
            \mlbackend_python\processor::check_pip_package_version(\mlbackend_python\processor::REQUIRED_PIP_PACKAGE_VERSION),
49
        );
1 efrain 50
    }
51
 
52
    /**
53
     * Provides data samples for the {@link self::test_check_pip_package_version()}.
54
     *
55
     * @return array
56
     */
1441 ariadna 57
    public static function check_pip_package_versions(): array {
1 efrain 58
        return [
59
            // Exact match.
60
            [
61
                '0.0.5',
62
                '0.0.5',
63
                0,
64
            ],
65
            [
66
                '1.0.0',
67
                '1.0.0',
68
                0,
69
            ],
70
            // Actual version higher than required, yet still API compatible.
71
            [
72
                '1.0.3',
73
                '1.0.1',
74
                0,
75
            ],
76
            [
77
                '2.1.3',
78
                '2.0.0',
79
                0,
80
            ],
81
            [
82
                '1.1.5',
83
                '1.1',
84
                0,
85
            ],
86
            [
87
                '2.0.3',
88
                '2',
89
                0,
90
            ],
91
            // Actual version not high enough to meet the requirements.
92
            [
93
                '0.0.5',
94
                '1.0.0',
95
                -1,
96
            ],
97
            [
98
                '0.37.0',
99
                '1.0.0',
100
                -1,
101
            ],
102
            [
103
                '0.0.5',
104
                '0.37.0',
105
                -1,
106
            ],
107
            [
108
                '2.0.0',
109
                '2.0.2',
110
                -1,
111
            ],
112
            [
113
                '2.7.0',
114
                '3.0',
115
                -1,
116
            ],
117
            [
118
                '2.8.9-beta1',
119
                '3.0',
120
                -1,
121
            ],
122
            [
123
                '1.1.0-rc1',
124
                '1.1.0',
125
                -1,
126
            ],
127
            // Actual version too high and no longer API compatible.
128
            [
129
                '2.0.0',
130
                '1.0.0',
131
                1,
132
            ],
133
            [
134
                '3.1.5',
135
                '2.0',
136
                1,
137
            ],
138
            [
139
                '3.0.0',
140
                '1.0',
141
                1,
142
            ],
143
            [
144
                '2.0.0',
145
                '0.0.5',
146
                1,
147
            ],
148
            [
149
                '3.0.2',
150
                '0.37.0',
151
                1,
152
            ],
153
            // Zero major version requirement is fulfilled with 1.x API (0.x are not considered stable APIs).
154
            [
155
                '1.0.0',
156
                '0.0.5',
157
                0,
158
            ],
159
            [
160
                '1.8.6',
161
                '0.37.0',
162
                0,
163
            ],
164
            // Empty version is never good enough.
165
            [
166
                '',
167
                '1.0.0',
168
                -1,
169
            ],
170
            [
171
                '0.0.0',
172
                '0.37.0',
173
                -1,
174
            ],
175
        ];
176
    }
177
}