|
| 1 | +# Copyright 2020 - 2021 MONAI Consortium |
| 2 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 3 | +# you may not use this file except in compliance with the License. |
| 4 | +# You may obtain a copy of the License at |
| 5 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 6 | +# Unless required by applicable law or agreed to in writing, software |
| 7 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 8 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 9 | +# See the License for the specific language governing permissions and |
| 10 | +# limitations under the License. |
| 11 | + |
| 12 | + |
| 13 | +import unittest |
| 14 | + |
| 15 | +from parameterized import parameterized |
| 16 | + |
| 17 | +from monai.utils import pytorch_after |
| 18 | + |
| 19 | +TEST_CASES = ( |
| 20 | + (1, 5, 9, "1.6.0"), |
| 21 | + (1, 6, 0, "1.6.0"), |
| 22 | + (1, 6, 1, "1.6.0", False), |
| 23 | + (1, 7, 0, "1.6.0", False), |
| 24 | + (2, 6, 0, "1.6.0", False), |
| 25 | + (0, 6, 0, "1.6.0a0+3fd9dcf"), |
| 26 | + (1, 5, 9, "1.6.0a0+3fd9dcf"), |
| 27 | + (1, 6, 0, "1.6.0a0+3fd9dcf", False), |
| 28 | + (1, 6, 1, "1.6.0a0+3fd9dcf", False), |
| 29 | + (2, 6, 0, "1.6.0a0+3fd9dcf", False), |
| 30 | + (1, 6, 0, "1.6.0-rc0+3fd9dcf", False), # defaults to prerelease |
| 31 | + (1, 6, 0, "1.6.0rc0", False), |
| 32 | + (1, 6, 0, "1.6", True), |
| 33 | + (1, 6, 0, "1", False), |
| 34 | + (1, 6, 0, "1.6.0+cpu", True), |
| 35 | + (1, 6, 1, "1.6.0+cpu", False), |
| 36 | +) |
| 37 | + |
| 38 | + |
| 39 | +class TestPytorchVersionCompare(unittest.TestCase): |
| 40 | + @parameterized.expand(TEST_CASES) |
| 41 | + def test_compare(self, a, b, p, current, expected=True): |
| 42 | + """Test pytorch_after with a and b""" |
| 43 | + self.assertEqual(pytorch_after(a, b, p, current), expected) |
| 44 | + |
| 45 | + |
| 46 | +if __name__ == "__main__": |
| 47 | + unittest.main() |
0 commit comments