Proyectos de Subversion Moodle

Rev

Rev 1 | | 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
26
 */
27
class processor_test extends \advanced_testcase {
28
 
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
 
46
        $this->assertSame(-1, \mlbackend_python\processor::check_pip_package_version('0.0.1'));
47
        $this->assertSame(0, \mlbackend_python\processor::check_pip_package_version(
48
            \mlbackend_python\processor::REQUIRED_PIP_PACKAGE_VERSION));
49
    }
50
 
51
    /**
52
     * Provides data samples for the {@link self::test_check_pip_package_version()}.
53
     *
54
     * @return array
55
     */
56
    public function check_pip_package_versions() {
57
        return [
58
            // Exact match.
59
            [
60
                '0.0.5',
61
                '0.0.5',
62
                0,
63
            ],
64
            [
65
                '1.0.0',
66
                '1.0.0',
67
                0,
68
            ],
69
            // Actual version higher than required, yet still API compatible.
70
            [
71
                '1.0.3',
72
                '1.0.1',
73
                0,
74
            ],
75
            [
76
                '2.1.3',
77
                '2.0.0',
78
                0,
79
            ],
80
            [
81
                '1.1.5',
82
                '1.1',
83
                0,
84
            ],
85
            [
86
                '2.0.3',
87
                '2',
88
                0,
89
            ],
90
            // Actual version not high enough to meet the requirements.
91
            [
92
                '0.0.5',
93
                '1.0.0',
94
                -1,
95
            ],
96
            [
97
                '0.37.0',
98
                '1.0.0',
99
                -1,
100
            ],
101
            [
102
                '0.0.5',
103
                '0.37.0',
104
                -1,
105
            ],
106
            [
107
                '2.0.0',
108
                '2.0.2',
109
                -1,
110
            ],
111
            [
112
                '2.7.0',
113
                '3.0',
114
                -1,
115
            ],
116
            [
117
                '2.8.9-beta1',
118
                '3.0',
119
                -1,
120
            ],
121
            [
122
                '1.1.0-rc1',
123
                '1.1.0',
124
                -1,
125
            ],
126
            // Actual version too high and no longer API compatible.
127
            [
128
                '2.0.0',
129
                '1.0.0',
130
                1,
131
            ],
132
            [
133
                '3.1.5',
134
                '2.0',
135
                1,
136
            ],
137
            [
138
                '3.0.0',
139
                '1.0',
140
                1,
141
            ],
142
            [
143
                '2.0.0',
144
                '0.0.5',
145
                1,
146
            ],
147
            [
148
                '3.0.2',
149
                '0.37.0',
150
                1,
151
            ],
152
            // Zero major version requirement is fulfilled with 1.x API (0.x are not considered stable APIs).
153
            [
154
                '1.0.0',
155
                '0.0.5',
156
                0,
157
            ],
158
            [
159
                '1.8.6',
160
                '0.37.0',
161
                0,
162
            ],
163
            // Empty version is never good enough.
164
            [
165
                '',
166
                '1.0.0',
167
                -1,
168
            ],
169
            [
170
                '0.0.0',
171
                '0.37.0',
172
                -1,
173
            ],
174
        ];
175
    }
176
}