]> git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/lib/test/test_run_and_expect.py
Merge pull request #12798 from donaldsharp/rib_match_multicast
[mirror_frr.git] / tests / topotests / lib / test / test_run_and_expect.py
1 #!/usr/bin/env python
2 # SPDX-License-Identifier: ISC
3
4 #
5 # test_run_and_expect.py
6 # Tests for library function: run_and_expect(_type)().
7 #
8 # Copyright (c) 2019 by
9 # Network Device Education Foundation, Inc. ("NetDEF")
10 #
11
12 """
13 Tests for the `run_and_expect(_type)()` functions.
14 """
15
16 import os
17 import sys
18 import pytest
19
20 # Save the Current Working Directory to find lib files.
21 CWD = os.path.dirname(os.path.realpath(__file__))
22 sys.path.append(os.path.join(CWD, "../../"))
23
24 # pylint: disable=C0413
25 from lib.topotest import run_and_expect_type
26
27
28 def test_run_and_expect_type():
29 "Test basic `run_and_expect_type` functionality."
30
31 def return_true():
32 "Test function that returns `True`."
33 return True
34
35 # Test value success.
36 success, value = run_and_expect_type(
37 return_true, bool, count=1, wait=0, avalue=True
38 )
39 assert success is True
40 assert value is True
41
42 # Test value failure.
43 success, value = run_and_expect_type(
44 return_true, bool, count=1, wait=0, avalue=False
45 )
46 assert success is False
47 assert value is True
48
49 # Test type success.
50 success, value = run_and_expect_type(return_true, bool, count=1, wait=0)
51 assert success is True
52 assert value is True
53
54 # Test type failure.
55 success, value = run_and_expect_type(return_true, str, count=1, wait=0)
56 assert success is False
57 assert value is True
58
59 # Test type failure, return correct type.
60 success, value = run_and_expect_type(return_true, str, count=1, wait=0, avalue=True)
61 assert success is False
62 assert value is True
63
64
65 if __name__ == "__main__":
66 sys.exit(pytest.main())