code: def test_read_img_as_numpy(tmpdir_factory, mock_pdf):
      # Wrong input type
      with pytest.raises(TypeError):
          _ = io.read_img_as_numpy(123)
  
      # Non-existing file
      with pytest.raises(FileNotFoundError):
          io.read_img_as_numpy("my_imaginary_file.jpg")
  
      # Invalid image
      with pytest.raises(ValueError):
          io.read_img_as_numpy(str(mock_pdf))
  
      # From path
      url = "https://doctr-static.mindee.com/models?id=v0.2.1/Grace_Hopper.jpg&src=0"
      file = BytesIO(requests.get(url).content)
      tmp_path = str(
          tmpdir_factory.mktemp("data").join("mock_img_file.jpg")
      )
      with open(tmp_path, "wb") as f:
          f.write(file.getbuffer())
  
      # Path & stream
      with open(tmp_path, "rb") as f:
          page_stream = io.read_img_as_numpy(f.read())
  
      for page in (io.read_img_as_numpy(tmp_path), page_stream):
          # Data type
          assert isinstance(page, np.ndarray)
          assert page.dtype == np.uint8
          # Shape
          assert page.shape == (606, 517, 3)
  
      # RGB
      bgr_page = io.read_img_as_numpy(tmp_path, rgb_output=False)
      assert np.all(page == bgr_page[..., ::-1])
  
      # Resize
      target_size = (200, 150)
      resized_page = io.read_img_as_numpy(tmp_path, target_size)
      assert resized_page.shape[:2] == target_size
  
file_path: doctr/tests/common/test_io.py
imports: from io import BytesIO
  from pathlib import Path
  import numpy
  import pytest
  import requests
  from doctr import io
label_desc: Use image node_id 3 for calling a global function with example usage: test_read_img_as_numpy(tmpdir_factory, mock_pdf) without return types