# Path: quantrocket/moonshot.py
# def read_moonshot_csv(filepath_or_buffer):
#     """
#     Load a Moonshot backtest CSV into a DataFrame.
# 
#     This is a light wrapper around pd.read_csv that handles setting index
#     columns and casting to proper data types.
# 
#     Parameters
#     ----------
#     filepath_or_buffer : string or file-like, required
#         path to CSV
# 
#     Returns
#     -------
#     DataFrame
#         a multi-index (Field, Date[, Time]) DataFrame of backtest
#         results, with sids or strategy codes as columns
# 
#     Examples
#     --------
#     >>> results = read_moonshot_csv("moonshot_backtest.csv")
#     >>> returns = results.loc["Return"]
#     """
#     return _read_moonshot_or_pnl_csv(filepath_or_buffer)


import unittest
import os
import pandas as pd
from quantrocket.moonshot import read_moonshot_csv
    def setUp(self):
        self.maxDiff = None

    def tearDown(self):
        if os.path.exists("results.csv"):
            os.remove("results.csv")

    def test_eod_aggregate(self):

        results = pd.DataFrame.from_dict(EOD_AGGREGATE_RESULTS)
        results.index.set_names(["Field","Date"], inplace=True)
        results.to_csv("results.csv")

        results = read_moonshot_csv("results.csv")

        results = results.reset_index()
        results.loc[:, "Date"] = results.Date.dt.strftime("%Y-%m-%d")
        results = results.set_index(["Field", "Date"])

        self.assertDictEqual(
            results.to_dict(),
            EOD_AGGREGATE_RESULTS
        )

    def test_eod_detailed(self):

        results = pd.DataFrame.from_dict(EOD_DETAILED_RESULTS)
        results.index.set_names(["Field","Date"], inplace=True)
        results.to_csv("results.csv")


# Path: quantrocket/moonshot.py
# def read_moonshot_csv(filepath_or_buffer):
#     """
#     Load a Moonshot backtest CSV into a DataFrame.
# 
#     This is a light wrapper around pd.read_csv that handles setting index
#     columns and casting to proper data types.
# 
#     Parameters
#     ----------
#     filepath_or_buffer : string or file-like, required
#         path to CSV
# 
#     Returns
#     -------
#     DataFrame
#         a multi-index (Field, Date[, Time]) DataFrame of backtest
#         results, with sids or strategy codes as columns
# 
#     Examples
#     --------
#     >>> results = read_moonshot_csv("moonshot_backtest.csv")
#     >>> returns = results.loc["Return"]
#     """
#     return _read_moonshot_or_pnl_csv(filepath_or_buffer)


# Path: tests/test_moonshot.py
import unittest
import os
import pandas as pd
from quantrocket.moonshot import read_moonshot_csv

    def setUp(self):
        self.maxDiff = None

    def tearDown(self):
        if os.path.exists("results.csv"):
            os.remove("results.csv")

    def test_eod_aggregate(self):

        results = pd.DataFrame.from_dict(EOD_AGGREGATE_RESULTS)
        results.index.set_names(["Field","Date"], inplace=True)
        results.to_csv("results.csv")

        results = read_moonshot_csv("results.csv")

        results = results.reset_index()
        results.loc[:, "Date"] = results.Date.dt.strftime("%Y-%m-%d")
        results = results.set_index(["Field", "Date"])

        self.assertDictEqual(
            results.to_dict(),
            EOD_AGGREGATE_RESULTS
        )

    def test_eod_detailed(self):

        results = pd.DataFrame.from_dict(EOD_DETAILED_RESULTS)
        results.index.set_names(["Field","Date"], inplace=True)
        results.to_csv("results.csv")


        results = read_moonshot_csv("results.csv")