code: def test_clear(cls, keep_attrs):
      kwargs = {f"{a}_attr": {a: a} for a in ("graph", "node", "edge")}
      c = cls(**kwargs)
      assert all(getattr(c, k) == v for k, v in kwargs.items())
      c.node("spam")
      assert len(c.body) == 1
      body = c.body
  
      c.clear(keep_attrs=keep_attrs)
      assert c.body == []
      assert c.body is body
      if keep_attrs:
          assert all(getattr(c, k) == v for k, v in kwargs.items())
      else:
          assert all(getattr(c, k) == {} for k in kwargs)
  
file_path: graphviz/tests/test_graphs.py
imports: import itertools
  import pytest
  import graphviz
label_desc: Use image node_id 6 for calling a global function with example usage: test_clear(cls, keep_attrs) without return types