@@ -82,6 +82,19 @@ def test_missing_expected_output_key_returns_0(self):
8282 score = top_k (["a" ], {})
8383 assert score == pytest .approx (0.0 )
8484
85+ def test_bare_string_expected_output_is_treated_as_single_item (self ):
86+ """A plain identifier string (e.g. from a CSV column) must not crash
87+ ast.literal_eval and should be treated as a single-item expected list."""
88+ top_k = make_top_k_evaluator (K = 10 )
89+ # "some_url" is a bare identifier — not a Python literal
90+ score = top_k (["some_url" ], {"expected_output" : "some_url" })
91+ assert score == pytest .approx (1.0 )
92+
93+ def test_bare_string_expected_output_no_match (self ):
94+ top_k = make_top_k_evaluator (K = 10 )
95+ score = top_k (["other_url" ], {"expected_output" : "some_url" })
96+ assert score == pytest .approx (0.0 )
97+
8598
8699class TestMakeMembershipEvaluator :
87100 def test_returns_callable_named_is_in (self ):
@@ -120,3 +133,14 @@ def test_single_item_list_match(self):
120133 def test_case_sensitive (self ):
121134 is_in = make_membership_evaluator ()
122135 assert is_in ("ES_SEARCH" , {"expected_output" : ["es_search" ]}) is False
136+
137+ def test_bare_string_expected_output_is_treated_as_single_item (self ):
138+ """A plain identifier string (e.g. from a CSV column) must not crash
139+ ast.literal_eval and should be treated as a single-item expected list."""
140+ is_in = make_membership_evaluator ()
141+ # "elasticsearch" is a bare identifier — not a Python literal
142+ assert is_in ("elasticsearch" , {"expected_output" : "elasticsearch" }) is True
143+
144+ def test_bare_string_expected_output_no_match (self ):
145+ is_in = make_membership_evaluator ()
146+ assert is_in ("cms" , {"expected_output" : "elasticsearch" }) is False
0 commit comments