# Path: fastavro/__main__.py
# class CleanJSONEncoder(json.JSONEncoder):
#     def default(self, obj):
#         if isinstance(obj, (datetime.date, datetime.datetime)):
#             return obj.isoformat()
#         elif isinstance(obj, (Decimal, UUID)):
#             return str(obj)
#         elif isinstance(obj, bytes):
#             return obj.decode("iso-8859-1")
#         else:
#             return json.JSONEncoder.default(self, obj)
# 
# Path: tests/conftest.py
# def assert_naive_datetime_equal_to_tz_datetime(naive_datetime, tz_datetime):
#     # mktime appears to ignore microseconds, so do this manually
#     microseconds = int(time.mktime(naive_datetime.timetuple())) * 1000 * 1000
#     microseconds += naive_datetime.microsecond
#     aware_datetime = datetime(1970, 1, 1, tzinfo=timezone.utc) + timedelta(
#         microseconds=microseconds
#     )
#     assert aware_datetime == tz_datetime


import fastavro
import json
import pytest
import datetime
import sys
import os
import numpy as np
    import pandas as pd
from fastavro.__main__ import CleanJSONEncoder
from decimal import Decimal
from io import BytesIO
from uuid import uuid4
from datetime import timezone, timedelta
from .conftest import assert_naive_datetime_equal_to_tz_datetime
}


def serialize(schema, data):
    bytes_writer = BytesIO()
    fastavro.schemaless_writer(bytes_writer, schema, data)
    return bytes_writer.getvalue()


def deserialize(schema, binary):
    bytes_writer = BytesIO()
    bytes_writer.write(binary)
    bytes_writer.seek(0)

    res = fastavro.schemaless_reader(bytes_writer, schema)
    return res


def test_logical_types():
    data1 = {
        "date": datetime.date.today(),
        "timestamp-millis": datetime.datetime.now(),
        "timestamp-micros": datetime.datetime.now(),
        "uuid": uuid4(),
        "time-millis": datetime.datetime.now().time(),
        "time-micros": datetime.datetime.now().time(),
    }
    binary = serialize(schema, data1)
    data2 = deserialize(schema, binary)
    assert data1["date"] == data2["date"]

# Path: fastavro/__main__.py
# class CleanJSONEncoder(json.JSONEncoder):
#     def default(self, obj):
#         if isinstance(obj, (datetime.date, datetime.datetime)):
#             return obj.isoformat()
#         elif isinstance(obj, (Decimal, UUID)):
#             return str(obj)
#         elif isinstance(obj, bytes):
#             return obj.decode("iso-8859-1")
#         else:
#             return json.JSONEncoder.default(self, obj)
# 
# Path: tests/conftest.py
# def assert_naive_datetime_equal_to_tz_datetime(naive_datetime, tz_datetime):
#     # mktime appears to ignore microseconds, so do this manually
#     microseconds = int(time.mktime(naive_datetime.timetuple())) * 1000 * 1000
#     microseconds += naive_datetime.microsecond
#     aware_datetime = datetime(1970, 1, 1, tzinfo=timezone.utc) + timedelta(
#         microseconds=microseconds
#     )
#     assert aware_datetime == tz_datetime


# Path: tests/test_logical_types.py
import fastavro
import json
import pytest
import datetime
import sys
import os
import numpy as np
    import pandas as pd
from fastavro.__main__ import CleanJSONEncoder
from decimal import Decimal
from io import BytesIO
from uuid import uuid4
from datetime import timezone, timedelta
from .conftest import assert_naive_datetime_equal_to_tz_datetime

}


def serialize(schema, data):
    bytes_writer = BytesIO()
    fastavro.schemaless_writer(bytes_writer, schema, data)
    return bytes_writer.getvalue()


def deserialize(schema, binary):
    bytes_writer = BytesIO()
    bytes_writer.write(binary)
    bytes_writer.seek(0)

    res = fastavro.schemaless_reader(bytes_writer, schema)
    return res


def test_logical_types():
    data1 = {
        "date": datetime.date.today(),
        "timestamp-millis": datetime.datetime.now(),
        "timestamp-micros": datetime.datetime.now(),
        "uuid": uuid4(),
        "time-millis": datetime.datetime.now().time(),
        "time-micros": datetime.datetime.now().time(),
    }
    binary = serialize(schema, data1)
    data2 = deserialize(schema, binary)
    assert data1["date"] == data2["date"]

    assert_naive_datetime_equal_to_tz_datetime(