]> git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/lib/test/test_run_and_expect.py
doc: Add `show ipv6 rpf X:X::X:X` command to docs
[mirror_frr.git] / tests / topotests / lib / test / test_run_and_expect.py
1 #!/usr/bin/env python
2
3 #
4 # test_run_and_expect.py
5 # Tests for library function: run_and_expect(_type)().
6 #
7 # Copyright (c) 2019 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 `run_and_expect(_type)()` functions.
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 run_and_expect_type
39
40
41 def test_run_and_expect_type():
42 "Test basic `run_and_expect_type` functionality."
43
44 def return_true():
45 "Test function that returns `True`."
46 return True
47
48 # Test value success.
49 success, value = run_and_expect_type(
50 return_true, bool, count=1, wait=0, avalue=True
51 )
52 assert success is True
53 assert value is True
54
55 # Test value failure.
56 success, value = run_and_expect_type(
57 return_true, bool, count=1, wait=0, avalue=False
58 )
59 assert success is False
60 assert value is True
61
62 # Test type success.
63 success, value = run_and_expect_type(return_true, bool, count=1, wait=0)
64 assert success is True
65 assert value is True
66
67 # Test type failure.
68 success, value = run_and_expect_type(return_true, str, count=1, wait=0)
69 assert success is False
70 assert value is True
71
72 # Test type failure, return correct type.
73 success, value = run_and_expect_type(return_true, str, count=1, wait=0, avalue=True)
74 assert success is False
75 assert value is True
76
77
78 if __name__ == "__main__":
79 sys.exit(pytest.main())