code: def test_truncate(tmpfile):
      with open(tmpfile, "w") as fh:
          fh.write("spam and eggs")
  
      with portalocker.Lock(tmpfile, mode="a+") as fh:
          # Make sure we didn't overwrite the original text
          fh.seek(0)
          assert fh.read(13) == "spam and eggs"
  
      with portalocker.Lock(tmpfile, mode="w+") as fh:
          # Make sure we truncated the file
          assert fh.read() == ""
  
imports: from __future__ import print_function
  from __future__ import with_statement
  import os
  import dataclasses
  import multiprocessing
  import time
  import typing
  import pytest
  import portalocker
  from portalocker import utils
  from portalocker import LockFlags
label_desc: Use image node_id 7 for calling a global function with example usage: test_truncate(tmpfile) without return types