示例#1
0
class TestColumn(unittest.TestCase):
    def setUp(self):
        root_dir = os.path.dirname(os.path.realpath(__file__))
        data_dir = os.path.join(root_dir, "data")
        self.reader = CsvReader(data_dir)

    def test_read_spy(self):
        df = self.reader.read_column(["SPY"], ColumnName.ADJCLOSE)
        self.assertEqual(df.shape[0], 50)
        self.assertEqual(df.shape[1], 1)

    def test_read_goog(self):
        df = self.reader.read_column(["GOOG"], ColumnName.ADJCLOSE)
        self.assertEqual(df.shape[0], 30)
        self.assertEqual(df.shape[1], 1)

    def test_read_gld(self):
        df = self.reader.read_column(["GLD"], ColumnName.ADJCLOSE)
        self.assertEqual(df.shape[0], 70)
        self.assertEqual(df.shape[1], 1)

    def test_read_all(self):
        df = self.reader.read_column(["SPY", "GOOG", "GLD"],
                                     ColumnName.ADJCLOSE)
        self.assertEqual(df.shape[0], 70)
        self.assertEqual(df.shape[1], 3)
示例#2
0
class TestMerge(unittest.TestCase):
    def setUp(self):
        root_dir = os.path.dirname(os.path.realpath(__file__))
        data_dir = os.path.join(root_dir, "data")
        self.reader = CsvReader(data_dir)

    def test_merge_tickers(self):
        df_a = self.reader.read_column(["GOOG"], ColumnName.ADJCLOSE)
        df_b = self.reader.read_column(["GLD"], ColumnName.ADJCLOSE)
        df_c = Merge().process(df_a, df_b)
        self.assertListEqual(df_c.columns.tolist(), ["GOOG", "GLD"])