|
| 1 | +from sphinxcontrib.test_reports.functions import tr_link, tr_link_match |
| 2 | + |
| 3 | + |
| 4 | +def test_tr_link_option_not_in_need(): |
| 5 | + """ |
| 6 | + Return an empty string when the specified test option is missing from the need. |
| 7 | + """ |
| 8 | + assert tr_link(app=None, need={}, needs={}, test_option="a", target_option="b") == "" |
| 9 | + |
| 10 | +def test_tr_link_no_target_option_in_needs(): |
| 11 | + """ |
| 12 | + Return an empty list when the target option is missing in all items of needs. |
| 13 | + """ |
| 14 | + assert tr_link(app=None, need={"a": "1"}, needs={"x": {"id": "123"}}, test_option="a", target_option="b") == [] |
| 15 | + |
| 16 | +def test_tr_link_no_match(): |
| 17 | + """ |
| 18 | + Returns an empty list when no matching value for the test option is found in any of the target options within needs. |
| 19 | + """ |
| 20 | + assert tr_link(app=None, need={"a": "1"}, needs={"x": {"b": "2", "id": "123"}}, test_option="a", target_option="b") == [] |
| 21 | + |
| 22 | +def test_tr_link_match(): |
| 23 | + """ |
| 24 | + Returns a list of ids when there is a matching value in both need and needs. |
| 25 | + """ |
| 26 | + assert tr_link(app=None, need={"a": "1"}, needs={"x": {"b": "1", "id": "123"}}, test_option="a", target_option="b") == ["123"] |
| 27 | + |
| 28 | +def test_tr_link_regex_match(): |
| 29 | + """ |
| 30 | + Returns a list of ids when the test option value containing an asterisk (*) |
| 31 | + correctly matches target options using regular expression patterns. |
| 32 | + """ |
| 33 | + needs = { |
| 34 | + "x": {"b": "abc123", "id": "111"}, |
| 35 | + "q": {"b": "abc/123", "id": "112"}, |
| 36 | + "y": {"b": "def456", "id": "222"}, |
| 37 | + "z": {"b": "ghi789", "id": "333"}, |
| 38 | + } |
| 39 | + need = {"id": "1", "a": "abc.*"} |
| 40 | + assert tr_link_match( |
| 41 | + app=None, need=need, needs=needs, test_option="a", target_option="b" |
| 42 | + ) == ["111", "112"] |
| 43 | + |
| 44 | + |
| 45 | +def test_tr_link_regex_no_match(): |
| 46 | + """ |
| 47 | + Returns an empty list when the test option value containing an asterisk (*) |
| 48 | + does not match any target options using regular expression patterns. |
| 49 | + """ |
| 50 | + needs = {"x": {"b": "abc123", "id": "111"}, "y": {"b": "def456", "id": "222"}} |
| 51 | + need = {"id": "1", "a": "xyz.*"} |
| 52 | + assert ( |
| 53 | + tr_link_match(app=None, need=need, needs=needs, test_option="a", target_option="b") |
| 54 | + == [] |
| 55 | + ) |
| 56 | + |
| 57 | +def test_tr_link_regex_skip_linking_to_itself(): |
| 58 | + """ |
| 59 | + Returns an empty list when the need and needs have the same 'id'. |
| 60 | + """ |
| 61 | + needs = {"x": {"b": "abc123", "id": "111"}, "y": {"b": "abc123", "id": "222"}} |
| 62 | + need = {"id": "111", "a": "abc123"} |
| 63 | + assert tr_link_match( |
| 64 | + app=None, need=need, needs=needs, test_option="a", target_option="b" |
| 65 | + ) == ["222"] |
0 commit comments