code: def test_layout():
      i = Interval(4, 5, axis="y")
      q = Quadrilateral(np.array([[2, 2], [6, 2], [6, 7], [2, 5]]))
      r = Rectangle(3, 3, 5, 6)
      t = TextBlock(i, id=1, type=2, text="12")
  
      # Test Initializations
      l = Layout([i, q, r])
      l = Layout((i, q))
      Layout([l])
      with pytest.raises(ValueError):
          Layout(l)
  
      # Test tuple-like inputs
      l = Layout((i, q, r))
      assert l._blocks == [i, q, r]
      l.append(i)
  
      # Test apply functions
      l = Layout([i, q, r])
      l.get_texts()
      assert l.filter_by(t) == Layout([i])
      assert l.condition_on(i) == Layout(
          [block.condition_on(i) for block in [i, q, r]]
      )
      assert l.relative_to(q) == Layout(
          [block.relative_to(q) for block in [i, q, r]]
      )
      assert l.is_in(r) == Layout(
          [block.is_in(r) for block in [i, q, r]]
      )
      assert l.get_homogeneous_blocks() == [
          i.to_quadrilateral(),
          q,
          r.to_quadrilateral(),
      ]
  
      i2 = TextBlock(i, id=1, type=2, text="12")
      r2 = TextBlock(r, id=1, type=2, parent="a")
      q2 = TextBlock(q, id=1, type=2, next="a")
      l2 = Layout([i2, r2, q2], page_data={"width": 200, "height": 200})
  
      l2.get_texts()
      l2.get_info("next")
      l2.condition_on(i)
      l2.relative_to(q)
      l2.filter_by(t)
      l2.is_in(r)
  
      l2.scale(4)
      l2.shift(4)
      l2.pad(left=2)
  
      # Test slicing function
      homogeneous_blocks = l2[:2].get_homogeneous_blocks()
      assert homogeneous_blocks[0].block == i.to_rectangle()
      assert homogeneous_blocks[1].block == r
  
      # Test appending and extending
      assert l + [i2] == Layout([i, q, r, i2])
      assert l + l == Layout([i, q, r] * 2)
      l.append(i)
      assert l == Layout([i, q, r, i])
      l2.extend([q])
      assert l2 == Layout(
          [i2, r2, q2, q], page_data={"width": 200, "height": 200}
      )
  
      # Test addition
      l + l2
      with pytest.raises(ValueError):
          l.page_data = {"width": 200, "height": 400}
          l + l2
  
      # Test sort
      ## When sorting inplace, it should return None
      l = Layout([i])
      assert (
          l.sort(key=lambda x: x.coordinates[1], inplace=True) is None
      )
  
      ## Make sure only sorting inplace works
      l = Layout([i, i.shift(2)])
      l.sort(key=lambda x: x.coordinates[1], reverse=True)
      assert l != Layout([i.shift(2), i])
      l.sort(key=lambda x: x.coordinates[1], reverse=True, inplace=True)
      assert l == Layout([i.shift(2), i])
  
      l = Layout([q, r, i], page_data={"width": 200, "height": 400})
      assert l.sort(key=lambda x: x.coordinates[0]) == Layout(
          [i, q, r], page_data={"width": 200, "height": 400}
      )
  
      l = Layout([q, t])
      assert l.sort(key=lambda x: x.coordinates[0]) == Layout([t, q])
  
file_path: layout-parser/tests/test_elements.py
imports: import pytest
  import numpy
  import pandas
  from layoutparser.elements import Interval, Rectangle, Quadrilateral, TextBlock, Layout
  from layoutparser.elements.errors import InvalidShapeError, NotSupportedShapeError
label_desc: Use image node_id 8 for calling a global function with example usage: test_layout() without return types