Test for invalid node IDs
()
| 42 | |
| 43 | |
| 44 | def test_invalid_node_id(): |
| 45 | """Test for invalid node IDs""" |
| 46 | builder = ModelBuilder( |
| 47 | threshold_type="float32", |
| 48 | leaf_output_type="float32", |
| 49 | metadata=Metadata( |
| 50 | num_feature=1, |
| 51 | task_type="kBinaryClf", |
| 52 | average_tree_output=False, |
| 53 | num_target=1, |
| 54 | num_class=[1], |
| 55 | leaf_vector_shape=(1, 1), |
| 56 | ), |
| 57 | tree_annotation=TreeAnnotation(num_tree=1, target_id=[0], class_id=[0]), |
| 58 | postprocessor=PostProcessorFunc(name="sigmoid"), |
| 59 | base_scores=[0.0], |
| 60 | ) |
| 61 | builder.start_tree() |
| 62 | with pytest.raises(TreeliteError): |
| 63 | builder.start_node(-1) |
| 64 | builder.start_node(0) |
| 65 | |
| 66 | def invalid_numerical_test(left_child_key, right_child_key): |
| 67 | builder.numerical_test( |
| 68 | feature_id=0, |
| 69 | threshold=0.0, |
| 70 | default_left=True, |
| 71 | opname="<", |
| 72 | left_child_key=left_child_key, |
| 73 | right_child_key=right_child_key, |
| 74 | ) |
| 75 | |
| 76 | with pytest.raises(TreeliteError): |
| 77 | invalid_numerical_test(0, 1) |
| 78 | with pytest.raises(TreeliteError): |
| 79 | invalid_numerical_test(2, 2) |
| 80 | with pytest.raises(TreeliteError): |
| 81 | invalid_numerical_test(-1, -2) |
| 82 | with pytest.raises(TreeliteError): |
| 83 | invalid_numerical_test(-1, 2) |
| 84 | with pytest.raises(TreeliteError): |
| 85 | invalid_numerical_test(2, -1) |
| 86 | |
| 87 | |
| 88 | @pytest.mark.parametrize("predict_kind", ["default", "raw", "leaf_id"]) |
nothing calls this directly
no test coverage detected