def test_binary(self):
    if PY3:
        bin_type_dict = {'bin': b'\x00\x01\x02\x03\x04'}
    else:
        bin_type_dict = {'bin': Binary(b'\x00\x01\x02\x03\x04')}
    md5_type_dict = {'md5': Binary(b' n7\x18\xaf\t/\xd1\xd1/\x80\xca\xe7q\xcc\xac', MD5_SUBTYPE)}
    custom_type_dict = {'custom': Binary(b'hello', USER_DEFINED_SUBTYPE)}
    self.round_trip(bin_type_dict)
    self.round_trip(md5_type_dict)
    self.round_trip(custom_type_dict)
    bin = json_util.loads('{"bin": {"$binary": "AAECAwQ=", "$type": "00"}}')['bin']
    if PY3:
        self.assertEqual(type(bin), bytes)
    else:
        self.assertEqual(type(bin), Binary)
    json_bin_dump = json_util.dumps(bin_type_dict)
    self.assertTrue(('"$type": "00"' in json_bin_dump))
    self.assertEqual(bin_type_dict, json_util.loads('{"bin": {"$type": 0, "$binary": "AAECAwQ="}}'))
    json_bin_dump = json_util.dumps(md5_type_dict)
    self.assertEqual(('{"md5": {"$binary": "IG43GK8JL9HRL4DK53HMrA==",' + ' "$type": "05"}}'), json_bin_dump)
    self.assertEqual(md5_type_dict, json_util.loads('{"md5": {"$type": 5, "$binary": "IG43GK8JL9HRL4DK53HMrA=="}}'))
    json_bin_dump = json_util.dumps(custom_type_dict)
    self.assertTrue(('"$type": "80"' in json_bin_dump))
    self.assertEqual(custom_type_dict, json_util.loads('{"custom": {"$type": 128, "$binary": "aGVsbG8="}}'))
    self.assertEqual(128, json_util.loads('{"custom": {"$type": "ffffff80", "$binary": "aGVsbG8="}}')['custom'].subtype)
    self.assertEqual(255, json_util.loads('{"custom": {"$type": "ffffffff", "$binary": "aGVsbG8="}}')['custom'].subtype)
def test_binary(self):
    if PY3:
        bin_type_dict = {'bin': b'\x00\x01\x02\x03\x04'}
    else:
        bin_type_dict = {'bin': Binary(b'\x00\x01\x02\x03\x04')}
    md5_type_dict = {'md5': Binary(b' n7\x18\xaf\t/\xd1\xd1/\x80\xca\xe7q\xcc\xac', MD5_SUBTYPE)}
    custom_type_dict = {'custom': Binary(b'hello', USER_DEFINED_SUBTYPE)}
    self.round_trip(bin_type_dict)
    self.round_trip(md5_type_dict)
    self.round_trip(custom_type_dict)
    bin = json_util.loads('{"bin": {"$binary": "AAECAwQ=", "$type": "00"}}')['bin']
    if PY3:
        self.assertEqual(type(bin), bytes)
    else:
        self.assertEqual(type(bin), Binary)
    json_bin_dump = json_util.dumps(bin_type_dict)
    self.assertTrue(('"$type": "00"' in json_bin_dump))
    self.assertEqual(bin_type_dict, json_util.loads('{"bin": {"$type": 0, "$binary": "AAECAwQ="}}'))
    json_bin_dump = json_util.dumps(md5_type_dict)
    self.assertEqual(('{"md5": {"$binary": "IG43GK8JL9HRL4DK53HMrA==",' + ' "$type": "05"}}'), json_bin_dump)
    self.assertEqual(md5_type_dict, json_util.loads('{"md5": {"$type": 5, "$binary": "IG43GK8JL9HRL4DK53HMrA=="}}'))
    json_bin_dump = json_util.dumps(custom_type_dict)
    self.assertTrue(('"$type": "80"' in json_bin_dump))
    self.assertEqual(custom_type_dict, json_util.loads('{"custom": {"$type": 128, "$binary": "aGVsbG8="}}'))
    self.assertEqual(128, json_util.loads('{"custom": {"$type": "ffffff80", "$binary": "aGVsbG8="}}')['custom'].subtype)
    self.assertEqual(255, json_util.loads('{"custom": {"$type": "ffffffff", "$binary": "aGVsbG8="}}')['custom'].subtype)