Exemple #1
0
    def test_utilfns(self):
        self.assertTrue(isnum(3))
        self.assertTrue(isnum(-3.32))
        self.assertFalse(isnum('32.3'))

        self.assertFalse(istext(3))
        self.assertTrue(istext('32.3'))

        self.assertEqual(yyyymmdd(19991230, '2 months'), 20000229)
        self.assertEqual(yyyymmdd(19991231, '-2 months'), 19991031)

        self.assertEqual(yyyymm(199912, 2), 200002)
        self.assertEqual(yyyymm(199912, -2), 199910)


        # not 19990531
        self.assertEqual(yyyymmdd(19990430, '1 month'), 19990530)

        self.assertEqual(yyyymmdd(19991231, '2 days'), 20000102)
        self.assertEqual(yyyymmdd(19991231, '-2 days'), 19991229)
Exemple #2
0
    def setUp(self):
        self.rs1 = []
        for year in range(2001, 2011):
            r = Row()
            r.yyyy = year
            self.rs1.append(r)
        self.rs1 = PRows(self.rs1, 'yyyy')

        self.rs2 = []
        start_month = 200101
        for i in range(36):
            r = Row()
            r.yyyymm = yyyymm(start_month, i)
            self.rs2.append(r)
        self.rs2 = PRows(self.rs2, 'yyyymm')

        self.rs3 = []
        start_date = 20010101
        for i in range(30):
            r = Row()
            r.yyyymmdd = yyyymmdd(start_date, i)
            self.rs3.append(r)
        self.rs3 = PRows(self.rs3, 'yyyymmdd')

        with dbopen(':memory:') as c:
            c.save('indport.csv')
            # to pseudo monthly data
            rs = []
            for rs1 in c.reel('indport order by date', group=lambda r: str(r.date)[0:4]):
                for r in rs1:
                    r.yyyy = int(str(r.date)[0:4])
                    r.fcode = 'A' + str(r.date)[4:]
                    del r.date
                    rs.append(r)
            self.indport = PRows(rs, 'yyyy', 'fcode')

            rs = []
            for rs1 in c.reel('indport order by date', group=lambda r: str(r.date)[0:6]):
                for r in rs1:
                    r.yyyymm = int(str(r.date)[0:6])
                    r.fcode = 'A' + str(r.date)[6:]
                    del r.date
                    rs.append(r)
            self.indport1 = PRows(rs, 'yyyymm', 'fcode')