|
10 | 10 | from docker.api.client import APIClient
|
11 | 11 | from docker.constants import IS_WINDOWS_PLATFORM, DEFAULT_DOCKER_API_VERSION
|
12 | 12 | from docker.errors import DockerException
|
13 |
| -from docker.utils import (convert_filters, convert_volume_binds, |
14 |
| - decode_json_header, kwargs_from_env, parse_bytes, |
15 |
| - parse_devices, parse_env_file, parse_host, |
16 |
| - parse_repository_tag, split_command, update_headers) |
| 13 | +from docker.utils import ( |
| 14 | + compare_version, convert_filters, convert_volume_binds, decode_json_header, |
| 15 | + format_environment, kwargs_from_env, parse_bytes, parse_devices, |
| 16 | + parse_env_file, parse_host, parse_repository_tag, split_command, |
| 17 | + update_headers, version_gte, version_lt |
| 18 | +) |
17 | 19 | from docker.utils.ports import build_port_bindings, split_port
|
18 |
| -from docker.utils.utils import format_environment |
19 | 20 |
|
20 | 21 | TEST_CERT_DIR = os.path.join(
|
21 | 22 | os.path.dirname(__file__),
|
@@ -629,3 +630,19 @@ def test_format_env_no_value(self):
|
629 | 630 | 'BAR': '',
|
630 | 631 | }
|
631 | 632 | assert sorted(format_environment(env_dict)) == ['BAR=', 'FOO']
|
| 633 | + |
| 634 | + |
| 635 | +def test_compare_versions(): |
| 636 | + assert compare_version('1.0', '1.1') == 1 |
| 637 | + assert compare_version('1.10', '1.1') == -1 |
| 638 | + assert compare_version('1.10', '1.10') == 0 |
| 639 | + assert compare_version('1.10.0', '1.10.1') == 1 |
| 640 | + assert compare_version('1.9', '1.10') == 1 |
| 641 | + assert compare_version('1.9.1', '1.10') == 1 |
| 642 | + # Test comparison helpers |
| 643 | + assert version_lt('1.0', '1.27') |
| 644 | + assert version_gte('1.27', '1.20') |
| 645 | + # Test zero-padding |
| 646 | + assert compare_version('1', '1.0') == 0 |
| 647 | + assert compare_version('1.10', '1.10.1') == 1 |
| 648 | + assert compare_version('1.10.0', '1.10') == 0 |
0 commit comments