Skip to content

Commit b55bf6a

Browse files
committed
add test
Signed-off-by: YunLiu <[email protected]>
1 parent 8fafc3f commit b55bf6a

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed

tests/test_version_after.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# Copyright (c) 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+
from __future__ import annotations
13+
14+
import unittest
15+
16+
from parameterized import parameterized
17+
18+
from monai.utils import pytorch_after, compute_capabilities_after
19+
20+
TEST_CASES_PT = (
21+
(1, 5, 9, "1.6.0"),
22+
(1, 6, 0, "1.6.0"),
23+
(1, 6, 1, "1.6.0", False),
24+
(1, 7, 0, "1.6.0", False),
25+
(2, 6, 0, "1.6.0", False),
26+
(0, 6, 0, "1.6.0a0+3fd9dcf"),
27+
(1, 5, 9, "1.6.0a0+3fd9dcf"),
28+
(1, 6, 0, "1.6.0a0+3fd9dcf", False),
29+
(1, 6, 1, "1.6.0a0+3fd9dcf", False),
30+
(2, 6, 0, "1.6.0a0+3fd9dcf", False),
31+
(1, 6, 0, "1.6.0-rc0+3fd9dcf", False), # defaults to prerelease
32+
(1, 6, 0, "1.6.0rc0", False),
33+
(1, 6, 0, "1.6", True),
34+
(1, 6, 0, "1", False),
35+
(1, 6, 0, "1.6.0+cpu", True),
36+
(1, 6, 1, "1.6.0+cpu", False),
37+
)
38+
39+
TEST_CASES_SM = [
40+
# (major, minor, sm, expected)
41+
(6, 1, "6.1", True),
42+
(6, 1, "6.0", False),
43+
(6, 0, "8.6", True),
44+
(7, 0, "8", True),
45+
(8, 6, "8", False),
46+
]
47+
48+
49+
class TestPytorchVersionCompare(unittest.TestCase):
50+
51+
@parameterized.expand(TEST_CASES_PT)
52+
def test_compare(self, a, b, p, current, expected=True):
53+
"""Test pytorch_after with a and b"""
54+
self.assertEqual(pytorch_after(a, b, p, current), expected)
55+
56+
57+
class TestComputeCapabilitiesAfter(unittest.TestCase):
58+
59+
@parameterized.expand(TEST_CASES_SM)
60+
def test_compute_capabilities_after(self, major, minor, sm, expected):
61+
self.assertEqual(compute_capabilities_after(major, minor, sm), expected)
62+
63+
64+
if __name__ == "__main__":
65+
unittest.main()

0 commit comments

Comments
 (0)