]> git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/lib/test/test_version.py
doc: Add `show ipv6 rpf X:X::X:X` command to docs
[mirror_frr.git] / tests / topotests / lib / test / test_version.py
1 #!/usr/bin/env python
2
3 #
4 # test_version.py
5 # Tests for library function: version_cmp().
6 #
7 # Copyright (c) 2017 by
8 # Network Device Education Foundation, Inc. ("NetDEF")
9 #
10 # Permission to use, copy, modify, and/or distribute this software
11 # for any purpose with or without fee is hereby granted, provided
12 # that the above copyright notice and this permission notice appear
13 # in all copies.
14 #
15 # THE SOFTWARE IS PROVIDED "AS IS" AND NETDEF DISCLAIMS ALL WARRANTIES
16 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
17 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NETDEF BE LIABLE FOR
18 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY
19 # DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
20 # WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
21 # ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
22 # OF THIS SOFTWARE.
23 #
24
25 """
26 Tests for the version_cmp() function.
27 """
28
29 import os
30 import sys
31 import pytest
32
33 # Save the Current Working Directory to find lib files.
34 CWD = os.path.dirname(os.path.realpath(__file__))
35 sys.path.append(os.path.join(CWD, "../../"))
36
37 # pylint: disable=C0413
38 from lib.topotest import version_cmp
39
40
41 def test_valid_versions():
42 "Test valid version compare results"
43
44 curver = "3.0"
45 samever = "3"
46 oldver = "2.0"
47 newver = "3.0.1"
48 newerver = "3.0.11"
49 vercustom = "3.0-dev"
50 verysmallinc = "3.0.0.0.0.0.0.1"
51
52 assert version_cmp(curver, oldver) == 1
53 assert version_cmp(curver, newver) == -1
54 assert version_cmp(curver, curver) == 0
55 assert version_cmp(curver, newerver) == -1
56 assert version_cmp(newver, newerver) == -1
57 assert version_cmp(curver, samever) == 0
58 assert version_cmp(curver, vercustom) == 0
59 assert version_cmp(vercustom, vercustom) == 0
60 assert version_cmp(vercustom, oldver) == 1
61 assert version_cmp(vercustom, newver) == -1
62 assert version_cmp(vercustom, samever) == 0
63 assert version_cmp(curver, verysmallinc) == -1
64 assert version_cmp(newver, verysmallinc) == 1
65 assert version_cmp(verysmallinc, verysmallinc) == 0
66 assert version_cmp(vercustom, verysmallinc) == -1
67
68
69 def test_invalid_versions():
70 "Test invalid version strings"
71
72 curver = "3.0"
73 badver1 = ".1"
74 badver2 = "-1.0"
75 badver3 = "."
76 badver4 = "3.-0.3"
77
78 with pytest.raises(ValueError):
79 assert version_cmp(curver, badver1)
80 assert version_cmp(curver, badver2)
81 assert version_cmp(curver, badver3)
82 assert version_cmp(curver, badver4)
83
84
85 def test_regression_1():
86 """
87 Test regression on the following type of comparison: '3.0.2' > '3'
88 Expected result is 1.
89 """
90 assert version_cmp("3.0.2", "3") == 1