import pytest
import numpy as np
from autocast import acast, add_acast

try:
    import torch
    HAS_TORCH = True
except ImportError:
    HAS_TORCH = False

@pytest.mark.skipif(not HAS_TORCH, reason="Torch not installed")
def test_torch_to_numpy():
    a = torch.rand(1, 3)
    b = acast(a, np.ndarray)
    assert isinstance(b, np.ndarray)
    assert np.allclose(a.numpy(), b)

def test_dict_recursion():
    a = {"k": torch.rand(1)}
    b = acast(a, float) # Assuming mapping exists or recurses
    # Add your assertions here
    
    
    
# if __name__ == "__main__":
#     print("Testing autocast.py")

#     import json

#     pretty = {str(k): [str(vv) for vv in v.keys()] for k, v in __g_mappings__.items()}
#     print(json.dumps(pretty, indent=4))

#     # import numpy as np
#     # import torch

#     # a = torch.rand(1, 3)
#     # b = acast(a, np.ndarray)
#     # print(a, b)
#     # print(type(a), type(b))

#     # a = {"k": torch.rand(1)}
#     # b = acast(a, float, debug=True)
#     # print(a, b)
#     # print(type(a), type(b))

#     # @acaster(torch.Tensor, int)
#     # def map_torch_to_torch(x=0):
#     #     return int(x + 1)
#     # print(acast(torch.zeros(1), int))

#     # @acaster(torch.Tensor, str)
#     # def map_torch_to_str(x=0):
#     #     import potatoooo
#     #     return "a"
#     # print(acast(torch.zeros(1), str))

#     # path = __find_path__(str, int)
#     # print(path)

#     # path = __find_path__(object, int)
#     # print(path)

#     # path = __find_path__(torch.Tensor, int)
#     # print(path)

#     # a = torch.rand(1, 3)
#     # b = acast(a, np.ndarray, str)
#     # print(a, b)

#     # omegaconf = importlib.import_module("omegaconf")
#     # a = omegaconf.listconfig.ListConfig([1, 2, 3])
#     # b = acast(a, object)
#     # print(a, b, type(a), type(b))

#     a = torch.rand(1)
#     b = acast(a, str, debug=True)
#     print(b)

#     @acaster(torch.Tensor, str)
#     def map_torch_str(x=torch.zeros(1)):
#         print("map_torch_str")
#         return str(x)

#     b = acast(a, str, debug=True)
#     print(b)
