import unittest
import pickle, copy
import keyword
import re
import sys
import gc
import weakref

from recordclass import make_dataclass, datatype, DataclassStorage
from recordclass import dataobject, datatuple
from recordclass import asdict, clsconfig, enable_gc

_t = ()
_t1 = (1,)
_o = object()
headgc_size = sys.getsizeof(_t) - _t.__sizeof__()
ptr_size = sys.getsizeof(_t1) - sys.getsizeof(_t)
pyobject_size = _o.__sizeof__()
pyvarobject_size = _t.__sizeof__()
del _t, _t1, _o

class TestPickle2(dataobject):
    __fields__ = 'x', 'y', 'z'

class TestPickle3(dataobject):
    __fields__  = 'x', 'y', 'z', '__dict__'

# class TestPickleVar2(datatuple):
#     __fields__ = 'x', 'y', 'z'

# class TestPickleVar3(datatuple):
#     __fields__  = 'x', 'y', 'z', '__dict__'
    
class TestPickle22(dataobject):
    x:int
    y:int
    z:int

class TestPickle33(dataobject):
    x:int
    y:int
    z:int
    __dict__:dict
    
class DataObjectTest3(unittest.TestCase):

    def test_datatype_tp(self):
        class A(dataobject):
            __fields__ = 'x', 'y'
            x:int
            y:int

        a = A(1,2)
        self.assertEqual(repr(a), "A(x=1, y=2)")
        self.assertEqual(a.x, 1)
        self.assertEqual(a.y, 2)
        self.assertEqual(asdict(a), {'x':1, 'y':2})
        self.assertEqual(A.__annotations__, {'x':int, 'y':int})
#         self.assertEqual(sys.getsizeof(a), 32)
        with self.assertRaises(TypeError):     