docstr: Test if the component runs correctly with scores already in the metadata.
docstr_tok: ["Test","if","the","component","runs","correctly","with","scores","already","in","the","metadata","."]
code: def test_run_scores_from_metadata(self):
      """
      Test if the component runs correctly with scores already in the metadata.
      """
      sampler = TopPSampler(top_p=0.95, score_field="similarity_score")
      docs = [
          Document(content="Berlin", meta={"similarity_score": -10.6}),
          Document(content="Belgrade", meta={"similarity_score": -8.9}),
          Document(content="Sarajevo", meta={"similarity_score": -4.6}),
      ]
      output = sampler.run(documents=docs)
      docs = output["documents"]
      assert len(docs) == 1
      assert docs[0].content == "Sarajevo"
  
file_path: haystack/test/components/samplers/test_top_p.py
imports: import random
  import pytest
  from haystack import Document, ComponentError
  from haystack.components.samplers.top_p import TopPSampler
label_desc: Use image node_id 1 for calling the TestTopPSampler obj's underlying member method code with example usage: obj.test_run_scores_from_metadata() without return types