]>
git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/lib/test/test_version.py
5 # Tests for library function: version_cmp().
7 # Copyright (c) 2017 by
8 # Network Device Education Foundation, Inc. ("NetDEF")
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
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
26 Tests for the version_cmp() function.
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
, "../../"))
37 # pylint: disable=C0413
38 from lib
.topotest
import version_cmp
41 def test_valid_versions():
42 "Test valid version compare results"
50 verysmallinc
= "3.0.0.0.0.0.0.1"
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
69 def test_invalid_versions():
70 "Test invalid version strings"
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
)
85 def test_regression_1():
87 Test regression on the following type of comparison: '3.0.2' > '3'
90 assert version_cmp("3.0.2", "3") == 1