code: def test_sha1_add_file(sha1_store, compress):
      os.chdir(TESTING_STORE_DIR)
  
      # Create random checkpoints
      size_list = [25e5, 27e5, 30e5, 35e5, 40e5]
      chkpts = [
          "checkpoint_1a.pt",
          "checkpoint_1b.pt",
          "checkpoint_1c.pt",
          "checkpoint_2.pt",
          "checkpoint_3.pt",
      ]
  
      for file, size in zip(chkpts, size_list):
          torch.save(nn.Linear(1, int(size)).state_dict(), file)
  
      # Add those 5 random files.
      for c in chkpts:
          sha1_store.add(c, compress)
  
      # Add a fixed data twice.
      module = nn.Linear(100, 100, bias=False)
      module.weight.data = torch.zeros(100, 100)
      zeros_file = "zeros.pt"
      torch.save(module.state_dict(), zeros_file)
      sha1_store.add(zeros_file, compress)
      sha1_store.add(zeros_file, compress)
  
      # Assert the ref counts are 1,1,1,1,1 and 2
      with sha1_store._readonly_json_ctx:
          json_dict = sha1_store._json_dict
      key = "3c06179202606573a4982d91c2829a1a675362b3"
      assert (
          key in json_dict.keys() and json_dict[key]["ref_count"] == 2
      ), json_dict
      json_dict = dict(
          filter(
              lambda item: len(item[0]) == SHA1_KEY_STR_LEN,
              json_dict.items(),
          )
      )
      assert sorted(
          map(lambda x: x["ref_count"], json_dict.values())
      ) == [1, 1, 1, 1, 1, 2], json_dict
  
file_path: fairscale/tests/experimental/wgit/test_sha1_store.py
imports: import os
  from pathlib import Path
  import shutil
  import sys
  import pytest
  import torch
  from torch import nn
  from fairscale.experimental.wgit.sha1_store import SHA1_Store
  from fairscale.fair_dev.testing.testing import objects_are_equal
label_desc: Use image node_id 2 for calling a global function with example usage: test_sha1_add_file(sha1_store, compress) without return types