code: def test_pipe_pipe_invalid_data_mocked(
      mocker, sentinel, mock_run, quiet
  ):
      mock_sys_stderr = mocker.patch(
          "sys.stderr",
          autospec=True,
          flush=mocker.Mock(),
          encoding=sentinel.encoding,
      )
  
      mock_out = mocker.create_autospec(
          bytes, instance=True, name="mock_out"
      )
      mock_err = mocker.create_autospec(
          bytes,
          instance=True,
          name="mock_err",
          **{"__len__.return_value": 1},
      )
  
      mock_run.return_value = subprocess.CompletedProcess(
          _common.INVALID_CMD,
          returncode=5,
          stdout=mock_out,
          stderr=mock_err,
      )
  
      with pytest.raises(subprocess.CalledProcessError) as e:
          graphviz.pipe("dot", "png", b"nongraph", quiet=quiet)
  
      assert e.value.returncode == 5
      assert e.value.cmd == _common.INVALID_CMD
      assert e.value.stdout is mock_out
      assert e.value.stderr is mock_err
      e.value.stdout = sentinel.new_stdout
      assert e.value.stdout is sentinel.new_stdout
      mock_run.assert_called_once_with(
          [_common.EXPECTED_DOT_BINARY, "-Kdot", "-Tpng"],
          input=b"nongraph",
          capture_output=True,
          startupinfo=_common.StartupinfoMatcher(),
      )
      if not quiet:
          mock_out.decode.assert_not_called()
          mock_err.decode.assert_called_once_with(sentinel.encoding)
          mock_sys_stderr.write.assert_called_once_with(
              mock_err.decode.return_value
          )
          mock_sys_stderr.flush.assert_called_once_with()
  
file_path: graphviz/tests/backend/test_piping.py
imports: import io
  import re
  import subprocess
  import pytest
  import graphviz
  import _common
label_desc: Use image node_id 2 for calling a global function with example usage: test_pipe_pipe_invalid_data_mocked(mocker, sentinel, mock_run, quiet) without return types