code: def test_writeTraining(self):
      if sys.version < "3":
          from StringIO import StringIO
  
          output = StringIO()
          encoded_file = codecs.EncodedFile(
              output, data_encoding="utf8", file_encoding="ascii"
          )
      else:
          from io import StringIO
  
          encoded_file = StringIO()
  
      training_pairs = {
          "distinct": [
              [
                  {
                      "bar": frozenset(["barë"]),
                      "baz": (1, 2),
                      "bang": (1, 2),
                      "foo": "baz",
                  },
                  {"foo": "baz"},
              ]
          ],
          "match": [],
      }
  
      json.dump(
          training_pairs,
          encoded_file,
          cls=dedupe.serializer.TupleEncoder,
      )
  
      encoded_file.seek(0)
  
      loaded_training_pairs = json.load(
          encoded_file, object_hook=dedupe.serializer._from_json
      )
  
      assert loaded_training_pairs["distinct"][0][0] == dict(
          training_pairs["distinct"][0][0]
      )
  
      assert isinstance(
          loaded_training_pairs["distinct"][0][0]["bar"], frozenset
      )
      assert isinstance(
          loaded_training_pairs["distinct"][0][0]["baz"], tuple
      )
  
      deduper = dedupe.Dedupe([{"field": "foo", "type": "String"}])
      deduper.classifier.cv = False
  
      encoded_file.seek(0)
  
      deduper._read_training(encoded_file)
      print(deduper.training_pairs)
      print(training_pairs)
      assert deduper.training_pairs == training_pairs
  
      encoded_file.close()
  
file_path: dedupe/tests/test_serializer.py
imports: from __future__ import print_function
  import codecs
  import json
  import sys
  import unittest
  import dedupe
label_desc: Use image node_id 1 for calling the SerializerTest obj's underlying member method code with example usage: obj.test_writeTraining() without return types