code: def test_counts_method(ts_en, ts_es, lang, name, exp):
      # the expected values are very sensitive to spacy model's token annotations
      # so we try to assess "more or less" equal counts
      ts = ts_en if lang == "en" else ts_es
      obs = ts.counts(name)
      assert isinstance(obs, dict)
      if name != "morph":
          assert all(isinstance(val, int) for val in obs.values())
          diffs = collections.Counter(ts.counts(name))
          diffs.subtract(exp)
          assert all(abs(val) <= 1 for val in diffs.values())
      else:
          assert all(
              isinstance(val_counts, dict)
              for val_counts in obs.values()
          )
          assert all(
              isinstance(val, int)
              for val_counts in obs.values()
              for val in val_counts.values()
          )
          assert list(obs.keys()) == list(exp.keys())
  
file_path: textacy/tests/text_stats/test_api.py
imports: import collections
  from contextlib import nullcontext
  import pyphen
  import pytest
  import textacy
  import textacy.text_stats
label_desc: Use image node_id 4 for calling a global function with example usage: test_counts_method(ts_en, ts_es, lang, name, exp) without return types