示例#1
0
    def test_nested_rowset(self):
        r = [None for x in range(2)]
        r[0] = row.RowData("-13", Date(1971, 2, 6), "comment7")  # noqa
        r[1] = row.RowData("12", Date(1971, 1, 5), "comment8")  # noqa
        self.rows.append(r)

        self.assertEqual(self.rows.value, -46)
示例#2
0
    def test_value(self):
        self.assertEqual(self.rows.value, -45)

        self.rows.append(row.RowData("-0.5", Date(1970, 3, 12),
                                     "comment9"))  # noqa
        self.rows.append(row.RowData("-0.5", Date(1970, 3, 13),
                                     "comment10"))  # noqa
        self.assertEqual(str(self.rows.value), '-46')
示例#3
0
    def test_fields(self):
        obj = row.RowData(10, Date(1970, 10, 20), "A Comment")

        self.assertIsInstance(obj, row.RowData)
        self.assertEqual(obj.value, 10)
        self.assertEqual(obj.date, Date(1970, 10, 20))
        self.assertEqual(obj.comment, "A Comment")
        self.assertEqual(obj.isforecast, False)
        self.assertEqual(obj.location, None)

        with self.assertRaises(ValueError):
            row.RowData(10, 'notadate', "A Comment")
示例#4
0
    def test_bangtags(self):
        self.assertEqual(self.rows[0].bangtags, dict())

        self.assertIn('test_bangtag', self.rows[2].bangtags)

        with self.assertRaises(ValueError):
            row.RowData("100", Date(1970, 1, 1), "!test_bangtag !test_bangtag")
示例#5
0
    def test_hashtag(self):
        self.assertEqual(self.rows[0].hashtag, None)

        self.assertEqual(self.rows[3].hashtag, 'test_hashtag')

        with self.assertRaises(ValueError):
            row.RowData("100", Date(1970, 1, 1),
                        "#test_hashtag #test_hashtag2")
示例#6
0
    def test_category_prefix(self):
        obj = row.RowData(10, Date(1970, 11, 1),
                          "#test_hashtag2:level2:level3")  # noqa

        self.assertEqual(obj.category_prefix(0), '')
        self.assertEqual(obj.category_prefix1, 'test_hashtag2')
        self.assertEqual(obj.category_prefix(2), 'test_hashtag2:level2')
        self.assertEqual(obj.category_prefix(3), 'test_hashtag2:level2:level3')
        self.assertEqual(obj.category_prefix(4), 'test_hashtag2:level2:level3')

        with self.assertRaises(ValueError):
            obj.category_prefix(-1)
示例#7
0
    def test__split_dates(self):
        self.assertEqual(self.rows[0]._split_dates(), [Date(1970, 1, 1)])
        self.assertEqual(self.rows[2]._split_dates(), [Date(1970, 1, 3)])
        self.assertEqual(self.rows[4]._split_dates(), [
            Date(1972, 1, 29),
            Date(1972, 2, 29),
            Date(1972, 3, 29),
            Date(1972, 4, 29),
            Date(1972, 5, 29)
        ])
        self.assertEqual(self.rows[5]._split_dates(), [
            Date(1972, 1, 31),
            Date(1972, 2, 29),
            Date(1972, 3, 31),
            Date(1972, 4, 30),
        ])

        with self.assertRaises(ValueError):
            row.RowData("100", Date(1970, 1, 1), "!months")
        with self.assertRaises(ValueError):
            row.RowData("100", Date(1970, 1, 1), "!months:1:2:3")
示例#8
0
    def test_locnxfer(self):
        obj = row.RowData(0, Date(
            1970, 10, 23
        ), "#test_hashtag !locn_xfer:test_location:test_location2:300")  # noqa

        rows = obj._split_locn_xfer()

        self.assertEqual(len(rows), 2)

        self.assertEqual(str(
            rows[0]
        ), '-300 1970-10-23 #test_hashtag !locn_xfer:test_location:test_location2:300 !locn:test_location'
                         )  # noqa
        self.assertEqual(str(
            rows[1]
        ), '300 1970-10-23 #test_hashtag !locn_xfer:test_location:test_location2:300 !locn:test_location2'
                         )  # noqa
示例#9
0
 def test_location(self):
     obj = row.RowData(20, Date(1970, 10, 22), "!locn:test_location")
     self.assertEqual(obj.location, "test_location")
示例#10
0
 def test_forecast_simple(self):
     obj = row.RowData(10, Date(1970, 10, 21), "A Comment !forecast")
     self.assertEqual(obj.isforecast, True)
示例#11
0
 def test_both_months_and_forecast(self):
     with self.assertRaises(ValueError):
         row.RowData("100", Date(1970, 1, 1), "!months:3 !forecast")