|
20 | 20 | from score_metamodel.checks.check_options import ( |
21 | 21 | check_extra_options, |
22 | 22 | check_options, |
| 23 | + check_validity_consistency, |
23 | 24 | parse_milestone, |
24 | 25 | ) |
25 | 26 | from score_metamodel.tests import fake_check_logger, need |
@@ -128,3 +129,47 @@ def test_milestone_parsing(): |
128 | 129 | assert parse_milestone("v0.5") == (0, 5, 0) |
129 | 130 | assert parse_milestone("v1.0") == (1, 0, 0) |
130 | 131 | assert parse_milestone("v1.0.1") == (1, 0, 1) |
| 132 | + |
| 133 | + |
| 134 | +def test_validity_consistency_requires_valid_from_if_valid_until_present(): |
| 135 | + logger = fake_check_logger() |
| 136 | + app = Mock(spec=Sphinx) |
| 137 | + need_1 = need( |
| 138 | + id="stkh_req__001", |
| 139 | + type="stkh_req", |
| 140 | + valid_until="v1.0", |
| 141 | + ) |
| 142 | + |
| 143 | + check_validity_consistency(app, need_1, cast(CheckLogger, logger)) |
| 144 | + |
| 145 | + logger.assert_warning("is missing required attribute: `valid_from`.") |
| 146 | + |
| 147 | + |
| 148 | +def test_validity_consistency_allows_missing_validity_pair(): |
| 149 | + logger = fake_check_logger() |
| 150 | + app = Mock(spec=Sphinx) |
| 151 | + need_1 = need( |
| 152 | + id="stkh_req__001", |
| 153 | + type="stkh_req", |
| 154 | + ) |
| 155 | + |
| 156 | + check_validity_consistency(app, need_1, cast(CheckLogger, logger)) |
| 157 | + |
| 158 | + logger.assert_no_warnings() |
| 159 | + |
| 160 | + |
| 161 | +def test_validity_consistency_warns_on_invalid_range(): |
| 162 | + logger = fake_check_logger() |
| 163 | + app = Mock(spec=Sphinx) |
| 164 | + need_1 = need( |
| 165 | + id="feat_req__001", |
| 166 | + type="feat_req", |
| 167 | + valid_from="v2.0", |
| 168 | + valid_until="v1.0", |
| 169 | + ) |
| 170 | + |
| 171 | + check_validity_consistency(app, need_1, cast(CheckLogger, logger)) |
| 172 | + |
| 173 | + logger.assert_warning( |
| 174 | + "inconsistent validity: valid_from (v2.0) >= valid_until (v1.0)." |
| 175 | + ) |
0 commit comments