| 1 | # SPDX-License-Identifier: Apache-2.0 |
| 2 | # SPDX-FileCopyrightText: Copyright contributors to the vLLM project |
| 3 | |
| 4 | from unittest.mock import patch |
| 5 | |
| 6 | import pytest |
| 7 | |
| 8 | from vllm import version |
| 9 | |
| 10 | |
| 11 | def test_version_is_defined(): |
| 12 | assert version.__version__ is not None |
| 13 | |
| 14 | |
| 15 | def test_version_tuple(): |
| 16 | # (major, minor, patch) plus optional pre-release tag, dev-distance, and |
| 17 | # git-hash components - setuptools_scm can emit any combination of them, |
| 18 | # e.g. 6 when a dev build sits on top of an rc-tagged commit. |
| 19 | assert len(version.__version_tuple__) >= 3 |
| 20 | |
| 21 | |
| 22 | @pytest.mark.parametrize( |
| 23 | "version_tuple, version_str, expected", |
| 24 | [ |
| 25 | ((0, 0, "dev"), "0.0", True), |
| 26 | ((0, 0, "dev"), "foobar", True), |
| 27 | ((0, 7, 4), "0.6", True), |
| 28 | ((0, 7, 4), "0.5", False), |
| 29 | ((0, 7, 4), "0.7", False), |
| 30 | ((1, 2, 3), "1.1", True), |
| 31 | ((1, 2, 3), "1.0", False), |
| 32 | ((1, 2, 3), "1.2", False), |
| 33 | # This won't work as expected |
| 34 | ((1, 0, 0), "1.-1", True), |
| 35 | ((1, 0, 0), "0.9", False), |
| 36 | ((1, 0, 0), "0.17", False), |
| 37 | ], |
| 38 | ) |
| 39 | def test_prev_minor_version_was(version_tuple, version_str, expected): |
| 40 | with patch("vllm.version.__version_tuple__", version_tuple): |
| 41 | assert version._prev_minor_version_was(version_str) == expected |