2 # Copyright © 2014, 2016, 2019 Intel Corporation
4 # Permission is hereby granted, free of charge, to any person obtaining a copy
5 # of this software and associated documentation files (the "Software"), to deal
6 # in the Software without restriction, including without limitation the rights
7 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 # copies of the Software, and to permit persons to whom the Software is
9 # furnished to do so, subject to the following conditions:
11 # The above copyright notice and this permission notice shall be included in
12 # all copies or substantial portions of the Software.
14 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 """Tests for framework.status.
24 This module does not have the comprehensive tests for all of the various
25 combinations of comparisons between the various kinds of functions. Instead, it
26 just asserts that the regressions, fixes, etc lists are as expected.
34 from framework
import status
37 # Statuses from worst to last. NotRun is intentionally not in this list and
38 # tested separately because of upcoming features for it
50 # all statuses except pass are problems
51 PROBLEMS
= STATUSES
[1:]
53 # Create lists of fixes and regressions programmatically based on the STATUSES
54 # list. This means less code, and easier expansion changes.
55 REGRESSIONS
= list(itertools
.combinations(STATUSES
, 2)) + \
56 list(itertools
.combinations([status
.SKIP
] + PROBLEMS
, 2))
57 FIXES
= list(itertools
.combinations(reversed(STATUSES
), 2)) + \
58 list(itertools
.combinations(list(reversed(PROBLEMS
)) + [status
.SKIP
], 2))
60 # The statuses that don't cause changes when transitioning from one another
61 NO_OPS
= [status
.SKIP
, status
.NOTRUN
]
64 @pytest.mark
.raises(exception
=status
.StatusException
)
65 def test_bad_lookup():
66 """status.status_lookup: An unexpected value raises a StatusException"""
67 status
.status_lookup('foobar')
70 @pytest.mark
.raises(exception
=TypeError)
71 def test_status_eq_raises():
72 """status.Status: eq comparison to uncomparable object results in TypeError"""
76 @pytest.mark
.raises(exception
=TypeError)
77 def test_nochangestatus_eq_raises():
78 """status.NoChangeStatus: eq comparison to uncomparable type results in TypeError"""
79 status
.NOTRUN
== dict()
82 @pytest.mark
.raises(exception
=TypeError)
83 def test_nochangestatus_ne_raises():
84 """status.NoChangeStatus: ne comparison to uncomparable type results in TypeError"""
85 status
.NOTRUN
!= dict()
89 """status.Status: A status can be looked up with 'x in y' synatx"""
96 @pytest.mark
.parametrize(
97 'stat', itertools
.chain(STATUSES
, [status
.SKIP
, status
.NOTRUN
]))
98 def test_lookup(stat
):
99 status
.status_lookup(stat
)
102 @pytest.mark
.parametrize('new,old', REGRESSIONS
)
103 def test_regression(new
, old
):
104 assert status
.status_lookup(new
) < status
.status_lookup(old
)
107 @pytest.mark
.parametrize('new,old', FIXES
)
108 def test_fixes(new
, old
):
109 assert status
.status_lookup(new
) > status
.status_lookup(old
)
112 @pytest.mark
.parametrize('new,old', itertools
.permutations(STATUSES
, 2))
113 def test_changes(new
, old
):
114 assert status
.status_lookup(new
) != status
.status_lookup(old
)
117 @pytest.mark
.parametrize('new,old', itertools
.permutations(NO_OPS
, 2))
118 def test_no_change(new
, old
):
119 new
= status
.status_lookup(new
)
120 old
= status
.status_lookup(old
)
125 @pytest.mark
.parametrize("stat,op,expected", [
126 (status
.Status('Test', 0, (0, 0)), str, 'Test'),
127 (status
.Status('Test', 0, (0, 0)), bytes
, b
'Test'),
128 (status
.Status('Test', 0, (0, 0)), int, 0),
129 (status
.Status('Test', 0, (0, 0)), repr, 'Status("Test", 0, (0, 0))'),
130 (status
.Status('Test', 0, (0, 0)), hash, hash('Test')),
131 (status
.NoChangeStatus('No'), hash, hash('No')),
133 def test_status_comparisons(stat
, op
, expected
):
134 """Test status.Status equality protocol."""
135 assert op(stat
) == expected