# 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 array
import datetime
import fastavro
from decimal import Decimal
from io import BytesIO
from uuid import uuid4
from .conftest import assert_naive_datetime_equal_to_tz_datetime

def test_complex_schema_nulls():
    data1 = {
        "array_string": ["a", "b", "c"],
        "array_record": [{"f1": "1", "f2": Decimal("123.456")}],
    }
    binary = serialize(schema, data1)
    data2 = deserialize(schema, binary)
    data1_compare = data1
    data1_compare.update(
        {
            "multi_union_time": None,
            "array_bytes_decimal": None,
            "array_fixed_decimal": None,
            "union_uuid": None,
        }
    )
    assert data1_compare == data2


def test_array_from_tuple():
    data_list = serialize({"type": "array", "items": "int"}, [1, 2, 3])
    data_tuple = serialize({"type": "array", "items": "int"}, (1, 2, 3))
    assert data_list == data_tuple


def test_array_from_array():
    schema = {"type": "array", "items": "int"}
    using_list = serialize(schema, [1, -2, 3])
    using_array = serialize(schema, array.array("l", [1, -2, 3]))

# 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_complex.py
import array
import datetime
import fastavro
from decimal import Decimal
from io import BytesIO
from uuid import uuid4
from .conftest import assert_naive_datetime_equal_to_tz_datetime


def test_complex_schema_nulls():
    data1 = {
        "array_string": ["a", "b", "c"],
        "array_record": [{"f1": "1", "f2": Decimal("123.456")}],
    }
    binary = serialize(schema, data1)
    data2 = deserialize(schema, binary)
    data1_compare = data1
    data1_compare.update(
        {
            "multi_union_time": None,
            "array_bytes_decimal": None,
            "array_fixed_decimal": None,
            "union_uuid": None,
        }
    )
    assert data1_compare == data2


def test_array_from_tuple():
    data_list = serialize({"type": "array", "items": "int"}, [1, 2, 3])
    data_tuple = serialize({"type": "array", "items": "int"}, (1, 2, 3))
    assert data_list == data_tuple


def test_array_from_array():
    schema = {"type": "array", "items": "int"}
    using_list = serialize(schema, [1, -2, 3])
    using_array = serialize(schema, array.array("l", [1, -2, 3]))

    assert using_list == using_array