docstr: Test if the component ranks documents correctly with a custom top_k.
docstr_tok: ["Test","if","the","component","ranks","documents","correctly","with","a","custom","top_k","."]
code: def test_run_top_k(
      self, query, docs_before_texts, expected_first_text
  ):
      """
      Test if the component ranks documents correctly with a custom top_k.
      """
      ranker = TransformersSimilarityRanker(
          model="cross-encoder/ms-marco-MiniLM-L-6-v2", top_k=2
      )
      ranker.warm_up()
      docs_before = [
          Document(content=text) for text in docs_before_texts
      ]
      output = ranker.run(query=query, documents=docs_before)
      docs_after = output["documents"]
  
      assert len(docs_after) == 2
      assert docs_after[0].content == expected_first_text
  
      sorted_scores = sorted(
          [doc.score for doc in docs_after], reverse=True
      )
      assert [doc.score for doc in docs_after] == sorted_scores
  
file_path: haystack/test/components/rankers/test_transformers_similarity.py
imports: from unittest.mock import MagicMock, patch
  import pytest
  import torch
  from transformers.modeling_outputs import SequenceClassifierOutput
  from haystack import Document, ComponentError
  from haystack.components.rankers.transformers_similarity import TransformersSimilarityRanker
label_desc: Use image node_id 11 for calling the TestSimilarityRanker obj's underlying member method code with example usage: obj.test_run_top_k(query, docs_before_texts, expected_first_text) without return types