code: def test_update(dvc):
      """Test that update overwrites existing stages with the new ones.
  
      The old stages and the new ones might have same hash, so we are
      making sure that the old stages were removed and replaced by new ones
      using `id`/`is` checks.
      """
      index = Index.from_repo(dvc)
      new_stage = Stage(dvc, path="path1")
      new_index = index.update({new_stage})
  
      assert not index.stages
      assert new_index.stages == [new_stage]
  
      dup_stage1 = Stage(dvc, path="path1")
      dup_stage2 = Stage(dvc, path="path2")
      dup_index = index.update([dup_stage1, dup_stage2])
      assert not index.stages
      assert len(new_index.stages) == 1
      assert new_index.stages[0] is new_stage
      assert set(map(id, dup_index.stages)) == {
          id(dup_stage1),
          id(dup_stage2),
      }
  
imports: import os
  from itertools import chain
  import pytest
  from pygtrie import Trie
  from dvc.repo.index import Index
  from dvc.stage import Stage
label_desc: Use image node_id 5 for calling a global function with example usage: test_update(dvc) without return types